quickbooks-ruby-base 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +17 -0
- data/lib/quickbooks/base/finders.rb +28 -0
- data/lib/quickbooks/base.rb +10 -8
- data/quickbooks-ruby-base.gemspec +1 -1
- data/spec/quickbooks_ruby_base_spec.rb +15 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTgzZjdjZGZjODEyMmMyNjk4MjM0ZmNmNjZhM2Q0YmJlN2U3NDI1Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MThiMzIwNmQ2NjQ3NTEzMTdhZTQwNzZmZDU0ZDA2NmQ0ZmExNjdiNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTE4MTkxNjU4M2M3NmVkNjY1OTRmMTNjMDQyNTAxOGJiYWJhMTdhYzNlYzYz
|
10
|
+
YTcyMDJlMjM2YjI2NzZmNWJhYzgzZmZmZWE5YWIwZTc2ZTU2NDExZjdjZWY2
|
11
|
+
MWNiYTYzMTYwMDc2N2ZhNTkyMTViNWYwZWIyZDEwNDc0N2YyZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjMwYWQ0ZTUzYWMxOTc2YjhjYzRjNjU0Y2EwZWIyYjdmNGIyMjc1NWQ5ZmY4
|
14
|
+
ZThhZTlkY2JhMmZmZTk5MWQ4YWJiZjc3NTZkMmZlM2I5ZGY4NGUyMGJhNmE3
|
15
|
+
NmVkODMyM2NjYjVjZjY4YTk1Nzc4MmFkMjc2YzJlMTFjODhiYTM=
|
data/README.md
CHANGED
@@ -72,6 +72,23 @@ base = Quickbooks::Base.new(account, :payment_method)
|
|
72
72
|
|
73
73
|
```
|
74
74
|
|
75
|
+
### id()
|
76
|
+
Convenience method to fetch an entity by its reference id
|
77
|
+
```
|
78
|
+
base = Quickbooks::Base.new(account, :customer)
|
79
|
+
>> base.id(1)
|
80
|
+
```
|
81
|
+
|
82
|
+
### display_name()
|
83
|
+
Convenience method to search for a name entity by DisplayName.
|
84
|
+
Note: Leverages proper escaping via the [Quickbooks::Util::QueryBuilder](https://github.com/ruckus/quickbooks-ruby/blob/master/lib/quickbooks/util/query_builder.rb) module.
|
85
|
+
```
|
86
|
+
base = Quickbooks::Base.new(account, :customer)
|
87
|
+
>> base.display_name('Chuck Russell')
|
88
|
+
# Generates a query based on the following SQL
|
89
|
+
# "Select Id, DisplayName From Customer WHERE DisplayName = 'Chuck Russell' LIMIT 1"
|
90
|
+
```
|
91
|
+
|
75
92
|
## Configuration
|
76
93
|
|
77
94
|
As the first argument, the `Quickbooks::Base` class expects a persistent object that holds OAuth connection information.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Quickbooks
|
2
|
+
class Base
|
3
|
+
module Finders
|
4
|
+
def qbuilder
|
5
|
+
Quickbooks::Util::QueryBuilder.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def sql_builder(where, options = {})
|
9
|
+
options[:entity] ||= @entity
|
10
|
+
options[:select] ||= '*'
|
11
|
+
options[:limit] ||= 1
|
12
|
+
"Select #{options[:select]} From #{options[:entity]} WHERE #{where} LIMIT #{options[:limit]}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def display_name_sql(display_name, options = {})
|
16
|
+
options[:select] ||= 'Id, DisplayName'
|
17
|
+
where = qbuilder.clause("DisplayName", "=", display_name)
|
18
|
+
sql_builder(where, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def display_name(display_name, options = {})
|
22
|
+
sql = display_name_sql(display_name, options)
|
23
|
+
@service.query(sql)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/quickbooks/base.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'quickbooks-ruby'
|
2
2
|
require_relative 'base/configuration'
|
3
|
+
require_relative 'base/finders'
|
3
4
|
|
4
5
|
module Quickbooks
|
5
6
|
class Base
|
6
|
-
attr_reader :service
|
7
|
+
attr_reader :service, :entity
|
8
|
+
include Finders
|
7
9
|
extend Configuration
|
8
10
|
|
9
11
|
def initialize(account, type = nil)
|
@@ -11,18 +13,18 @@ module Quickbooks
|
|
11
13
|
create_service_for(type) if type
|
12
14
|
end
|
13
15
|
|
14
|
-
def generate_quickbooks_ruby_namespace(
|
15
|
-
|
16
|
-
"Quickbooks::#{type}::#{
|
16
|
+
def generate_quickbooks_ruby_namespace(entity, type = 'Model')
|
17
|
+
@entity = entity.is_a?(Symbol) ? entity.to_s.camelcase : entity
|
18
|
+
"Quickbooks::#{type}::#{@entity}"
|
17
19
|
end
|
18
20
|
|
19
|
-
def quickbooks_ruby_model(
|
20
|
-
generate_quickbooks_ruby_namespace(
|
21
|
+
def quickbooks_ruby_model(entity, *args)
|
22
|
+
generate_quickbooks_ruby_namespace(entity, 'Model').constantize.new(*args)
|
21
23
|
end
|
22
24
|
alias_method :qr_model, :quickbooks_ruby_model
|
23
25
|
|
24
|
-
def quickbooks_ruby_service(
|
25
|
-
generate_quickbooks_ruby_namespace(
|
26
|
+
def quickbooks_ruby_service(entity)
|
27
|
+
generate_quickbooks_ruby_namespace(entity, 'Service').constantize.new
|
26
28
|
end
|
27
29
|
alias_method :qr_service, :quickbooks_ruby_service
|
28
30
|
|
@@ -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.
|
7
|
+
spec.version = '1.2.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}
|
@@ -29,7 +29,7 @@ describe Quickbooks::Base do
|
|
29
29
|
|
30
30
|
describe ".show" do
|
31
31
|
|
32
|
-
it "description should display using the
|
32
|
+
it "description should display using the display_name for vendor" do
|
33
33
|
xml = read_fixture('vendors')
|
34
34
|
stub_response(xml)
|
35
35
|
qr = Quickbooks::Base.new(full_account, :vendor)
|
@@ -108,8 +108,7 @@ describe Quickbooks::Base do
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
describe ".
|
112
|
-
|
111
|
+
describe ".id" do
|
113
112
|
it 'grabs a object by id' do
|
114
113
|
xml = read_fixture('invoice')
|
115
114
|
stub_response(xml)
|
@@ -119,6 +118,19 @@ describe Quickbooks::Base do
|
|
119
118
|
end
|
120
119
|
end
|
121
120
|
|
121
|
+
describe ".display_name_sql" do
|
122
|
+
it 'for basic usage' do
|
123
|
+
qr = Quickbooks::Base.new(full_account, :customer)
|
124
|
+
expect(qr.display_name_sql('Chuck Russell')).to eq "Select Id, DisplayName From Customer WHERE DisplayName = 'Chuck Russell' LIMIT 1"
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'for custom usage' do
|
128
|
+
qr = Quickbooks::Base.new(full_account, :customer)
|
129
|
+
sql = qr.display_name_sql('Chuck Russell', entity: 'Vendor', select: '*', limit: 5)
|
130
|
+
expect(sql).to eq "Select * From Vendor WHERE DisplayName = 'Chuck Russell' LIMIT 5"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
122
134
|
def read_fixture(filename)
|
123
135
|
File.read(File.join('spec', 'fixtures', "#{filename}.xml"))
|
124
136
|
end
|
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.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: quickbooks-ruby
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- lib/quickbooks-ruby-base.rb
|
82
82
|
- lib/quickbooks/base.rb
|
83
83
|
- lib/quickbooks/base/configuration.rb
|
84
|
+
- lib/quickbooks/base/finders.rb
|
84
85
|
- quickbooks-ruby-base.gemspec
|
85
86
|
- spec/fixtures/dummy.xml
|
86
87
|
- spec/fixtures/invoice.xml
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: '0'
|
111
112
|
requirements: []
|
112
113
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.4.6
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: Base class to provide common methods for the quickbooks-ruby gem
|
@@ -123,4 +124,3 @@ test_files:
|
|
123
124
|
- spec/fixtures/vendors.xml
|
124
125
|
- spec/quickbooks_ruby_base_spec.rb
|
125
126
|
- spec/spec_helper.rb
|
126
|
-
has_rdoc:
|