cin7_api 1.1.1 → 1.1.3

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
  SHA256:
3
- metadata.gz: 3649d7406e010700d3596d03c8022a197e1bfbe200d4271a0259da223bad6b47
4
- data.tar.gz: f2502dadc70812ab8065b4020f989fb9e9d7ffd09963d90f9b90f4a7e0209c8a
3
+ metadata.gz: 84b6f3451dca3d2409dbbaf6fbe16a77c90f8d4e42e872307a4dacd64f7081e3
4
+ data.tar.gz: cddd5b4db69517546ba0b57edfd9e76685976079dfd4d1f3d41e013e99d482bc
5
5
  SHA512:
6
- metadata.gz: 9297145c475bf521d10fa9a5e60338eb3dd5b642b15d720fa035c3da5b84ff7f852cee1539257bceb895e24245b64adf159e02052fd3345218b401bc1868fbb2
7
- data.tar.gz: f67e0f395798aeecd3ffd893f787d8d0ab6ba6cc3b7aa94bcc152a1f9a53cb19cebac245e5ba081a98442fbdfd408d69b39796b7dca74d272b51ce626664e507
6
+ metadata.gz: c1efa4749445245595f42709296cf2f371f2386301b99ae1b469c26faded2806a96f3a54d3109c13ca231418cdb33e4f112b5d9f1f84fda2f31351b69255aff4
7
+ data.tar.gz: 05e37e4f5c33cf1d7db4479511a6ce730c7e45b58d4b948bb01301e6437b0d91c5ba89907fb694feb337cec4110aa22e8ce34dc1ccda4b1f5e6bca564d5725ca
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,71 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cin7_api (1.1.1)
5
- activesupport
4
+ cin7_api (1.1.3)
5
+ activesupport (= 7.1.3.2)
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.5)
12
+ activesupport (7.1.3.2)
13
+ base64
14
+ bigdecimal
13
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ connection_pool (>= 2.2.5)
17
+ drb
14
18
  i18n (>= 1.6, < 2)
15
19
  minitest (>= 5.1)
20
+ mutex_m
16
21
  tzinfo (~> 2.0)
17
22
  ast (2.4.2)
23
+ base64 (0.2.0)
24
+ bigdecimal (3.1.8)
18
25
  coderay (1.1.3)
19
- concurrent-ruby (1.2.2)
20
- diff-lcs (1.5.0)
21
- dotenv (2.8.1)
22
- faraday (2.7.6)
23
- faraday-net_http (>= 2.0, < 3.1)
24
- ruby2_keywords (>= 0.0.4)
25
- faraday-net_http (3.0.2)
26
- i18n (1.14.1)
26
+ concurrent-ruby (1.2.3)
27
+ connection_pool (2.4.1)
28
+ diff-lcs (1.5.1)
29
+ dotenv (3.1.0)
30
+ drb (2.2.1)
31
+ faraday (2.9.0)
32
+ faraday-net_http (>= 2.0, < 3.2)
33
+ faraday-net_http (3.1.0)
34
+ net-http
35
+ i18n (1.14.5)
27
36
  concurrent-ruby (~> 1.0)
28
- json (2.6.3)
37
+ json (2.7.2)
29
38
  language_server-protocol (3.17.0.3)
30
- method_source (1.0.0)
31
- minitest (5.18.1)
32
- parallel (1.22.1)
33
- parser (3.2.2.0)
39
+ method_source (1.1.0)
40
+ minitest (5.23.0)
41
+ mutex_m (0.2.0)
42
+ net-http (0.4.1)
43
+ uri
44
+ parallel (1.24.0)
45
+ parser (3.3.0.5)
34
46
  ast (~> 2.4.1)
35
- pry (0.14.1)
47
+ racc
48
+ pry (0.14.2)
36
49
  coderay (~> 1.1)
37
50
  method_source (~> 1.0)
51
+ racc (1.7.3)
38
52
  rainbow (3.1.1)
39
- rake (13.0.6)
40
- regexp_parser (2.7.0)
41
- rexml (3.2.5)
42
- rspec (3.11.0)
43
- rspec-core (~> 3.11.0)
44
- rspec-expectations (~> 3.11.0)
45
- rspec-mocks (~> 3.11.0)
46
- rspec-core (3.11.0)
47
- rspec-support (~> 3.11.0)
48
- rspec-expectations (3.11.1)
53
+ rake (13.2.1)
54
+ regexp_parser (2.9.0)
55
+ rexml (3.2.6)
56
+ rspec (3.13.0)
57
+ rspec-core (~> 3.13.0)
58
+ rspec-expectations (~> 3.13.0)
59
+ rspec-mocks (~> 3.13.0)
60
+ rspec-core (3.13.0)
61
+ rspec-support (~> 3.13.0)
62
+ rspec-expectations (3.13.0)
49
63
  diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.11.0)
51
- rspec-mocks (3.11.1)
64
+ rspec-support (~> 3.13.0)
65
+ rspec-mocks (3.13.0)
52
66
  diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.11.0)
54
- rspec-support (3.11.1)
67
+ rspec-support (~> 3.13.0)
68
+ rspec-support (3.13.1)
55
69
  rubocop (1.48.1)
56
70
  json (~> 2.3)
57
71
  parallel (~> 1.10)
@@ -62,22 +76,22 @@ GEM
62
76
  rubocop-ast (>= 1.26.0, < 2.0)
63
77
  ruby-progressbar (~> 1.7)
64
78
  unicode-display_width (>= 2.4.0, < 3.0)
65
- rubocop-ast (1.28.0)
66
- parser (>= 3.2.1.0)
79
+ rubocop-ast (1.31.2)
80
+ parser (>= 3.3.0.4)
67
81
  rubocop-performance (1.16.0)
68
82
  rubocop (>= 1.7.0, < 2.0)
69
83
  rubocop-ast (>= 0.4.0)
70
84
  ruby-progressbar (1.13.0)
71
- ruby2_keywords (0.0.5)
72
85
  standard (1.25.5)
73
86
  language_server-protocol (~> 3.17.0.2)
74
87
  rubocop (~> 1.48.1)
75
88
  rubocop-performance (~> 1.16.0)
76
89
  tzinfo (2.0.6)
77
90
  concurrent-ruby (~> 1.0)
78
- unicode-display_width (2.4.2)
79
- vcr (6.1.0)
80
- zeitwerk (2.6.8)
91
+ unicode-display_width (2.5.0)
92
+ uri (0.13.0)
93
+ vcr (6.2.0)
94
+ zeitwerk (2.6.14)
81
95
 
82
96
  PLATFORMS
83
97
  arm64-darwin-22
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
3
4
  require "active_support/core_ext/string"
4
5
  require "ostruct"
5
6
 
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
3
4
  require "active_support/core_ext/string"
5
+ require "active_support/core_ext/hash"
4
6
 
5
7
  module Cin7API
6
8
  class Resource
@@ -10,8 +12,8 @@ module Cin7API
10
12
  @client = client
11
13
  end
12
14
 
13
- def get_request(url, params: {}, headers: {})
14
- handle_response client.connection.get(url, parsed_params(params), headers)
15
+ def get_request(url, params: {}, page: 1, headers: {})
16
+ handle_response client.connection.get(url, parsed_params(params, page), headers)
15
17
  end
16
18
 
17
19
  def post_request(url, body:, headers: {})
@@ -36,13 +38,13 @@ module Cin7API
36
38
  raise Error, "The resource you have specified cannot be found. #{error_message}"
37
39
  when 429
38
40
  raise RateLimitError,
39
- "The API rate limit for your application has been exceeded. #{error_message}"
41
+ "The API rate limit for your application has been exceeded. #{error_message}"
40
42
  when 500
41
43
  raise ServerError,
42
- "An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
44
+ "An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
43
45
  when 503
44
46
  raise Error,
45
- "API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
47
+ "API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
46
48
  end
47
49
 
48
50
  response
@@ -50,7 +52,9 @@ module Cin7API
50
52
 
51
53
  private
52
54
 
53
- def parsed_params(params)
55
+ def parsed_params(params, page)
56
+ return params unless params.present?
57
+
54
58
  # E.g: Need to convert to where: ["OrderId=2223", "SalesRefernce='CRN-2223'"]
55
59
  parsed_params =
56
60
  params.each_with_object([]) do |(key, value), array|
@@ -60,7 +64,7 @@ module Cin7API
60
64
  end
61
65
 
62
66
  # Only handle for Cin7 where query for now
63
- {where: parsed_params}
67
+ { where: parsed_params, page: page }
64
68
  end
65
69
  end
66
70
  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
- branches.filter do |branch|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cin7API
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.3"
5
5
  end
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.1
4
+ version: 1.1.3
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: 2023-06-19 00:00:00.000000000 Z
11
+ date: 2024-05-17 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: '0'
19
+ version: 7.1.3.2
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: '0'
26
+ version: 7.1.3.2
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.10
168
+ rubygems_version: 3.5.9
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Cin7 API Wrapper