lightspeed_ruby 0.3.0 → 0.3.1

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: f032891a3ff992f221f39227cbbe4b7bba13a96c
4
- data.tar.gz: e3860fe3eb16993f95047e3b28e309f91b8ed0c3
3
+ metadata.gz: d34283a7c48e00ef4018116853b4d3ee6ffe04ab
4
+ data.tar.gz: efc454725299780d31abb0044d2bf3450d525a38
5
5
  SHA512:
6
- metadata.gz: ed625008cbd0580669277b29ed6c4aae1eb5ed08aff7fb7643157a59c1619378345644635bdf19ed52e31dfd7101a7a2df48f424f21183bb0528b92443d6efab
7
- data.tar.gz: bc7b279263bef9399cc79a9956ec9d26de50a3ab9649bd7d878cfa9e90540fee70bf8057463bad9ed1ab64545002204c21a5c41d9936d8c9225223abdb719f35
6
+ metadata.gz: dda45771b9be156c251935e2038c56b193ea82f70eb859de4abbe6ca38b396ac5b7fab0f5717a85fe1a0f1265a0f5bb701ac22b6f3d38bf7318d2006e64a40bd
7
+ data.tar.gz: a51fff917ad7cae09c526ebd644ce1ef98940bdb8f5a972708dd2f476d89d33407a41e6ad6a674a6e644c2fdbe6b79213a1fec6ef106f35339639c2544b914c1
@@ -0,0 +1,12 @@
1
+ module Lightspeed
2
+ module API
3
+ class Error < StandardError
4
+ attr_reader :response
5
+
6
+ def initialize(message:, response:)
7
+ @response = response
8
+ super(message)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -9,10 +9,12 @@ module Lightspeed
9
9
  count = Float::INFINITY
10
10
  while offset < count
11
11
  response = yield(options_string(offset, limit))
12
- attributes = response.delete("@attributes")
12
+ body = response.body
13
+ raise_error(response) unless response.success?
14
+ attributes = body.delete("@attributes")
13
15
  count = attributes["count"].to_i
14
16
  offset = attributes["offset"].to_i + limit
15
- results << response.values
17
+ results << body.values
16
18
  end
17
19
  results.flatten
18
20
  end
@@ -22,6 +24,13 @@ module Lightspeed
22
24
  def options_string(offset, limit)
23
25
  "offset=#{offset}&limit=#{limit}"
24
26
  end
27
+
28
+ def raise_error(response)
29
+ raise Lightspeed::API::Error.new(
30
+ message: response.body["message"],
31
+ response: response,
32
+ )
33
+ end
25
34
  end
26
35
  end
27
36
  end
@@ -15,7 +15,7 @@ module Lightspeed
15
15
 
16
16
  def all(limit: nil)
17
17
  with_pages(limit: limit) do |options|
18
- client.get("Account/#{client.account_id}/Item.json?#{options}").body
18
+ client.get("Account/#{client.account_id}/Item.json?#{options}")
19
19
  end
20
20
  end
21
21
 
@@ -1,4 +1,5 @@
1
1
  require "lightspeed/configuration"
2
+ require "lightspeed/api/error"
2
3
  require "lightspeed/api/tokens"
3
4
  require "lightspeed/api/accounts"
4
5
  require "lightspeed/api/sales"
@@ -1,3 +1,3 @@
1
1
  module Lightspeed
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightspeed_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zamith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,6 +114,7 @@ files:
114
114
  - lib/lightspeed/api/accounts.rb
115
115
  - lib/lightspeed/api/categories.rb
116
116
  - lib/lightspeed/api/customers.rb
117
+ - lib/lightspeed/api/error.rb
117
118
  - lib/lightspeed/api/helpers/pagination.rb
118
119
  - lib/lightspeed/api/items.rb
119
120
  - lib/lightspeed/api/items/custom_fields.rb