Class: Quickbooks::Base
- Inherits:
-
Object
show all
- Extended by:
- Configuration
- Includes:
- Finders
- Defined in:
- lib/quickbooks/base.rb,
lib/quickbooks/base/finders.rb,
lib/quickbooks/base/configuration.rb
Defined Under Namespace
Modules: Configuration, Finders
Instance Attribute Summary collapse
Instance Method Summary
collapse
configure, oauth_consumer, oauth_consumer=
Methods included from Finders
#display_name_sql, #find_by_display_name, #find_by_id, #qbuilder, #sql_builder
Constructor Details
#initialize(account, type = nil) ⇒ Base
11
12
13
14
|
# File 'lib/quickbooks/base.rb', line 11
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.
7
8
9
|
# File 'lib/quickbooks/base.rb', line 7
def service
@service
end
|
Instance Method Details
#company_id ⇒ Object
81
82
83
|
# File 'lib/quickbooks/base.rb', line 81
def company_id
retrieve(:company_id)
end
|
#create_service_for(type) ⇒ Object
98
99
100
|
# File 'lib/quickbooks/base.rb', line 98
def create_service_for(type)
@service = service_for(type)
end
|
#describing_method(e) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/quickbooks/base.rb', line 58
def describing_method(e)
case entity(e)
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
47
48
49
50
51
|
# File 'lib/quickbooks/base.rb', line 47
def description(e)
desc = (method = describing_method(e)) =~ /(total)/ ? e.send(method).to_f : e.send(method)
rescue => e
'nil'
end
|
#entity(obj = nil) ⇒ Object
53
54
55
56
|
# File 'lib/quickbooks/base.rb', line 53
def entity(obj = nil)
obj ||= @service
obj.class.name.split('::').last
end
|
#generate_quickbooks_ruby_namespace(type, variety = 'Model') ⇒ Object
20
21
22
23
|
# File 'lib/quickbooks/base.rb', line 20
def generate_quickbooks_ruby_namespace(type, variety = 'Model')
type = qbo_case(type)
"Quickbooks::#{variety}::#{type}"
end
|
#oauth_client ⇒ Object
35
36
37
|
# File 'lib/quickbooks/base.rb', line 35
def oauth_client
@oauth_client ||= OAuth::AccessToken.new(Quickbooks::Base.oauth_consumer, token, secret)
end
|
#qbo_case(type) ⇒ Object
16
17
18
|
# File 'lib/quickbooks/base.rb', line 16
def qbo_case(type)
type.is_a?(Symbol) ? type.to_s.camelcase : type
end
|
#quickbooks_ruby_model(type, *args) ⇒ Object
Also known as:
qr_model
25
26
27
|
# File 'lib/quickbooks/base.rb', line 25
def quickbooks_ruby_model(type, *args)
generate_quickbooks_ruby_namespace(type, 'Model').constantize.new(*args)
end
|
#quickbooks_ruby_service(type) ⇒ Object
Also known as:
qr_service
30
31
32
|
# File 'lib/quickbooks/base.rb', line 30
def quickbooks_ruby_service(type)
generate_quickbooks_ruby_namespace(type, 'Service').constantize.new
end
|
#retrieve(type) ⇒ Object
85
86
87
88
89
|
# File 'lib/quickbooks/base.rb', line 85
def retrieve(type)
meth = "persistent_#{type}"
arr = Quickbooks::Base.send(meth).split('.')
send_chain(arr)
end
|
#secret ⇒ Object
77
78
79
|
# File 'lib/quickbooks/base.rb', line 77
def secret
retrieve(:secret)
end
|
#service_for(type) ⇒ Object
91
92
93
94
95
96
|
# File 'lib/quickbooks/base.rb', line 91
def service_for(type)
service = quickbooks_ruby_service(type)
service.access_token = oauth_client
service.company_id = company_id
service
end
|
#show(options = {}) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/quickbooks/base.rb', line 39
def show(options = {})
options = { per_page: 20, page: 1 }.merge(options)
service = determine_service(options[:entity])
service.query(nil, options).entries.collect do |e|
"QBID: #{e.id} DESC: #{description(e)}"
end
end
|
#token ⇒ Object
73
74
75
|
# File 'lib/quickbooks/base.rb', line 73
def token
retrieve(:token)
end
|