Class: GitQuickBooks::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/gitquickbooks/api.rb

Overview

Expose and authorize primary QB account

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



15
16
17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def access_token
  @access_token
end

#authorize_urlObject (readonly)

Returns the value of attribute authorize_url.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def authorize_url
  @authorize_url
end

#callback_urlObject (readonly)

Returns the value of attribute callback_url.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def callback_url
  @callback_url
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def key
  @key
end

#realmObject (readonly)

Returns the value of attribute realm.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def realm
  @realm
end

#secretObject (readonly)

Returns the value of attribute secret.



8
9
10
# File 'lib/gitquickbooks/api.rb', line 8

def secret
  @secret
end

Instance Method Details

#authorize(oauth) ⇒ Object



42
43
44
45
# 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_oauthObject



26
27
28
29
30
31
32
33
34
35
# 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_authObject



37
38
39
40
# 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