lightspeed_ruby 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lightspeed/api/helpers/pagination.rb +28 -0
- data/lib/lightspeed/api/items.rb +8 -2
- data/lib/lightspeed/configuration.rb +1 -1
- data/lib/lightspeed/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f032891a3ff992f221f39227cbbe4b7bba13a96c
|
4
|
+
data.tar.gz: e3860fe3eb16993f95047e3b28e309f91b8ed0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/lightspeed/api/items.rb
CHANGED
@@ -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
|
-
|
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: [])
|
data/lib/lightspeed/version.rb
CHANGED
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.
|
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:
|
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
|