lightspeed_ruby 0.2.0 → 0.3.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: '0886b5c2d83eed7249e2339f7f561eb97a75ba7c'
4
- data.tar.gz: 3ce3a727e2eb72b8c12cc183690e51312271d5fe
3
+ metadata.gz: f032891a3ff992f221f39227cbbe4b7bba13a96c
4
+ data.tar.gz: e3860fe3eb16993f95047e3b28e309f91b8ed0c3
5
5
  SHA512:
6
- metadata.gz: 23eb41e314c9cfe4d95eac2cdc4f88657c58cf75f250d02f3b175aa3da173acd924dd089ebb40c85f44bff16810fb32b1d4d89a4c55dafaab2e7a6a2fd775c77
7
- data.tar.gz: bbf32f203f15f472b4142137e63fdc1b1495bb051101003861bdcfc746fc7d072ae567fc19807b1d699cc156f6d33dcf50f9259b318ff969872dc60b093f8bb5
6
+ metadata.gz: ed625008cbd0580669277b29ed6c4aae1eb5ed08aff7fb7643157a59c1619378345644635bdf19ed52e31dfd7101a7a2df48f424f21183bb0528b92443d6efab
7
+ data.tar.gz: bc7b279263bef9399cc79a9956ec9d26de50a3ab9649bd7d878cfa9e90540fee70bf8057463bad9ed1ab64545002204c21a5c41d9936d8c9225223abdb719f35
@@ -0,0 +1,28 @@
1
+ module Lightspeed
2
+ module API
3
+ module Helpers
4
+ module Pagination
5
+ def with_pages(limit:)
6
+ limit ||= 100
7
+ results = []
8
+ offset = 0
9
+ count = Float::INFINITY
10
+ while offset < count
11
+ response = yield(options_string(offset, limit))
12
+ attributes = response.delete("@attributes")
13
+ count = attributes["count"].to_i
14
+ offset = attributes["offset"].to_i + limit
15
+ results << response.values
16
+ end
17
+ results.flatten
18
+ end
19
+
20
+ private
21
+
22
+ def options_string(offset, limit)
23
+ "offset=#{offset}&limit=#{limit}"
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,16 +1,22 @@
1
+ require "lightspeed/api/helpers/pagination"
2
+
1
3
  require "lightspeed/api/items/custom_fields"
2
4
 
3
5
  module Lightspeed
4
6
  module API
5
7
  class Items
8
+ include Lightspeed::API::Helpers::Pagination
9
+
6
10
  def initialize(client)
7
11
  @client = client
8
12
  end
9
13
 
10
14
  def custom_fields; Items::CustomFields.new(client); end
11
15
 
12
- def all
13
- client.get("Account/#{client.account_id}/Item.json").body
16
+ def all(limit: nil)
17
+ with_pages(limit: limit) do |options|
18
+ client.get("Account/#{client.account_id}/Item.json?#{options}").body
19
+ end
14
20
  end
15
21
 
16
22
  def find(item_id, with: [])
@@ -4,7 +4,7 @@ module Lightspeed
4
4
 
5
5
  def initialize(rate_limit: nil)
6
6
  @rate_limit = rate_limit || false
7
- @environment = "production"
7
+ @environment = :production
8
8
  end
9
9
 
10
10
  def environment=(env)
@@ -1,3 +1,3 @@
1
1
  module Lightspeed
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zamith
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2018-01-18 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/helpers/pagination.rb
117
118
  - lib/lightspeed/api/items.rb
118
119
  - lib/lightspeed/api/items/custom_fields.rb
119
120
  - lib/lightspeed/api/items/custom_fields/custom_field_choices.rb