cin7_api 1.0.4 → 1.1.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 +4 -4
- data/Gemfile +0 -2
- data/Gemfile.lock +30 -21
- data/lib/cin7_api/client.rb +4 -0
- data/lib/cin7_api/errors.rb +12 -0
- data/lib/cin7_api/{error.rb → objects/branch.rb} +2 -1
- data/lib/cin7_api/resource.rb +12 -10
- data/lib/cin7_api/resources/branch_resource.rb +24 -0
- data/lib/cin7_api/resources/credit_note_resource.rb +25 -0
- data/lib/cin7_api/version.rb +1 -1
- data/lib/cin7_api.rb +6 -1
- metadata +20 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 056166ba00f5465bd7aa38f23e82a384f0690cb4edaddf990d6794cd30785736
|
|
4
|
+
data.tar.gz: 9cc3abe5f31a1c51a063dfd52e30a040dcab70078f1d54f26df6c71fa61e0cdb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2d9165f321d846269107172ee3da875725e086cbf20246f2a9dc70de0ecbc51f3595d76829eca8ff285dc3c908ff3398ea643bf6575d0832dca0889202f8927
|
|
7
|
+
data.tar.gz: 1a14d8c4a9977f810609cdaec318edc69801cc2fba5b4825b57d878dd3c813e3c2f09d00ccd705cd3305ec4c5580d907ef2ec4996e3ddd7810bccdf978a83c54
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
cin7_api (1.0
|
|
4
|
+
cin7_api (1.1.0)
|
|
5
5
|
activesupport
|
|
6
6
|
faraday (~> 2.5)
|
|
7
7
|
zeitwerk
|
|
@@ -9,34 +9,35 @@ PATH
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
activesupport (7.0.
|
|
12
|
+
activesupport (7.0.5)
|
|
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.
|
|
19
|
+
concurrent-ruby (1.2.2)
|
|
20
20
|
diff-lcs (1.5.0)
|
|
21
21
|
dotenv (2.8.1)
|
|
22
|
-
faraday (2.
|
|
22
|
+
faraday (2.7.5)
|
|
23
23
|
faraday-net_http (>= 2.0, < 3.1)
|
|
24
24
|
ruby2_keywords (>= 0.0.4)
|
|
25
|
-
faraday-net_http (3.0.
|
|
26
|
-
i18n (1.
|
|
25
|
+
faraday-net_http (3.0.2)
|
|
26
|
+
i18n (1.13.0)
|
|
27
27
|
concurrent-ruby (~> 1.0)
|
|
28
|
-
json (2.6.
|
|
28
|
+
json (2.6.3)
|
|
29
|
+
language_server-protocol (3.17.0.3)
|
|
29
30
|
method_source (1.0.0)
|
|
30
|
-
minitest (5.
|
|
31
|
+
minitest (5.18.0)
|
|
31
32
|
parallel (1.22.1)
|
|
32
|
-
parser (3.
|
|
33
|
+
parser (3.2.2.0)
|
|
33
34
|
ast (~> 2.4.1)
|
|
34
35
|
pry (0.14.1)
|
|
35
36
|
coderay (~> 1.1)
|
|
36
37
|
method_source (~> 1.0)
|
|
37
38
|
rainbow (3.1.1)
|
|
38
39
|
rake (13.0.6)
|
|
39
|
-
regexp_parser (2.
|
|
40
|
+
regexp_parser (2.7.0)
|
|
40
41
|
rexml (3.2.5)
|
|
41
42
|
rspec (3.11.0)
|
|
42
43
|
rspec-core (~> 3.11.0)
|
|
@@ -51,27 +52,35 @@ GEM
|
|
|
51
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
52
53
|
rspec-support (~> 3.11.0)
|
|
53
54
|
rspec-support (3.11.1)
|
|
54
|
-
rubocop (1.
|
|
55
|
+
rubocop (1.48.1)
|
|
55
56
|
json (~> 2.3)
|
|
56
57
|
parallel (~> 1.10)
|
|
57
|
-
parser (>= 3.
|
|
58
|
+
parser (>= 3.2.0.0)
|
|
58
59
|
rainbow (>= 2.2.2, < 4.0)
|
|
59
60
|
regexp_parser (>= 1.8, < 3.0)
|
|
60
61
|
rexml (>= 3.2.5, < 4.0)
|
|
61
|
-
rubocop-ast (>= 1.
|
|
62
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
|
62
63
|
ruby-progressbar (~> 1.7)
|
|
63
|
-
unicode-display_width (>=
|
|
64
|
-
rubocop-ast (1.
|
|
65
|
-
parser (>= 3.
|
|
66
|
-
|
|
64
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
65
|
+
rubocop-ast (1.28.0)
|
|
66
|
+
parser (>= 3.2.1.0)
|
|
67
|
+
rubocop-performance (1.16.0)
|
|
68
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
69
|
+
rubocop-ast (>= 0.4.0)
|
|
70
|
+
ruby-progressbar (1.13.0)
|
|
67
71
|
ruby2_keywords (0.0.5)
|
|
68
|
-
|
|
72
|
+
standard (1.25.5)
|
|
73
|
+
language_server-protocol (~> 3.17.0.2)
|
|
74
|
+
rubocop (~> 1.48.1)
|
|
75
|
+
rubocop-performance (~> 1.16.0)
|
|
76
|
+
tzinfo (2.0.6)
|
|
69
77
|
concurrent-ruby (~> 1.0)
|
|
70
|
-
unicode-display_width (2.
|
|
78
|
+
unicode-display_width (2.4.2)
|
|
71
79
|
vcr (6.1.0)
|
|
72
|
-
zeitwerk (2.6.
|
|
80
|
+
zeitwerk (2.6.8)
|
|
73
81
|
|
|
74
82
|
PLATFORMS
|
|
83
|
+
arm64-darwin-22
|
|
75
84
|
x86_64-darwin-21
|
|
76
85
|
x86_64-linux
|
|
77
86
|
|
|
@@ -81,7 +90,7 @@ DEPENDENCIES
|
|
|
81
90
|
pry
|
|
82
91
|
rake (~> 13.0)
|
|
83
92
|
rspec (~> 3.0)
|
|
84
|
-
|
|
93
|
+
standard (~> 1.25.0)
|
|
85
94
|
vcr
|
|
86
95
|
|
|
87
96
|
BUNDLED WITH
|
data/lib/cin7_api/client.rb
CHANGED
data/lib/cin7_api/resource.rb
CHANGED
|
@@ -35,13 +35,14 @@ module Cin7API
|
|
|
35
35
|
when 404
|
|
36
36
|
raise Error, "The resource you have specified cannot be found. #{error_message}"
|
|
37
37
|
when 429
|
|
38
|
-
raise
|
|
38
|
+
raise RateLimitError,
|
|
39
|
+
"The API rate limit for your application has been exceeded. #{error_message}"
|
|
39
40
|
when 500
|
|
40
|
-
raise
|
|
41
|
-
|
|
41
|
+
raise ServerError,
|
|
42
|
+
"An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
|
|
42
43
|
when 503
|
|
43
44
|
raise Error,
|
|
44
|
-
|
|
45
|
+
"API is currently unavailable – typically due to a scheduled outage – try again soon. #{error_message}"
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
response
|
|
@@ -51,14 +52,15 @@ module Cin7API
|
|
|
51
52
|
|
|
52
53
|
def parsed_params(params)
|
|
53
54
|
# E.g: Need to convert to where: ["OrderId=2223", "SalesRefernce='CRN-2223'"]
|
|
54
|
-
parsed_params =
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
parsed_params =
|
|
56
|
+
params.each_with_object([]) do |(key, value), array|
|
|
57
|
+
# Cin7 requires string value filter to be wrapped in single-quote
|
|
58
|
+
parsed_value = value.is_a?(String) ? %('#{value}') : value
|
|
59
|
+
array << "#{key.to_s.camelcase}=#{parsed_value}"
|
|
60
|
+
end
|
|
59
61
|
|
|
60
62
|
# Only handle for Cin7 where query for now
|
|
61
|
-
{
|
|
63
|
+
{where: parsed_params}
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Cin7API
|
|
4
|
+
class BranchResource < Resource
|
|
5
|
+
# Use 1 for active branches
|
|
6
|
+
# Use 0 for inactive branches
|
|
7
|
+
# @client.branch.where(active: 1)
|
|
8
|
+
def where(**params)
|
|
9
|
+
response_body = get_request("Branches", params: params).body
|
|
10
|
+
branches = response_body.map { |attributes| Branch.new(attributes) }
|
|
11
|
+
# Doing a filter here because Cin7 is doing a binary OR check for the filter params
|
|
12
|
+
branches.filter do |branch|
|
|
13
|
+
params.reduce(true) do |acc, (key, value)|
|
|
14
|
+
if key == :active
|
|
15
|
+
parsed_value = value == 1
|
|
16
|
+
branch["is_active"] == parsed_value
|
|
17
|
+
else
|
|
18
|
+
acc && branch[key] == value
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -35,5 +35,30 @@ module Cin7API
|
|
|
35
35
|
responses = put_request("CreditNotes", body: attributes_array).body
|
|
36
36
|
responses.map { |attributes| Response.new(attributes) }
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
# attributes_array = [
|
|
40
|
+
# {
|
|
41
|
+
# branchId: 3,
|
|
42
|
+
# salesReference: "HBP1030",
|
|
43
|
+
# lineItems: [
|
|
44
|
+
# {
|
|
45
|
+
# code: "5-PAIRS-SOCKS",
|
|
46
|
+
# styleCode: "5-PAIRS-SOCKS",
|
|
47
|
+
# sizeCodes: nil,
|
|
48
|
+
# name: "5PAIRS SOCKS - ONE SIZE",
|
|
49
|
+
# option1: "ONE SIZE",
|
|
50
|
+
# option2: "",
|
|
51
|
+
# option3: nil,
|
|
52
|
+
# qty: 1,
|
|
53
|
+
# unitPrice: 0
|
|
54
|
+
# },
|
|
55
|
+
# ],
|
|
56
|
+
# }
|
|
57
|
+
# ]
|
|
58
|
+
# @client.credit_note.create(attributes_array)
|
|
59
|
+
def create(attributes_array)
|
|
60
|
+
responses = post_request("CreditNotes", body: attributes_array).body
|
|
61
|
+
responses.map { |attributes| Response.new(attributes) }
|
|
62
|
+
end
|
|
38
63
|
end
|
|
39
64
|
end
|
data/lib/cin7_api/version.rb
CHANGED
data/lib/cin7_api.rb
CHANGED
|
@@ -7,7 +7,12 @@ loader = Zeitwerk::Loader.for_gem
|
|
|
7
7
|
loader.inflector.inflect("cin7_api" => "Cin7API")
|
|
8
8
|
loader.collapse("#{__dir__}/cin7_api/objects")
|
|
9
9
|
loader.collapse("#{__dir__}/cin7_api/resources")
|
|
10
|
-
|
|
10
|
+
# Zeitwerk doesn't support multiple classes in a single file
|
|
11
|
+
# https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#one-file-one-constant-at-the-same-top-level
|
|
12
|
+
loader.ignore("#{__dir__}/cin7_api/errors.rb")
|
|
13
|
+
loader.setup
|
|
14
|
+
|
|
15
|
+
require "cin7_api/errors"
|
|
11
16
|
|
|
12
17
|
module Cin7API
|
|
13
18
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cin7_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
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: 2023-06-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -52,6 +52,20 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: standard
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.25.0
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.25.0
|
|
55
69
|
- !ruby/object:Gem::Dependency
|
|
56
70
|
name: faraday
|
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -113,13 +127,15 @@ files:
|
|
|
113
127
|
- Rakefile
|
|
114
128
|
- lib/cin7_api.rb
|
|
115
129
|
- lib/cin7_api/client.rb
|
|
116
|
-
- lib/cin7_api/
|
|
130
|
+
- lib/cin7_api/errors.rb
|
|
117
131
|
- lib/cin7_api/object.rb
|
|
132
|
+
- lib/cin7_api/objects/branch.rb
|
|
118
133
|
- lib/cin7_api/objects/credit_note.rb
|
|
119
134
|
- lib/cin7_api/objects/payment.rb
|
|
120
135
|
- lib/cin7_api/objects/response.rb
|
|
121
136
|
- lib/cin7_api/objects/sales_order.rb
|
|
122
137
|
- lib/cin7_api/resource.rb
|
|
138
|
+
- lib/cin7_api/resources/branch_resource.rb
|
|
123
139
|
- lib/cin7_api/resources/credit_note_resource.rb
|
|
124
140
|
- lib/cin7_api/resources/payment_resource.rb
|
|
125
141
|
- lib/cin7_api/resources/sales_order_resource.rb
|
|
@@ -149,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
149
165
|
- !ruby/object:Gem::Version
|
|
150
166
|
version: '0'
|
|
151
167
|
requirements: []
|
|
152
|
-
rubygems_version: 3.
|
|
168
|
+
rubygems_version: 3.4.10
|
|
153
169
|
signing_key:
|
|
154
170
|
specification_version: 4
|
|
155
171
|
summary: Cin7 API Wrapper
|