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:
:qb_key => QuickBook Key,
:qb_secret => QuickBook Secret,
:token => Access Token,
:secret => Access Sceret,
:company_id => QuickBook Company ID,
:environment => ENVIRONMENT::SANDBOX or ENVIRONMENT::PRODUCTION
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 68 69 70 71 72 73 74 |
# File 'lib/gateway/quickbook.rb', line 41 def self.connect() if(.class == String) configuration = YAML.load_file("config/quickbook.yml") environment = = Hash.new [:qb_key] = configuration[environment]["key"] [:qb_secret] = configuration[environment]["secret"] [:token] = configuration[environment]["access_token"] [:secret] = configuration[environment]["access_secret"] [:company_id] = configuration[environment]["company_id"] [:environment] = environment end gateway = new gateway.consumer = OAuth::Consumer.new([:qb_key], [:qb_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" }) gateway.access_token = OAuth::AccessToken.new(gateway.consumer, [:token], [:secret]) 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
83 84 85 |
# File 'lib/gateway/quickbook.rb', line 83 def get(path, parameters = {}) return handle_query_result(self.access_token.get(url(path, parameters), {"Accept" => HTTP::JSON})) end |
#post(path, parameters, body) ⇒ Object
91 92 93 |
# File 'lib/gateway/quickbook.rb', line 91 def post(path, parameters, body) return handle_query_result(self.access_token.post(url(path, parameters), body, {"Content-Type" => HTTP::JSON, "Accept" => HTTP::JSON})) end |
#query_data(query) ⇒ Object
87 88 89 |
# File 'lib/gateway/quickbook.rb', line 87 def query_data(query) return get(API::QUERY, {:query => query}) end |