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
69
70
71
|
# File 'lib/quickbooks/base.rb', line 69
def company_id
retrieve(:company_id)
end
|
#create_service_for(type) ⇒ Object
79
80
81
82
83
84
|
# File 'lib/quickbooks/base.rb', line 79
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/quickbooks/base.rb', line 46
def describing_method
case @service.class.name
when /(Item|TaxCode|PaymentMethod|Account)/
'name'
when /(Invoice|CreditMemo)/
'doc_number'
when /Payment/
'total'
when /(Vendor|Customer|Employee)/
'display_name'
else
'txn_date'
end
end
|
#description(e) ⇒ Object
40
41
42
43
44
|
# File 'lib/quickbooks/base.rb', line 40
def description(e)
desc = (method = describing_method) =~ /(total)/ ? e.send(method).to_f : e.send(method)
rescue => e
'nil'
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
73
74
75
76
77
|
# File 'lib/quickbooks/base.rb', line 73
def retrieve(type)
meth = "persistent_#{type}"
arr = Quickbooks::Base.send(meth).split('.')
send_chain(arr)
end
|
#secret ⇒ Object
65
66
67
|
# File 'lib/quickbooks/base.rb', line 65
def secret
retrieve(:secret)
end
|
#show(options = {}) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/quickbooks/base.rb', line 33
def show(options = {})
options = { per_page: 20, page: 1 }.merge(options)
@service.query(nil, options).entries.collect do |e|
"QBID: #{e.id} DESC: #{description(e)}"
end
end
|
#token ⇒ Object
61
62
63
|
# File 'lib/quickbooks/base.rb', line 61
def token
retrieve(:token)
end
|