Class: Quickbooks::Base
- Inherits:
-
Object
show all
- Extended by:
- Configuration
- Defined in:
- lib/quickbooks/base.rb,
lib/quickbooks/base/configuration.rb
Defined Under Namespace
Modules: Configuration
Instance Attribute Summary collapse
Instance Method Summary
collapse
configure, oauth_consumer, oauth_consumer=
Constructor Details
#initialize(account, type = nil) ⇒ Base
Returns a new instance of Base.
9
10
11
12
|
# File 'lib/quickbooks/base.rb', line 9
def initialize(account, type = nil)
@account = account
create_service_for(type) if type
end
|
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
6
7
8
|
# File 'lib/quickbooks/base.rb', line 6
def service
@service
end
|
Instance Method Details
#company_id ⇒ Object
58
59
60
|
# File 'lib/quickbooks/base.rb', line 58
def company_id
retrieve(:company_id)
end
|
#create_service_for(type) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/quickbooks/base.rb', line 68
def create_service_for(type)
@service = quickbooks_ruby_service(type)
@service.access_token = oauth_client
@service.company_id = company_id
@service
end
|
#describing_method ⇒ Object
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/quickbooks/base.rb', line 39
def describing_method
case @service.class.name
when /(Item|TaxCode|PaymentMethod)/
'name'
when /(Invoice|Payment)/
'doc_number'
when /(Vendor|Customer|Employee)/
'display_name'
end
end
|
#generate_quickbooks_ruby_namespace(which, type = 'Model') ⇒ Object
14
15
16
17
|
# File 'lib/quickbooks/base.rb', line 14
def generate_quickbooks_ruby_namespace(which, type = 'Model')
which = which.to_s.camelcase if which.is_a?(Symbol)
"Quickbooks::#{type}::#{which}"
end
|
#oauth_client ⇒ Object
29
30
31
|
# File 'lib/quickbooks/base.rb', line 29
def oauth_client
@oauth_client ||= OAuth::AccessToken.new(Quickbooks::Base.oauth_consumer, token, secret)
end
|
#quickbooks_ruby_model(which, *args) ⇒ Object
Also known as:
qr_model
19
20
21
|
# File 'lib/quickbooks/base.rb', line 19
def quickbooks_ruby_model(which, *args)
generate_quickbooks_ruby_namespace(which, 'Model').constantize.new(*args)
end
|
#quickbooks_ruby_service(which) ⇒ Object
Also known as:
qr_service
24
25
26
|
# File 'lib/quickbooks/base.rb', line 24
def quickbooks_ruby_service(which)
generate_quickbooks_ruby_namespace(which, 'Service').constantize.new
end
|
#retrieve(type) ⇒ Object
62
63
64
65
66
|
# File 'lib/quickbooks/base.rb', line 62
def retrieve(type)
meth = "persistent_#{type}"
arr = Quickbooks::Base.send(meth).split('.')
send_chain(arr)
end
|
#secret ⇒ Object
54
55
56
|
# File 'lib/quickbooks/base.rb', line 54
def secret
retrieve(:secret)
end
|
#show(options = {}) ⇒ Object
33
34
35
36
37
|
# File 'lib/quickbooks/base.rb', line 33
def show(options = {})
options = { per_page: 20, page: 1 }.merge(options)
method = describing_method
@service.query(nil, options).entries.collect { |e| "QBID: #{e.id} DESC: #{e.send(method) if method}" }
end
|
#token ⇒ Object
50
51
52
|
# File 'lib/quickbooks/base.rb', line 50
def token
retrieve(:token)
end
|