Class: Gateway::Quickbook

Inherits:
Result
  • Object
show all
Defined in:
lib/gateway/quickbook.rb

Defined Under Namespace

Modules: API, ENVIRONMENT, HTTP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Result

#handle_query_result

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



7
8
9
# File 'lib/gateway/quickbook.rb', line 7

def access_token
  @access_token
end

#apiObject

Returns the value of attribute api.



6
7
8
# File 'lib/gateway/quickbook.rb', line 6

def api
  @api
end

#company_idObject

Returns the value of attribute company_id.



7
8
9
# File 'lib/gateway/quickbook.rb', line 7

def company_id
  @company_id
end

#consumerObject

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(options)   
  if(options.class == String)
    configuration = YAML.load_file("config/quickbook.yml")
    environment = options
    options = Hash.new
    options[:qb_key] = configuration[environment]["key"]
    options[:qb_secret] =   configuration[environment]["secret"]
    options[:token] =   configuration[environment]["access_token"]
    options[:secret] =   configuration[environment]["access_secret"]
    options[:company_id] =   configuration[environment]["company_id"]
    options[:environment] = environment
  end
  
  gateway = new
  gateway.consumer = OAuth::Consumer.new(options[:qb_key], options[: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, options[:token], options[:secret])
  
  gateway.company_id = options[:company_id]
  
  case options[: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