quick_book_gateway 0.0.2 → 0.0.4
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.
- data/README +16 -1
- data/lib/gateway/quickbook.rb +1 -1
- data/lib/service/finder.rb +45 -18
- data/lib/service/persistence.rb +5 -5
- data/lib/service/query.rb +3 -2
- data/lib/service/record.rb +22 -4
- metadata +20 -16
- checksums.yaml +0 -7
data/README
CHANGED
@@ -49,7 +49,8 @@
|
|
49
49
|
5. You are ready to create, fetch or modify any data on Quickbook.
|
50
50
|
|
51
51
|
For ex.
|
52
|
-
|
52
|
+
|
53
|
+
customer = Customer.find(DisplayName: "Kunal")
|
53
54
|
customer.CompanyName = "Kunal Lalge"
|
54
55
|
customer.save!
|
55
56
|
|
@@ -58,14 +59,22 @@
|
|
58
59
|
For ex. https://developer.intuit.com/docs/api/accounting/customer
|
59
60
|
|
60
61
|
7. One can also use callbacks, below are list of callbacks:
|
62
|
+
|
61
63
|
|
62
64
|
before_save - Executes every time before object save
|
65
|
+
|
63
66
|
after_save - Executes every time after object save
|
67
|
+
|
64
68
|
before_create - Executes only before new object save
|
69
|
+
|
65
70
|
after_create - Executes only after new object save
|
71
|
+
|
66
72
|
before_update - Executes only before existing object save
|
73
|
+
|
67
74
|
after_update - Executes only after existing object save
|
75
|
+
|
68
76
|
before_destroy - Executes every time before destroy an object
|
77
|
+
|
69
78
|
after_destroy - Executes every time after destroy an object
|
70
79
|
|
71
80
|
Ex.
|
@@ -75,6 +84,12 @@
|
|
75
84
|
end
|
76
85
|
end
|
77
86
|
|
87
|
+
|
88
|
+
## UPDATES
|
89
|
+
|
90
|
+
0.0.4 - find_all will fetch all records using pagination
|
91
|
+
|
92
|
+
|
78
93
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
79
94
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
80
95
|
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
data/lib/gateway/quickbook.rb
CHANGED
@@ -76,7 +76,7 @@ module Gateway
|
|
76
76
|
private
|
77
77
|
def url(path, params = {})
|
78
78
|
url = File.join(self.api, API::VERSION, API::COMPANY.gsub("?", self.company_id.to_s), path)
|
79
|
-
return "#{url}
|
79
|
+
return "#{url}?minorversion=4&#{params.to_uri_query}"
|
80
80
|
end
|
81
81
|
|
82
82
|
public
|
data/lib/service/finder.rb
CHANGED
@@ -4,6 +4,25 @@ module Service
|
|
4
4
|
base.send :extend, Query
|
5
5
|
end
|
6
6
|
|
7
|
+
private
|
8
|
+
def query_data(options, total_records, records)
|
9
|
+
qb_data = quickbook_gateway.query_data(create_query(options))
|
10
|
+
|
11
|
+
if qb_data[entity]
|
12
|
+
qb_data[entity].each{|qb_record|
|
13
|
+
model = self.new(qb_record)
|
14
|
+
model.is_new_record = false
|
15
|
+
|
16
|
+
records << model
|
17
|
+
}
|
18
|
+
|
19
|
+
if total_records > records.length
|
20
|
+
options[:start] = records.length + 1
|
21
|
+
query_data(options, total_records, records)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
7
26
|
#Find All records related to options provided
|
8
27
|
#Options are as below
|
9
28
|
# :conditions => where clause. Default is NOTHING
|
@@ -11,19 +30,36 @@ module Service
|
|
11
30
|
#
|
12
31
|
# :select => Needed column list. Default is ALL
|
13
32
|
# For ex. if you want Id, DisplayName of all customers then :select => "Id, DisplayName"
|
14
|
-
|
33
|
+
public
|
34
|
+
def find_all(options = {}, top = nil)
|
15
35
|
raise QuickBookgatewayInvalid unless quickbook_gateway
|
16
36
|
|
37
|
+
top = options.delete(:top) unless top
|
38
|
+
|
17
39
|
records = Array.new
|
18
40
|
|
19
|
-
|
41
|
+
unless options.keys.index(:conditions)
|
42
|
+
conditions = [""]
|
43
|
+
options.keys.each{|column|
|
44
|
+
conditions[0] += "AND #{column}=?"
|
45
|
+
conditions << options.delete(column)
|
46
|
+
}
|
20
47
|
|
21
|
-
|
22
|
-
model = self.new(qb_record)
|
23
|
-
model.is_new_record = false
|
48
|
+
conditions[0] = conditions[0][4..conditions[0].length].to_s
|
24
49
|
|
25
|
-
|
26
|
-
|
50
|
+
options[:conditions] = conditions
|
51
|
+
end
|
52
|
+
|
53
|
+
if top
|
54
|
+
options[:top] = top
|
55
|
+
total_records = top
|
56
|
+
else
|
57
|
+
total_records = quickbook_gateway.query_data(create_query(options.merge({:select => "COUNT(*)"})))["totalCount"].to_i
|
58
|
+
end
|
59
|
+
|
60
|
+
if total_records > 0
|
61
|
+
query_data(options, total_records, records)
|
62
|
+
end
|
27
63
|
|
28
64
|
return records
|
29
65
|
end
|
@@ -40,8 +76,7 @@ module Service
|
|
40
76
|
return model
|
41
77
|
end
|
42
78
|
|
43
|
-
options[
|
44
|
-
return self.find_all(options)[0]
|
79
|
+
return self.find_all(options, 1)[0]
|
45
80
|
end
|
46
81
|
|
47
82
|
#Try to find record on QuickBook Online as per options provided else create instance of new
|
@@ -53,15 +88,7 @@ module Service
|
|
53
88
|
def find_or_initialize(options)
|
54
89
|
return new() if(options.keys.length == 0)
|
55
90
|
|
56
|
-
|
57
|
-
options.keys.each{|column|
|
58
|
-
conditions[0] += "AND #{column}=?"
|
59
|
-
conditions << options[column]
|
60
|
-
}
|
61
|
-
|
62
|
-
conditions[0] = conditions[0][4..conditions[0].length].to_s
|
63
|
-
|
64
|
-
qb_record = find({:conditions => conditions})
|
91
|
+
qb_record = find(options.dup)
|
65
92
|
|
66
93
|
qb_record = new(options) unless qb_record
|
67
94
|
|
data/lib/service/persistence.rb
CHANGED
@@ -7,8 +7,8 @@ module Service
|
|
7
7
|
|
8
8
|
private
|
9
9
|
def qb_entity
|
10
|
-
return case
|
11
|
-
when 'TaxRate' then '
|
10
|
+
return case entity
|
11
|
+
when 'TaxRate' then 'taxservice'
|
12
12
|
else entity.downcase
|
13
13
|
end
|
14
14
|
end
|
@@ -25,7 +25,7 @@ module Service
|
|
25
25
|
params = {}
|
26
26
|
params[:operation] = :update unless(self.is_new_record)
|
27
27
|
|
28
|
-
self.attributes = quickbook_gateway.post(qb_entity, params , self.attributes.to_json())[
|
28
|
+
self.attributes = quickbook_gateway.post(qb_entity, params , self.attributes.to_json())[entity]
|
29
29
|
|
30
30
|
after_update unless new_record
|
31
31
|
after_create if new_record
|
@@ -38,12 +38,12 @@ module Service
|
|
38
38
|
def destroy
|
39
39
|
before_destroy
|
40
40
|
|
41
|
-
entities_for_delete = ["INVOICE"]
|
41
|
+
entities_for_delete = ["INVOICE", "PAYMENT", "SALESRECEIPT", "REFUNDRECEIPT"]
|
42
42
|
|
43
43
|
raise RecordDeleteError, "Can't delete record without ID" if self["Id"].to_i == 0
|
44
44
|
if(entities_for_delete.index(qb_entity.upcase))
|
45
45
|
raise RecordDeleteError, "Can't delete new record" if self.is_new_record
|
46
|
-
quickbook_gateway.post(qb_entity.downcase, {:operation => :delete} , {"Id" => self["Id"]}.to_json())
|
46
|
+
quickbook_gateway.post(qb_entity.downcase, {:operation => :delete} , {"Id" => self["Id"], "SyncToken" => self["SyncToken"]}.to_json())
|
47
47
|
self.attributes = {}
|
48
48
|
self.is_new_record = true
|
49
49
|
else
|
data/lib/service/query.rb
CHANGED
@@ -17,9 +17,10 @@ module Service
|
|
17
17
|
condition = "WHERE #{sanitize_sql(options[:conditions])}" unless(options[:conditions].to_s.blank?)
|
18
18
|
columns = options[:select] unless(options[:select].to_s.blank?)
|
19
19
|
|
20
|
-
|
20
|
+
start = "STARTPOSITION #{options[:start]}" if(options[:start].to_i > 0)
|
21
|
+
max_result = "MAXRESULTS #{options[:top]}" if(options[:top].to_i > 0)
|
21
22
|
|
22
|
-
return "SELECT #{columns} FROM #{entity} #{condition} #{max_result}"
|
23
|
+
return "SELECT #{columns} FROM #{entity} #{condition} #{start} #{max_result}"
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/service/record.rb
CHANGED
@@ -3,12 +3,18 @@ module Service
|
|
3
3
|
#QuickBook API documentation https://developer.intuit.com/v2/apiexplorer?apiname=V3QBO
|
4
4
|
class Record
|
5
5
|
@@quickbook_gateway
|
6
|
-
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :entity_name
|
9
|
+
end
|
10
|
+
|
7
11
|
extend Service::Finder
|
8
12
|
include Service::Persistence
|
9
13
|
include Errors
|
10
14
|
|
11
|
-
|
15
|
+
attr_reader :attributes
|
16
|
+
|
17
|
+
attr_accessor :is_new_record
|
12
18
|
|
13
19
|
#Set instance of Gateway::QuickBook
|
14
20
|
def self.quickbook_gateway=(gateway)
|
@@ -28,13 +34,25 @@ module Service
|
|
28
34
|
self.attributes = attributes
|
29
35
|
end
|
30
36
|
|
37
|
+
def attributes=(values)
|
38
|
+
@attributes = Hash.new
|
39
|
+
values.keys.each{|key|
|
40
|
+
self[key] = values[key]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
31
44
|
private
|
32
45
|
def self.entity
|
33
|
-
self.name.split("::").last
|
46
|
+
self.entity_name = self.entity_name || self.name.split("::").last
|
47
|
+
return self.entity_name
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.set_entity_name(name)
|
51
|
+
self.entity_name = name
|
34
52
|
end
|
35
53
|
|
36
54
|
def entity
|
37
|
-
self.class.entity
|
55
|
+
return self.class.entity
|
38
56
|
end
|
39
57
|
|
40
58
|
public
|
metadata
CHANGED
@@ -1,70 +1,74 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_book_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Kunal Lalge
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: oauth
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0'
|
27
|
-
description: 'Connect to QuickBook Online and easily synchronize data. Please read
|
30
|
+
description: ! 'Connect to QuickBook Online and easily synchronize data. Please read
|
28
31
|
README file to know how to use located at gems-directory/quick_book_gateway-0.0.2/README '
|
29
32
|
email: kunallalge@gmail.com
|
30
33
|
executables: []
|
31
34
|
extensions: []
|
32
35
|
extra_rdoc_files: []
|
33
36
|
files:
|
34
|
-
-
|
37
|
+
- lib/quick_book_gateway.rb
|
38
|
+
- lib/errors.rb
|
39
|
+
- lib/core_ext/string.rb
|
35
40
|
- lib/core_ext/hash.rb
|
36
41
|
- lib/core_ext/nil.rb
|
37
|
-
- lib/core_ext/string.rb
|
38
|
-
- lib/errors.rb
|
39
42
|
- lib/gateway/quickbook.rb
|
40
43
|
- lib/gateway/result.rb
|
41
|
-
- lib/
|
42
|
-
- lib/service/callback.rb
|
44
|
+
- lib/service/query.rb
|
43
45
|
- lib/service/finder.rb
|
46
|
+
- lib/service/callback.rb
|
44
47
|
- lib/service/persistence.rb
|
45
|
-
- lib/service/query.rb
|
46
48
|
- lib/service/record.rb
|
49
|
+
- README
|
47
50
|
homepage: https://rubygems.org/gems/quick_book_gateway
|
48
51
|
licenses: []
|
49
|
-
metadata: {}
|
50
52
|
post_install_message:
|
51
53
|
rdoc_options: []
|
52
54
|
require_paths:
|
53
55
|
- lib
|
54
56
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
55
58
|
requirements:
|
56
|
-
- -
|
59
|
+
- - ! '>='
|
57
60
|
- !ruby/object:Gem::Version
|
58
61
|
version: '0'
|
59
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
60
64
|
requirements:
|
61
|
-
- -
|
65
|
+
- - ! '>='
|
62
66
|
- !ruby/object:Gem::Version
|
63
67
|
version: '0'
|
64
68
|
requirements: []
|
65
69
|
rubyforge_project:
|
66
|
-
rubygems_version:
|
70
|
+
rubygems_version: 1.8.24
|
67
71
|
signing_key:
|
68
|
-
specification_version:
|
72
|
+
specification_version: 3
|
69
73
|
summary: QuickBook Online Gateway
|
70
74
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 3c8d6f892535dd7bd3d268c41b800805c5127a3b
|
4
|
-
data.tar.gz: 33ceb4988781d01fe856a0d034c5d5807cf51b74
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: fdedd1f3a31a592b01c8df6c127249613259d388c5a1cd76e3b187136cb43a095c6b2fd9ca4c6a6e528d23f71ebdafa0abfb88bfaf6e63b6658a042b624ccd45
|
7
|
-
data.tar.gz: e10c5855b3006c6a4b25b1132823ef382e458bdba28f9b9a9b98934f0f82ce6a59ab20394b1c6ffc71e085538a2ca29dfb5243591cd97bc9b62d2e28fa366e72
|