Class: GitQuickBooks::Api
- Inherits:
-
Object
- Object
- GitQuickBooks::Api
- Defined in:
- lib/gitquickbooks/api.rb
Overview
Expose and authorize primary QB account
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#authorize_url ⇒ Object
readonly
Returns the value of attribute authorize_url.
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#realm ⇒ Object
readonly
Returns the value of attribute realm.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #authorize(oauth) ⇒ Object
- #build_oauth ⇒ Object
-
#initialize ⇒ Api
constructor
A new instance of Api.
- #setup_auth ⇒ Object
Constructor Details
#initialize ⇒ Api
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_token ⇒ Object (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_url ⇒ Object (readonly)
Returns the value of attribute authorize_url.
8 9 10 |
# File 'lib/gitquickbooks/api.rb', line 8 def @authorize_url end |
#callback_url ⇒ Object (readonly)
Returns the value of attribute callback_url.
8 9 10 |
# File 'lib/gitquickbooks/api.rb', line 8 def callback_url @callback_url end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
8 9 10 |
# File 'lib/gitquickbooks/api.rb', line 8 def key @key end |
#realm ⇒ Object (readonly)
Returns the value of attribute realm.
8 9 10 |
# File 'lib/gitquickbooks/api.rb', line 8 def realm @realm end |
#secret ⇒ Object (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 (oauth) @access_token = @request_token.get_access_token(oauth_verifier: oauth) GitQuickBooks::Cache.new.write('key', @access_token) end |
#build_oauth ⇒ Object
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_auth ⇒ Object
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.(oauth_callback: @callback_url) end |