cin7_api 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/Gemfile.lock +41 -37
- data/lib/cin7_api/errors.rb +6 -0
- data/lib/cin7_api/resource.rb +11 -9
- data/lib/cin7_api/resources/branch_resource.rb +13 -1
- data/lib/cin7_api/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b85874c98a472da8ce77ad2376b6f0309a9f88d88dfe491fa9c39b1d1507a57
|
4
|
+
data.tar.gz: 7f2a25e07d66d034b978ae4c452cb70b7880f8aeeb33a044b464925415bf127d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b634704ee15ae8082b9a695123146d06b883a19fa8f750a168ba61c82724303ea13c75d2fdbe2035a2286e756027e98aa68fabb718a8b3e4ac63474492ff9b
|
7
|
+
data.tar.gz: 773532c8ee41cdaf800311505ede37ed6bd823565f3e3d8847a00af4d594127458661ed2c7930d5196f5767f48b5a2ccfa38fa5de988421c16d7ce0923197381
|
data/.rubocop.yml
CHANGED
@@ -11,3 +11,18 @@ Style/StringLiteralsInInterpolation:
|
|
11
11
|
|
12
12
|
Layout/LineLength:
|
13
13
|
Max: 120
|
14
|
+
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/CyclomaticComplexity:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/AbcSize:
|
28
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,57 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cin7_api (1.1.
|
5
|
-
activesupport
|
4
|
+
cin7_api (1.1.2)
|
5
|
+
activesupport (~> 7.0.5)
|
6
6
|
faraday (~> 2.5)
|
7
7
|
zeitwerk
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (7.0.
|
12
|
+
activesupport (7.0.8.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
17
|
ast (2.4.2)
|
18
18
|
coderay (1.1.3)
|
19
|
-
concurrent-ruby (1.2.
|
20
|
-
diff-lcs (1.5.
|
21
|
-
dotenv (
|
22
|
-
faraday (2.
|
23
|
-
faraday-net_http (>= 2.0, < 3.
|
24
|
-
|
25
|
-
|
26
|
-
i18n (1.
|
19
|
+
concurrent-ruby (1.2.3)
|
20
|
+
diff-lcs (1.5.1)
|
21
|
+
dotenv (3.1.0)
|
22
|
+
faraday (2.9.0)
|
23
|
+
faraday-net_http (>= 2.0, < 3.2)
|
24
|
+
faraday-net_http (3.1.0)
|
25
|
+
net-http
|
26
|
+
i18n (1.14.4)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
|
-
json (2.
|
28
|
+
json (2.7.2)
|
29
29
|
language_server-protocol (3.17.0.3)
|
30
|
-
method_source (1.
|
31
|
-
minitest (5.
|
32
|
-
|
33
|
-
|
30
|
+
method_source (1.1.0)
|
31
|
+
minitest (5.22.3)
|
32
|
+
net-http (0.4.1)
|
33
|
+
uri
|
34
|
+
parallel (1.24.0)
|
35
|
+
parser (3.3.0.5)
|
34
36
|
ast (~> 2.4.1)
|
35
|
-
|
37
|
+
racc
|
38
|
+
pry (0.14.2)
|
36
39
|
coderay (~> 1.1)
|
37
40
|
method_source (~> 1.0)
|
41
|
+
racc (1.7.3)
|
38
42
|
rainbow (3.1.1)
|
39
|
-
rake (13.
|
40
|
-
regexp_parser (2.
|
41
|
-
rexml (3.2.
|
42
|
-
rspec (3.
|
43
|
-
rspec-core (~> 3.
|
44
|
-
rspec-expectations (~> 3.
|
45
|
-
rspec-mocks (~> 3.
|
46
|
-
rspec-core (3.
|
47
|
-
rspec-support (~> 3.
|
48
|
-
rspec-expectations (3.
|
43
|
+
rake (13.2.1)
|
44
|
+
regexp_parser (2.9.0)
|
45
|
+
rexml (3.2.6)
|
46
|
+
rspec (3.13.0)
|
47
|
+
rspec-core (~> 3.13.0)
|
48
|
+
rspec-expectations (~> 3.13.0)
|
49
|
+
rspec-mocks (~> 3.13.0)
|
50
|
+
rspec-core (3.13.0)
|
51
|
+
rspec-support (~> 3.13.0)
|
52
|
+
rspec-expectations (3.13.0)
|
49
53
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-mocks (3.
|
54
|
+
rspec-support (~> 3.13.0)
|
55
|
+
rspec-mocks (3.13.0)
|
52
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-support (3.
|
57
|
+
rspec-support (~> 3.13.0)
|
58
|
+
rspec-support (3.13.1)
|
55
59
|
rubocop (1.48.1)
|
56
60
|
json (~> 2.3)
|
57
61
|
parallel (~> 1.10)
|
@@ -62,22 +66,22 @@ GEM
|
|
62
66
|
rubocop-ast (>= 1.26.0, < 2.0)
|
63
67
|
ruby-progressbar (~> 1.7)
|
64
68
|
unicode-display_width (>= 2.4.0, < 3.0)
|
65
|
-
rubocop-ast (1.
|
66
|
-
parser (>= 3.
|
69
|
+
rubocop-ast (1.31.2)
|
70
|
+
parser (>= 3.3.0.4)
|
67
71
|
rubocop-performance (1.16.0)
|
68
72
|
rubocop (>= 1.7.0, < 2.0)
|
69
73
|
rubocop-ast (>= 0.4.0)
|
70
74
|
ruby-progressbar (1.13.0)
|
71
|
-
ruby2_keywords (0.0.5)
|
72
75
|
standard (1.25.5)
|
73
76
|
language_server-protocol (~> 3.17.0.2)
|
74
77
|
rubocop (~> 1.48.1)
|
75
78
|
rubocop-performance (~> 1.16.0)
|
76
79
|
tzinfo (2.0.6)
|
77
80
|
concurrent-ruby (~> 1.0)
|
78
|
-
unicode-display_width (2.
|
79
|
-
|
80
|
-
|
81
|
+
unicode-display_width (2.5.0)
|
82
|
+
uri (0.13.0)
|
83
|
+
vcr (6.2.0)
|
84
|
+
zeitwerk (2.6.13)
|
81
85
|
|
82
86
|
PLATFORMS
|
83
87
|
arm64-darwin-22
|
data/lib/cin7_api/errors.rb
CHANGED
data/lib/cin7_api/resource.rb
CHANGED
@@ -10,8 +10,8 @@ module Cin7API
|
|
10
10
|
@client = client
|
11
11
|
end
|
12
12
|
|
13
|
-
def get_request(url, params: {}, headers: {})
|
14
|
-
handle_response client.connection.get(url, parsed_params(params), headers)
|
13
|
+
def get_request(url, params: {}, page: 1, headers: {})
|
14
|
+
handle_response client.connection.get(url, parsed_params(params, page), headers)
|
15
15
|
end
|
16
16
|
|
17
17
|
def post_request(url, body:, headers: {})
|
@@ -29,20 +29,20 @@ module Cin7API
|
|
29
29
|
when 400
|
30
30
|
raise Error, "A bad request or a validation exception has occurred. #{error_message}"
|
31
31
|
when 401
|
32
|
-
raise
|
32
|
+
raise AuthenticationError, "Invalid authorization credentials. #{error_message}"
|
33
33
|
when 403
|
34
|
-
raise
|
34
|
+
raise PermissionError, "Connection doesn't have permission to access the resource. #{error_message}"
|
35
35
|
when 404
|
36
36
|
raise Error, "The resource you have specified cannot be found. #{error_message}"
|
37
37
|
when 429
|
38
38
|
raise RateLimitError,
|
39
|
-
|
39
|
+
"The API rate limit for your application has been exceeded. #{error_message}"
|
40
40
|
when 500
|
41
41
|
raise ServerError,
|
42
|
-
|
42
|
+
"An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
|
43
43
|
when 503
|
44
44
|
raise Error,
|
45
|
-
|
45
|
+
"API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
|
46
46
|
end
|
47
47
|
|
48
48
|
response
|
@@ -50,7 +50,9 @@ module Cin7API
|
|
50
50
|
|
51
51
|
private
|
52
52
|
|
53
|
-
def parsed_params(params)
|
53
|
+
def parsed_params(params, page)
|
54
|
+
return params unless params.present?
|
55
|
+
|
54
56
|
# E.g: Need to convert to where: ["OrderId=2223", "SalesRefernce='CRN-2223'"]
|
55
57
|
parsed_params =
|
56
58
|
params.each_with_object([]) do |(key, value), array|
|
@@ -60,7 +62,7 @@ module Cin7API
|
|
60
62
|
end
|
61
63
|
|
62
64
|
# Only handle for Cin7 where query for now
|
63
|
-
{where: parsed_params}
|
65
|
+
{ where: parsed_params, page: page }
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
@@ -6,10 +6,22 @@ module Cin7API
|
|
6
6
|
# Use 0 for inactive branches
|
7
7
|
# @client.branch.where(active: 1)
|
8
8
|
def where(**params)
|
9
|
+
page = 1
|
10
|
+
paginated_branches = []
|
11
|
+
|
9
12
|
response_body = get_request("Branches", params: params).body
|
10
13
|
branches = response_body.map { |attributes| Branch.new(attributes) }
|
14
|
+
paginated_branches += branches
|
15
|
+
|
16
|
+
while branches.length == 50
|
17
|
+
page += 1
|
18
|
+
response_body = get_request("Branches", params: params, page: page).body
|
19
|
+
branches = response_body.map { |attributes| Branch.new(attributes) }
|
20
|
+
paginated_branches += branches
|
21
|
+
end
|
22
|
+
|
11
23
|
# Doing a filter here because Cin7 is doing a binary OR check for the filter params
|
12
|
-
|
24
|
+
paginated_branches.filter do |branch|
|
13
25
|
params.reduce(true) do |acc, (key, value)|
|
14
26
|
if key == :active
|
15
27
|
parsed_value = value == 1
|
data/lib/cin7_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cin7_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wei Zhe Heng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 7.0.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 7.0.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: zeitwerk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
rubygems_version: 3.4.
|
168
|
+
rubygems_version: 3.4.19
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Cin7 API Wrapper
|