cin7_api 1.0.3 → 1.0.5

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: 00aa61f9aba5bdaed71770a08bf215e94cc7dded390dcf68c04b175d672e359b
4
- data.tar.gz: cf3b16f9e72f5f213c2b6a9fc6cab2517354ca238eea1af5afd24b3da02f2a82
3
+ metadata.gz: 0553e1a9d4db6501e28ed87aa824a5e58ce79171917f04f7d3c9fb72cb35454e
4
+ data.tar.gz: d71205d4103dc6eecaaf6fa6b4b1465e8ff14e3e4b017edfa0d9daa24e7452d6
5
5
  SHA512:
6
- metadata.gz: ef12eed82b1d6ffdfdbcf6881d5fd83b91552df444d4b016008253b8763e4cd893f101175e474d85b62196e16422211f0d0c89490f2b7d17171f803f7ffd2e0a
7
- data.tar.gz: 89e8c1b6f97614e2914bcc89e049a7e3273625e4e785be2a44a9c8a529504fd0a4e51e326f51c7aaba491c8f3e7462b438f1ce9c71e87bb191ec4886040ecef3
6
+ metadata.gz: a19008caf61d33c068423f9aa656d5eba3348d2b262bdc044f7914a395385bf9465244a281b5173c0272170c556acb20ea287f24acd02bc48f2af6608424f476
7
+ data.tar.gz: 69a986ad34adda010c8075166e031ef3e1a56411d7e904498f2c4bee318fb0250b4fd36b77773b4c4f0cf6bdc5bdff5a8297c3f3d1ee9b877fed6c9ad674d2ba
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cin7_api (1.0.2)
4
+ cin7_api (1.0.5)
5
5
  activesupport
6
6
  faraday (~> 2.5)
7
7
  zeitwerk
@@ -19,10 +19,10 @@ GEM
19
19
  concurrent-ruby (1.1.10)
20
20
  diff-lcs (1.5.0)
21
21
  dotenv (2.8.1)
22
- faraday (2.5.2)
22
+ faraday (2.6.0)
23
23
  faraday-net_http (>= 2.0, < 3.1)
24
24
  ruby2_keywords (>= 0.0.4)
25
- faraday-net_http (3.0.0)
25
+ faraday-net_http (3.0.1)
26
26
  i18n (1.12.0)
27
27
  concurrent-ruby (~> 1.0)
28
28
  json (2.6.2)
@@ -69,7 +69,7 @@ GEM
69
69
  concurrent-ruby (~> 1.0)
70
70
  unicode-display_width (2.3.0)
71
71
  vcr (6.1.0)
72
- zeitwerk (2.6.0)
72
+ zeitwerk (2.6.1)
73
73
 
74
74
  PLATFORMS
75
75
  x86_64-darwin-21
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cin7API
4
+ class Error < StandardError
5
+ end
6
+
7
+ class ServerError < StandardError
8
+ end
9
+
10
+ class RateLimitError < StandardError
11
+ end
12
+ end
@@ -35,9 +35,9 @@ 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 Error, "The API rate limit for your application has been exceeded. #{error_message}"
38
+ raise RateLimitError, "The API rate limit for your application has been exceeded. #{error_message}"
39
39
  when 500
40
- raise Error,
40
+ raise ServerError,
41
41
  "An unhandled error with the Cin7 API. Contact the Cin7 API team if problems persist. #{error_message}"
42
42
  when 503
43
43
  raise Error,
@@ -2,20 +2,19 @@
2
2
 
3
3
  module Cin7API
4
4
  class CreditNoteResource < Resource
5
- # NOTE: Cin7 is doing a binary OR check for the filter params
6
5
  # @client.credit_note.where(sales_reference: "#1050", email: "postco360@example.com")
7
6
  def where(**params)
8
- credit_notes = get_request("CreditNotes", params: params).body
9
- credit_notes.map { |attributes| CreditNote.new(attributes) }
7
+ response_body = get_request("CreditNotes", params: params).body
8
+ credit_notes = response_body.map { |attributes| CreditNote.new(attributes) }
9
+ # Doing a filter here because Cin7 is doing a binary OR check for the filter params
10
+ credit_notes.filter do |credit_note|
11
+ params.reduce(true) { |acc, (key, value)| acc && credit_note[key] == value }
12
+ end
10
13
  end
11
14
 
12
15
  # @client.credit_note.find_by(sales_reference: "#1050", email: "postco360@example.com")
13
16
  def find_by(**params)
14
- credit_note =
15
- where(**params).find do |p|
16
- params.reduce(true) { |acc, (key, value)| acc && p[key] == value }
17
- end
18
- credit_note ? CreditNote.new(credit_note) : nil
17
+ where(**params).first
19
18
  end
20
19
 
21
20
  # @client.credit_note.find(2223)
@@ -2,19 +2,19 @@
2
2
 
3
3
  module Cin7API
4
4
  class PaymentResource < Resource
5
- # @client.payment.where(order_id: 2223)
5
+ # @client.payment.where(order_id: 2223, order_ref: "CRN-2223")
6
6
  def where(**params)
7
- payments = get_request("Payments", params: params).body
8
- payments.map { |attributes| Payment.new(attributes) }
7
+ response_body = get_request("Payments", params: params).body
8
+ payments = response_body.map { |attributes| Payment.new(attributes) }
9
+ # Doing a filter here because Cin7 is doing a binary OR check for the filter params
10
+ payments.filter do |payment|
11
+ params.reduce(true) { |acc, (key, value)| acc && payment[key] == value }
12
+ end
9
13
  end
10
14
 
11
15
  # @client.payment.find_by(order_id: 2223, order_ref: "CRN-2223")
12
16
  def find_by(**params)
13
- payment =
14
- where(**params).find do |p|
15
- params.reduce(true) { |acc, (key, value)| acc && p[key] == value }
16
- end
17
- payment.present? ? payment : nil
17
+ where(**params).first
18
18
  end
19
19
 
20
20
  # @client.payment.find(698)
@@ -2,20 +2,19 @@
2
2
 
3
3
  module Cin7API
4
4
  class SalesOrderResource < Resource
5
- # NOTE: Cin7 is doing a binary OR check for the filter params
6
5
  # @client.sales_order.where(reference: "#1050", email: "postco360@example.com")
7
6
  def where(**params)
8
- sales_orders = get_request("SalesOrders", params: params).body
9
- sales_orders.map { |attributes| SalesOrder.new(attributes) }
7
+ response_body = get_request("SalesOrders", params: params).body
8
+ sales_orders = response_body.map { |attributes| SalesOrder.new(attributes) }
9
+ # Doing a filter here because Cin7 is doing a binary OR check for the filter params
10
+ sales_orders.filter do |sales_order|
11
+ params.reduce(true) { |acc, (key, value)| acc && sales_order[key] == value }
12
+ end
10
13
  end
11
14
 
12
15
  # @client.sales_order.find_by(reference: "#1050", email: "postco360@example.com")
13
16
  def find_by(**params)
14
- sales_order =
15
- where(**params).find do |p|
16
- params.reduce(true) { |acc, (key, value)| acc && p[key] == value }
17
- end
18
- sales_order ? SalesOrder.new(sales_order) : nil
17
+ where(**params).first
19
18
  end
20
19
 
21
20
  # @client.sales_order.find(2218)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cin7API
4
- VERSION = "1.0.3"
4
+ VERSION = "1.0.5"
5
5
  end
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
- loader.setup # ready!
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.3
4
+ version: 1.0.5
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: 2022-09-23 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -113,7 +113,7 @@ files:
113
113
  - Rakefile
114
114
  - lib/cin7_api.rb
115
115
  - lib/cin7_api/client.rb
116
- - lib/cin7_api/error.rb
116
+ - lib/cin7_api/errors.rb
117
117
  - lib/cin7_api/object.rb
118
118
  - lib/cin7_api/objects/credit_note.rb
119
119
  - lib/cin7_api/objects/payment.rb
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Cin7API
4
- class Error < StandardError; end
5
- end