class GitQuickBooks::Api

Expose and authorize primary QB account

Attributes

access_token[R]
authorize_url[R]
callback_url[R]
key[R]
realm[R]
secret[R]

Public Class Methods

new() click to toggle source
# File lib/gitquickbooks/api.rb, line 15
def initialize
  @key          = ENV['QB_KEY']
  @secret       = ENV['QB_SECRET']
  @realm        = ENV['COMPANY_ID']
  @callback_url = 'https://localhost/oob'
  @qb_oauth     = build_oauth
  @access_token = GitQuickBooks::Cache.new.fetch('key') do
    setup_auth
  end
end

Public Instance Methods

authorize(oauth) click to toggle source
# File lib/gitquickbooks/api.rb, line 42
def authorize(oauth)
  @access_token = @request_token.get_access_token(oauth_verifier: oauth)
  GitQuickBooks::Cache.new.write('key', @access_token)
end
build_oauth() click to toggle source
# File lib/gitquickbooks/api.rb, line 26
def build_oauth
  OAuth::Consumer.new(
    @key,
    @secret,
    site: 'https://oauth.intuit.com',
    request_token_path: '/oauth/v1/get_request_token',
    authorize_url: 'https://appcenter.intuit.com/Connect/Begin',
    access_token_path: '/oauth/v1/get_access_token'
  )
end
setup_auth() click to toggle source
# File lib/gitquickbooks/api.rb, line 37
def setup_auth
  @request_token ||= @qb_oauth.get_request_token(oauth_callback: @callback_url)
  @authorize_url ||= @request_token.authorize_url(oauth_callback: @callback_url)
end