Class: Gateway::Quickbook
Defined Under Namespace
Modules: API, ENVIRONMENT, HTTP
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#company_id ⇒ Object
Returns the value of attribute company_id.
-
#consumer ⇒ Object
Returns the value of attribute consumer.
Class Method Summary collapse
-
.connect(options) ⇒ Object
Connect to QuickBook online API gateway Options are as follow String: Environment ENVIRONMENT::SANDBOX or ENVIRONMENT::PRODUCTION.
Instance Method Summary collapse
- #get(path, parameters = {}) ⇒ Object
- #post(path, parameters, body) ⇒ Object
- #query_data(query) ⇒ Object
Methods inherited from Result
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
7 8 9 |
# File 'lib/gateway/quickbook.rb', line 7 def access_token @access_token end |
#api ⇒ Object
Returns the value of attribute api.
6 7 8 |
# File 'lib/gateway/quickbook.rb', line 6 def api @api end |
#company_id ⇒ Object
Returns the value of attribute company_id.
7 8 9 |
# File 'lib/gateway/quickbook.rb', line 7 def company_id @company_id end |
#consumer ⇒ Object
Returns the value of attribute consumer.
7 8 9 |
# File 'lib/gateway/quickbook.rb', line 7 def consumer @consumer end |
Class Method Details
.connect(options) ⇒ Object
Connect to QuickBook online API gateway Options are as follow
String: Environment ENVIRONMENT::SANDBOX or ENVIRONMENT::PRODUCTION. AutoLoad QuickBook key, secret, access token, access secret, company ID from config/quickbook.yml corresponding to environment given.
Hash:
:client_id => QuickBook App Client ID,
:client_secret => QuickBook App Client Secret,
:refresh_token => Can generate from playground https://developer.intuit.com/app/developer/playground, validate for 100 days
:company_id => QuickBook Company ID,
:environment => ENVIRONMENT::SANDBOX or ENVIRONMENT::PRODUCTION
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gateway/quickbook.rb', line 40 def self.connect() if(.class == String) configuration = YAML.load_file("config/quickbook.yml") environment = = Hash.new [:client_id] = configuration[environment]["client_id"] [:client_secret] = configuration[environment]["client_secret"] [:refresh_token] = configuration[environment]["refresh_token"] [:company_id] = configuration[environment]["company_id"] [:environment] = environment end gateway = new gateway.consumer = OAuth2::Client.new([:client_id], [:client_secret], {:token_url => 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer', auth_scheme: :basic_auth}) gateway.access_token = OAuth2::AccessToken.new(gateway.consumer, nil, {refresh_token: [:refresh_token]}) gateway.access_token = gateway.access_token.refresh! gateway.company_id = [:company_id] case [:environment] when ENVIRONMENT::PRODUCTION gateway.send("api=", "https://quickbooks.api.intuit.com") else gateway.send("api=", "https://sandbox-quickbooks.api.intuit.com") end Service::Record.quickbook_gateway = gateway end |
Instance Method Details
#get(path, parameters = {}) ⇒ Object
76 77 78 |
# File 'lib/gateway/quickbook.rb', line 76 def get(path, parameters = {}) return handle_query_result(self.access_token.get(url(path, parameters), {headers: {"Accept" => HTTP::JSON}})) end |
#post(path, parameters, body) ⇒ Object
84 85 86 |
# File 'lib/gateway/quickbook.rb', line 84 def post(path, parameters, body) return handle_query_result(self.access_token.post(url(path, parameters), {body: body, headers: {"Content-Type" => HTTP::JSON, "Accept" => HTTP::JSON}})) end |
#query_data(query) ⇒ Object
80 81 82 |
# File 'lib/gateway/quickbook.rb', line 80 def query_data(query) return get(API::QUERY, {:query => query}) end |