qbo_api 1.3.0 → 1.4.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e327269409bb7956e548ad03f37dd9a39d2bcd
4
- data.tar.gz: 6aed50f15871f495593fc3818bc545e6e99d613e
3
+ metadata.gz: 4e13df877cf63f1959afcef602f250f85f16c73f
4
+ data.tar.gz: cffab533c3c65f5db86830a721341b2680cafac9
5
5
  SHA512:
6
- metadata.gz: 9cba0e85a274833fb6a27c859a9201803c0c2bc47243a5baca9c671be31c41820d356afd7c8616121f12ca4165e4a9389ef818c887bbd521ec69230695b38b55
7
- data.tar.gz: 0c3eae6343927f9cec48061cb8b4a1281c26933b6aff6bccfa674f2222685ce62bf3d60c8bc7c1421335dd14a2737b905c0a094e1eab67a297cdb112f64cf048
6
+ metadata.gz: 95c7b44ab0590fbc503f9b38dbd1d7b34cb46319ff932b7954de8803b275a05b4f3a62e776e7d18e11b472d0aba2460cd6e641459c7c43136395760e06c97daa
7
+ data.tar.gz: c758d9dfabd28aa45bed53da9deadb18ae942246c80ca267fa98e12765723a6ab40c821a57f29dccd9a95c5057bd3fb1bdc4dd89d804b4e95cc092bf03c6bed4
data/README.md CHANGED
@@ -71,10 +71,25 @@ QboApi.log = true
71
71
  ```ruby
72
72
  QboApi.logger = Rails.logger
73
73
  ```
74
- - To run all create, modify, and delete requests with unique [RequestIds](https://developer.intuit.com/hub/blog/2015/04/06/15346).
74
+ - To run all requests with unique [RequestIds](https://developer.intuit.com/hub/blog/2015/04/06/15346).
75
75
  ```ruby
76
76
  QboApi.request_id = true
77
77
  ```
78
+ - To run individual requests with a RequestId then do something like this:
79
+ ```ruby
80
+ resp = qbo_api.create(:bill, payload: bill_hash, params: { requestid: qbo_api.uuid })
81
+ # Works with .get, .create, .update, .query methods
82
+ ```
83
+ - To run all requests with a [Minor version](https://developer.intuit.com/docs/0100_quickbooks_online/0200_dev_guides/accounting/minor_versions).
84
+ ```ruby
85
+ QboApi.minor_version = 8
86
+ ```
87
+ - To run individual requests with a minor version then do something like this:
88
+ ```ruby
89
+ resp = qbo_api.get(:item, 8, params: { minorversion: 8 })
90
+ # Works with .get, .create, .update, .query methods
91
+ ```
92
+
78
93
 
79
94
  ### Create
80
95
  ```ruby
@@ -50,24 +50,24 @@ class QboApi
50
50
  end
51
51
  end
52
52
 
53
- def query(query)
53
+ def query(query, params: nil)
54
54
  path = "#{realm_id}/query?query=#{CGI.escape(query)}"
55
55
  entity = extract_entity_from_query(query, to_sym: true)
56
- request(:get, entity: entity, path: path)
56
+ request(:get, entity: entity, path: path, params: params)
57
57
  end
58
58
 
59
- def get(entity, id)
59
+ def get(entity, id, params: nil)
60
60
  path = "#{entity_path(entity)}/#{id}"
61
- request(:get, entity: entity, path: path)
61
+ request(:get, entity: entity, path: path, params: params)
62
62
  end
63
63
 
64
- def create(entity, payload:)
65
- request(:post, entity: entity, path: entity_path(entity), payload: payload)
64
+ def create(entity, payload:, params: nil)
65
+ request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params)
66
66
  end
67
67
 
68
- def update(entity, id:, payload:)
68
+ def update(entity, id:, payload:, params: nil)
69
69
  payload.merge!(set_update(entity, id))
70
- request(:post, entity: entity, path: entity_path(entity), payload: payload)
70
+ request(:post, entity: entity, path: entity_path(entity), payload: payload, params: params)
71
71
  end
72
72
 
73
73
  def delete(entity, id:)
@@ -109,13 +109,14 @@ class QboApi
109
109
  end while (results ? results.size == max : false)
110
110
  end
111
111
 
112
- def request(method, path:, entity: nil, payload: nil)
112
+ def request(method, path:, entity: nil, payload: nil, params: nil)
113
113
  raw_response = connection.send(method) do |req|
114
+ path = finalize_path(path, params: params)
114
115
  case method
115
116
  when :get, :delete
116
117
  req.url path
117
118
  when :post, :put
118
- req.url add_request_id_to(path)
119
+ req.url path
119
120
  req.body = JSON.generate(payload)
120
121
  end
121
122
  end
@@ -32,5 +32,13 @@ class QboApi
32
32
  def request_id=(value)
33
33
  @request_id = value
34
34
  end
35
+
36
+ def minor_version
37
+ @minor_version ||= false
38
+ end
39
+
40
+ def minor_version=(value)
41
+ @minor_version = value
42
+ end
35
43
  end
36
44
  end
@@ -17,6 +17,13 @@ class QboApi
17
17
  SecureRandom.uuid
18
18
  end
19
19
 
20
+ def finalize_path(path, params: nil)
21
+ path = add_request_id_to(path)
22
+ path = add_minor_version_to(path)
23
+ path = add_params_to_path(path: path, params: params) if params
24
+ path
25
+ end
26
+
20
27
  def add_request_id_to(path)
21
28
  if QboApi.request_id
22
29
  add_params_to_path(path: path, params: { "requestid" => uuid })
@@ -25,6 +32,14 @@ class QboApi
25
32
  end
26
33
  end
27
34
 
35
+ def add_minor_version_to(path)
36
+ if minor_version = QboApi.minor_version
37
+ add_params_to_path(path: path, params: { "minorversion" => minor_version })
38
+ else
39
+ path
40
+ end
41
+ end
42
+
28
43
  def add_params_to_path(path:, params:)
29
44
  uri = URI.parse(path)
30
45
  params.each do |p|
@@ -1,3 +1,3 @@
1
1
  class QboApi
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qbo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Pelczarski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-28 00:00:00.000000000 Z
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler