cin7_api 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3649d7406e010700d3596d03c8022a197e1bfbe200d4271a0259da223bad6b47
4
- data.tar.gz: f2502dadc70812ab8065b4020f989fb9e9d7ffd09963d90f9b90f4a7e0209c8a
3
+ metadata.gz: 0b85874c98a472da8ce77ad2376b6f0309a9f88d88dfe491fa9c39b1d1507a57
4
+ data.tar.gz: 7f2a25e07d66d034b978ae4c452cb70b7880f8aeeb33a044b464925415bf127d
5
5
  SHA512:
6
- metadata.gz: 9297145c475bf521d10fa9a5e60338eb3dd5b642b15d720fa035c3da5b84ff7f852cee1539257bceb895e24245b64adf159e02052fd3345218b401bc1868fbb2
7
- data.tar.gz: f67e0f395798aeecd3ffd893f787d8d0ab6ba6cc3b7aa94bcc152a1f9a53cb19cebac245e5ba081a98442fbdfd408d69b39796b7dca74d272b51ce626664e507
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.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.5)
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.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)
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.6.3)
28
+ json (2.7.2)
29
29
  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)
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
- pry (0.14.1)
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.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)
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.11.0)
51
- rspec-mocks (3.11.1)
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.11.0)
54
- rspec-support (3.11.1)
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.28.0)
66
- parser (>= 3.2.1.0)
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.4.2)
79
- vcr (6.1.0)
80
- zeitwerk (2.6.8)
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
@@ -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: {})
@@ -36,13 +36,13 @@ module Cin7API
36
36
  raise Error, "The resource you have specified cannot be found. #{error_message}"
37
37
  when 429
38
38
  raise RateLimitError,
39
- "The API rate limit for your application has been exceeded. #{error_message}"
39
+ "The API rate limit for your application has been exceeded. #{error_message}"
40
40
  when 500
41
41
  raise ServerError,
42
- "An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
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
- "API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
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
- 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.2"
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.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: 2023-06-19 00:00:00.000000000 Z
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: '0'
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: '0'
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.10
168
+ rubygems_version: 3.4.19
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Cin7 API Wrapper