quickbooks-ruby-base 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmVlZjM5YjNkN2ZiMjQ4YzcwN2I2YTY4YTZlNTkxYThmM2E5ZDVlZA==
4
+ ZDViYzQyNTdmNDE1NGQ5MDNiYWI0NzAzZGZiZTA2YmZkZjRiZmI5YQ==
5
5
  data.tar.gz: !binary |-
6
- OTI4MzMzN2IxYWZjNDBiZGFkZmFlNmJhODJiYzg1ZDMxNDU0YzVjZg==
6
+ MWVjMmE3ODlmMDZhZWUyMzUyMWNjZDNjYjgyZDYzMjY4MGViY2RjYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWU1NmU0YmFjMmRkYjkyNzg2ZWM1ZGFjMWVjZGJlNjcwNzljMTg0MDc0OTZh
10
- MmZjOGU0YWVhZTc3Nzk3MzA0ODYwZjNkZDFhZGFkYzI0ODBjOGYwZjUxYjY5
11
- YmQ2NTQyNTliN2ZmMzE4NWE0Y2FkOGNiNDgyODhhNzE1NmIyZGY=
9
+ MGFlMjgyNTI3OTk5MzMzYjBjMzVhNmRhZTZkM2EzNGZmNTZkOWMwYmQwYTUw
10
+ ZGM4OGY4ZjIzYjg4MjIwZmVlZDY3OWVlZWU1MmFiMWYzMTA4M2Y4NjEzMDA1
11
+ ZmJlZWE0NmJlMTYyYTRlZGE2NGU2NmMyNWFhNzhhOWQ0OTdiM2E=
12
12
  data.tar.gz: !binary |-
13
- N2VjZWY0OWJiYjQ3NGYyYzYyN2ZmMDRkOGJlYTE2NTEwZTdkNjIxMmU5YzM0
14
- NTk0MzcyZTgyZWI1ZGRmM2JhYmQ5NWNhMzVlMTc0NjgxMDE4ZTY3N2ZiMTEz
15
- MDNhMjQ1YTQxNGFlZDc0OWNhOTA4M2MxY2FkZDU0NzQzMGFmZTE=
13
+ NTc3NDI0NmUyNjkxZjM1MTA1ODE5OTdmNzQ3NzA0MzU1Nzc5MWVlZDAwYmQw
14
+ OTJiNWQ1YjEyNmYxMThkYjljY2U3MmVkY2FiZjBiZWUxMDEyM2I1ZTdhZDAw
15
+ ZDBlZTJhM2U5YTg2Nzg4N2E4NmQ0MDFiZTRhMGFhOWM0YTY4Njc=
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .ruby-version
19
+ *.sess
data/README.md CHANGED
@@ -68,6 +68,9 @@ base = Quickbooks::Base.new(account, :payment_method)
68
68
  # With options
69
69
  >> base.show page:1, per_page: 3
70
70
  => ["QBID: 5 DESC: American Express", "QBID: 1 DESC: Cash", "QBID: 2 DESC: Check"]
71
+ # Show another entity
72
+ >> base.show(entity: :vendor)
73
+ => ["QBID: 5 DESC: Hampton's Car Parts", "QBID: 6 DESC: Good Eats", "QBID: 7 DESC: The Flower Shoppe"]
71
74
 
72
75
  ```
73
76
 
@@ -76,6 +79,8 @@ Convenience method to fetch an entity by its reference id
76
79
  ```
77
80
  base = Quickbooks::Base.new(account, :customer)
78
81
  >> base.find_by_id(1)
82
+ # Second argument to find Employee with id = 55
83
+ >> base.find_by_id(55, :employee)
79
84
  ```
80
85
 
81
86
  ### find_by_display_name()
@@ -87,6 +92,13 @@ base = Quickbooks::Base.new(account, :customer)
87
92
  # Generates a query based on the following SQL
88
93
  # "SELECT Id, DisplayName FROM Customer WHERE DisplayName = 'Chuck Russell'"
89
94
  ```
95
+ #### with options
96
+ ```
97
+ base = Quickbooks::Base.new(account)
98
+ >> base.find_by_display_name("Jonnie O'Meara", entity: :vendor, select: '*')
99
+ # Generates a query based on the following SQL
100
+ # "SELECT * FROM Vendor WHERE DisplayName = 'Jonnie O\\'Meara'"
101
+ ```
90
102
 
91
103
  ## Configuration
92
104
 
@@ -13,8 +13,12 @@ module Quickbooks
13
13
  create_service_for(type) if type
14
14
  end
15
15
 
16
+ def qbo_case(type)
17
+ type.is_a?(Symbol) ? type.to_s.camelcase : type
18
+ end
19
+
16
20
  def generate_quickbooks_ruby_namespace(type, variety = 'Model')
17
- type = type.is_a?(Symbol) ? type.to_s.camelcase : type
21
+ type = qbo_case(type)
18
22
  "Quickbooks::#{variety}::#{type}"
19
23
  end
20
24
 
@@ -34,23 +38,25 @@ module Quickbooks
34
38
 
35
39
  def show(options = {})
36
40
  options = { per_page: 20, page: 1 }.merge(options)
37
- @service.query(nil, options).entries.collect do |e|
41
+ service = determine_service(options[:entity])
42
+ service.query(nil, options).entries.collect do |e|
38
43
  "QBID: #{e.id} DESC: #{description(e)}"
39
44
  end
40
45
  end
41
46
 
42
47
  def description(e)
43
- desc = (method = describing_method) =~ /(total)/ ? e.send(method).to_f : e.send(method)
48
+ desc = (method = describing_method(e)) =~ /(total)/ ? e.send(method).to_f : e.send(method)
44
49
  rescue => e
45
50
  'nil'
46
51
  end
47
52
 
48
- def entity
49
- @service.class.name.split('::').last
53
+ def entity(obj = nil)
54
+ obj ||= @service
55
+ obj.class.name.split('::').last
50
56
  end
51
57
 
52
- def describing_method
53
- case entity
58
+ def describing_method(e)
59
+ case entity(e)
54
60
  when /(Item|TaxCode|PaymentMethod|Account)/
55
61
  'name'
56
62
  when /(Invoice|CreditMemo)/
@@ -82,15 +88,23 @@ module Quickbooks
82
88
  send_chain(arr)
83
89
  end
84
90
 
91
+ def service_for(type)
92
+ service = quickbooks_ruby_service(type)
93
+ service.access_token = oauth_client
94
+ service.company_id = company_id
95
+ service
96
+ end
97
+
85
98
  def create_service_for(type)
86
- @service = quickbooks_ruby_service(type)
87
- @service.access_token = oauth_client
88
- @service.company_id = company_id
89
- @service
99
+ @service = service_for(type)
90
100
  end
91
101
 
92
102
  private
93
103
 
104
+ def determine_service(entity)
105
+ entity ? service_for(entity) : @service
106
+ end
107
+
94
108
  def send_chain(arr)
95
109
  arr.inject(@account) {|o, a| o.send(a) }
96
110
  end
@@ -2,8 +2,13 @@ module Quickbooks
2
2
  class Base
3
3
  module Finders
4
4
 
5
- def find_by_id(id)
6
- @service.fetch_by_id(id)
5
+ def find_by_id(id, model = nil)
6
+ if model
7
+ new_service = service_for(model)
8
+ new_service.fetch_by_id(id)
9
+ else
10
+ @service.fetch_by_id(id)
11
+ end
7
12
  end
8
13
 
9
14
  def qbuilder
@@ -13,7 +18,7 @@ module Quickbooks
13
18
  def sql_builder(where, options = {})
14
19
  options[:entity] ||= entity
15
20
  options[:select] ||= '*'
16
- "SELECT #{options[:select]} FROM #{options[:entity]} WHERE #{where}"
21
+ "SELECT #{options[:select]} FROM #{qbo_case(options[:entity])} WHERE #{where}"
17
22
  end
18
23
 
19
24
  def display_name_sql(display_name, options = {})
@@ -24,7 +29,8 @@ module Quickbooks
24
29
 
25
30
  def find_by_display_name(display_name, options = {})
26
31
  sql = display_name_sql(display_name, options)
27
- @service.query(sql)
32
+ service = determine_service(options[:entity])
33
+ service.query(sql)
28
34
  end
29
35
  end
30
36
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'quickbooks-ruby-base'
7
- spec.version = '1.5.0'
7
+ spec.version = '1.6.0'
8
8
  spec.authors = ["Christian"]
9
9
  spec.email = ["christian@minimul.com"]
10
10
  spec.summary = %q{Base class to provide common methods for the quickbooks-ruby gem}
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-08-12T12:29:53.867-07:00">
3
+ <Customer domain="QBO" sparse="false">
4
+ <Id>2</Id>
5
+ <SyncToken>0</SyncToken>
6
+ <MetaData>
7
+ <CreateTime>2015-06-24T16:49:28-07:00</CreateTime>
8
+ <LastUpdatedTime>2015-07-01T12:56:01-07:00</LastUpdatedTime>
9
+ </MetaData>
10
+ <GivenName>Bill</GivenName>
11
+ <FamilyName>Lucchini</FamilyName>
12
+ <FullyQualifiedName>Bill's Windsurf Shop</FullyQualifiedName>
13
+ <CompanyName>Bill's Windsurf Shop</CompanyName>
14
+ <DisplayName>Bill's Windsurf Shop</DisplayName>
15
+ <PrintOnCheckName>Bill's Windsurf Shop</PrintOnCheckName>
16
+ <Active>true</Active>
17
+ <PrimaryPhone>
18
+ <FreeFormNumber>(415) 444-6538</FreeFormNumber>
19
+ </PrimaryPhone>
20
+ <PrimaryEmailAddr>
21
+ <Address>Surf@Intuit.com</Address>
22
+ </PrimaryEmailAddr>
23
+ <Taxable>false</Taxable>
24
+ <BillAddr>
25
+ <Id>3</Id>
26
+ <Line1>12 Ocean Dr.</Line1>
27
+ <City>Half Moon Bay</City>
28
+ <CountrySubDivisionCode>CA</CountrySubDivisionCode>
29
+ <PostalCode>94213</PostalCode>
30
+ <Lat>37.4307072</Lat>
31
+ <Long>-122.4295234</Long>
32
+ </BillAddr>
33
+ <Job>false</Job>
34
+ <BillWithParent>false</BillWithParent>
35
+ <Balance>85.00</Balance>
36
+ <BalanceWithJobs>85.00</BalanceWithJobs>
37
+ <PreferredDeliveryMethod>Print</PreferredDeliveryMethod>
38
+ </Customer>
39
+ </IntuitResponse>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-08-12T12:45:49.202-07:00">
3
+ <Employee domain="QBO" sparse="false">
4
+ <Id>55</Id>
5
+ <SyncToken>0</SyncToken>
6
+ <MetaData>
7
+ <CreateTime>2015-06-30T11:21:48-07:00</CreateTime>
8
+ <LastUpdatedTime>2015-06-30T11:21:48-07:00</LastUpdatedTime>
9
+ </MetaData>
10
+ <GivenName>Emily</GivenName>
11
+ <FamilyName>Platt</FamilyName>
12
+ <DisplayName>Emily Platt</DisplayName>
13
+ <PrintOnCheckName>Emily Platt</PrintOnCheckName>
14
+ <Active>true</Active>
15
+ <BillableTime>false</BillableTime>
16
+ </Employee>
17
+ </IntuitResponse>
@@ -0,0 +1,26 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2
+ <IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-08-12T08:05:03.899-07:00">
3
+ <Item domain="QBO" sparse="false">
4
+ <Id>5</Id>
5
+ <SyncToken>2</SyncToken>
6
+ <MetaData>
7
+ <CreateTime>2015-06-29T10:42:19-07:00</CreateTime>
8
+ <LastUpdatedTime>2015-07-02T13:16:17-07:00</LastUpdatedTime>
9
+ </MetaData>
10
+ <Name>Rock Fountain</Name>
11
+ <Description>Rock Fountain</Description>
12
+ <Active>true</Active>
13
+ <FullyQualifiedName>Rock Fountain</FullyQualifiedName>
14
+ <Taxable>true</Taxable>
15
+ <UnitPrice>275</UnitPrice>
16
+ <Type>Inventory</Type>
17
+ <IncomeAccountRef name="Sales of Product Income">79</IncomeAccountRef>
18
+ <PurchaseDesc>Rock Fountain</PurchaseDesc>
19
+ <PurchaseCost>125</PurchaseCost>
20
+ <ExpenseAccountRef name="Cost of Goods Sold">80</ExpenseAccountRef>
21
+ <AssetAccountRef name="Inventory Asset">81</AssetAccountRef>
22
+ <TrackQtyOnHand>true</TrackQtyOnHand>
23
+ <QtyOnHand>2</QtyOnHand>
24
+ <InvStartDate>2015-07-02</InvStartDate>
25
+ </Item>
26
+ </IntuitResponse>
@@ -57,6 +57,14 @@ describe Quickbooks::Base do
57
57
  expect(qr.show.last).to match /100\.0/
58
58
  end
59
59
 
60
+ it "display another entity using the entity options" do
61
+ xml = read_fixture('payments')
62
+ stub_response(xml)
63
+ qr = Quickbooks::Base.new(full_account, :invoice)
64
+ expect(qr.show).to be_empty
65
+ expect(qr.show(entity: :payment).last).to match /100\.0/
66
+ end
67
+
60
68
  it "description should display 'nil' as no description fits" do
61
69
  pending 'Need to find a transaction or name entity that does not match txn_date'
62
70
  xml = read_fixture('dummy')
@@ -103,8 +111,8 @@ describe Quickbooks::Base do
103
111
  describe ".create_service_for" do
104
112
  it "creates a access_token service" do
105
113
  qb = Quickbooks::Base.new(full_account)
106
- service = qb.create_service_for :access_token
107
- expect(service.class.name).to match /Service::AccessToken/
114
+ qb.create_service_for :access_token
115
+ expect(qb.service.class.name).to match /Service::AccessToken/
108
116
  end
109
117
  end
110
118
 
@@ -116,6 +124,14 @@ describe Quickbooks::Base do
116
124
  result = qr.find_by_id(28)
117
125
  expect(result.id).to eq 156
118
126
  end
127
+
128
+ it 'grabs object from different entity' do
129
+ xml = read_fixture('item_5')
130
+ stub_response(xml)
131
+ qr = Quickbooks::Base.new(full_account)
132
+ result = qr.find_by_id(5, :item)
133
+ expect(result.id).to eq 5
134
+ end
119
135
  end
120
136
 
121
137
  describe ".display_name_sql" do
@@ -125,9 +141,27 @@ describe Quickbooks::Base do
125
141
  end
126
142
 
127
143
  it 'for custom usage' do
128
- qr = Quickbooks::Base.new(full_account, :customer)
129
- sql = qr.display_name_sql('Chuck Russell', entity: 'Vendor', select: '*')
130
- expect(sql).to eq "SELECT * FROM Vendor WHERE DisplayName = 'Chuck Russell'"
144
+ qr = Quickbooks::Base.new(full_account)
145
+ sql = qr.display_name_sql("Jonnie O'Meara", entity: :vendor, select: '*')
146
+ expect(sql).to eq "SELECT * FROM Vendor WHERE DisplayName = 'Jonnie O\\'Meara'"
147
+ end
148
+ end
149
+
150
+ describe ".find_by_display_name" do
151
+ it 'use entity on initialization' do
152
+ xml = read_fixture('employee_55')
153
+ stub_response(xml)
154
+ qr = Quickbooks::Base.new(full_account, :employee)
155
+ result = qr.find_by_display_name("Emily Platt")
156
+ expect(result.first.id).to eq 55
157
+ end
158
+
159
+ it 'passing in the entity' do
160
+ xml = read_fixture('customer_2')
161
+ stub_response(xml)
162
+ qr = Quickbooks::Base.new(full_account)
163
+ result = qr.find_by_display_name("Bill's Windsurf Shop", entity: :customer)
164
+ expect(result.first.id).to eq 2
131
165
  end
132
166
  end
133
167
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quickbooks-ruby-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-04 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: quickbooks-ruby
@@ -83,9 +83,12 @@ files:
83
83
  - lib/quickbooks/base/configuration.rb
84
84
  - lib/quickbooks/base/finders.rb
85
85
  - quickbooks-ruby-base.gemspec
86
+ - spec/fixtures/customer_2.xml
86
87
  - spec/fixtures/dummy.xml
88
+ - spec/fixtures/employee_55.xml
87
89
  - spec/fixtures/invoice.xml
88
90
  - spec/fixtures/invoices.xml
91
+ - spec/fixtures/item_5.xml
89
92
  - spec/fixtures/payments.xml
90
93
  - spec/fixtures/tax_codes.xml
91
94
  - spec/fixtures/vendors.xml
@@ -116,9 +119,12 @@ signing_key:
116
119
  specification_version: 4
117
120
  summary: Base class to provide common methods for the quickbooks-ruby gem
118
121
  test_files:
122
+ - spec/fixtures/customer_2.xml
119
123
  - spec/fixtures/dummy.xml
124
+ - spec/fixtures/employee_55.xml
120
125
  - spec/fixtures/invoice.xml
121
126
  - spec/fixtures/invoices.xml
127
+ - spec/fixtures/item_5.xml
122
128
  - spec/fixtures/payments.xml
123
129
  - spec/fixtures/tax_codes.xml
124
130
  - spec/fixtures/vendors.xml