erp_integration 0.13.0 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33c09fbc8ebeff2b8b907e88e8b9bc147aefba15d5f7c1245de69cf66b24a8e6
4
- data.tar.gz: c4ffdceea9bd5510bbee71647868e54a1ef36cc58bd7832a9333216811a3dd81
3
+ metadata.gz: 54fc417ece0422718783a178a6a70d86e9d822d0a195996463e07d07a67aeb21
4
+ data.tar.gz: a3252c16fc30517a4829b0e617b5c9b4d3d8fd26d86ef1562af33ac1ceb953b9
5
5
  SHA512:
6
- metadata.gz: 4e7a15d4a90a16905aab8c8be40e751c3b16148ad616631e6adad6033fdf444eeaeb9d6f37e30ba4639f17f5a1a7e800281051a2e98e44aa93936e74eed7c0de
7
- data.tar.gz: bfba3edd52a0529d5ca11457b12ab255c3aed41fb2ca08df17c2c09333fa7c22c76ce96a0b96436c84327b62442d4129429d5a928863e5185c3724d926ddcef2
6
+ metadata.gz: c4e59e843c9740007d99511ea3a5a364f57d0077e40826c2d7528c2c4665dcbb1ebc6ba4f217628b4584cf25f257fd39f944c5d214036232377acf0ce5e06caf
7
+ data.tar.gz: bd78fe69cc0d4218a18dda58291a6f18cb37a6d7ac922e80cfff298fb5352ac42848f097d97c6ce931ac134cf54ac0e445a9568b6979edb556e68ac7a6c8d42c
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
45
45
  spec.add_development_dependency 'rubocop', '< 0.82.0'
46
46
  spec.add_development_dependency 'rubocop-rake', '~> 0.5'
47
47
  spec.add_development_dependency 'rubocop-rspec', '< 1.39.0'
48
- spec.add_development_dependency 'webmock', '~> 3.17.0'
48
+ spec.add_development_dependency 'webmock', '~> 3.18.1'
49
49
 
50
50
  # The `parallel` gem is a dev dependency for Rubocop. However, the versions
51
51
  # for parallel after 1.19.2 don't work with ruby 2.3.x. As ruby 2.3.x is
@@ -175,6 +175,10 @@ module ErpIntegration
175
175
  def tracking_number_adapter
176
176
  @tracking_number_adapter || :fulfil
177
177
  end
178
+
179
+ def webhook_adapter
180
+ @webhook_adapter || :fulfil
181
+ end
178
182
  end
179
183
 
180
184
  # Returns ERP Integration's configuration.
@@ -8,24 +8,40 @@ module ErpIntegration
8
8
  module QueryMethods
9
9
  attr_accessor :selected_fields, :where_clauses
10
10
 
11
+ # The `QueryMethods#select` works in two unique ways
12
+ #
13
+ # First, it takes a block to allow it to function like a regular `Enumerable#select`.
14
+ #
15
+ # @example
16
+ # $ ErpIntegration::SalesOrder.select { |sales_order| sales_order.id > 100 }
17
+ # # => [<ErpIntegration::SalesOrder @id=101 />, <ErpIntegration::Resource @id=102 />]
18
+ #
19
+ # Secondly, it allows us to select specific fields to be returned by Fulfil.
20
+ #
11
21
  # Fulfil only returns an ID by default when one would query their API. However,
12
22
  # the ID is seldom the only value one will need. The `select` method allows
13
23
  # selecting multiple fields at once.
14
24
  #
15
25
  # @example
16
26
  # $ ErpIntegration::SalesOrder.select(:id, :name, 'product.name')
17
- # # => <ErpIntegration::Fulfil::Resources::Order @selected_fields=[:id, :name, "product.name"] />
27
+ # # => <ErpIntegration::Fulfil::Resources::SalesOrder @selected_fields=[:id, :name, "product.name"] />
18
28
  #
19
29
  # When one calls the `all` method, it will fetch all the resources from Fulfil
20
30
  # and it will return all the given fields (if available).
21
31
  #
22
32
  # @example
23
33
  # $ ErpIntegration::SalesOrder.select(:id, :name, 'product.name').all
24
- # # => <ErpIntegration::Fulfil::Collection @items=[...] />
34
+ # # => [<ErpIntegration::SalesOrder @id=101 />, <ErpIntegration::Resource @id=102 />]
25
35
  #
26
36
  # Both a list of Strings, Symbols or a combination of these can be passed
27
37
  # to the `select` method.
28
38
  def select(*fields)
39
+ if block_given?
40
+ raise ArgumentError, "'select' with block doesn't take arguments." if fields.any?
41
+
42
+ return super()
43
+ end
44
+
29
45
  clone.select!(*fields)
30
46
  end
31
47
 
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../api_resource'
4
+
5
+ module ErpIntegration
6
+ module Fulfil
7
+ module Resources
8
+ class Webhook < ApiResource
9
+ self.model_name = 'ir.webhook'
10
+
11
+ # Archives the webhook with the given ID.
12
+ # @param id [Integer] The ID of the webhook to archive.
13
+ # @return [Boolean] Whether the webhook was archived successfully or not.
14
+ def archive(id)
15
+ client.put("model/#{model_name}/archive", [[id]])
16
+ true
17
+ rescue ErpIntegration::HttpError::BadRequest
18
+ false
19
+ # Workaround: Fulfil api does not return a json when status code is 200
20
+ # (a.k.a. "Ok") and faraday is having an error when trying to parse it.
21
+ # Let's skip the parse error and move on.
22
+ rescue Faraday::ParsingError
23
+ true
24
+ end
25
+
26
+ # Restores the webhook with the given ID.
27
+ # @param id [Integer] The ID of the webhook to be restored.
28
+ # @return [Boolean] Whether the webhook was restored successfully or not.
29
+ def restore(id)
30
+ client.put("model/#{model_name}/restore", [[id]])
31
+ true
32
+ rescue ErpIntegration::HttpError::BadRequest
33
+ false
34
+ # Workaround: Fulfil api does not return a json when status code is 200
35
+ # (a.k.a. "Ok") and faraday is having an error when trying to parse it.
36
+ # Let's skip the parse error and move on.
37
+ rescue Faraday::ParsingError
38
+ true
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ErpIntegration
4
- VERSION = '0.13.0'
4
+ VERSION = '0.15.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErpIntegration
4
+ # The `ErpIntegration::Webhook` exposes an uniformed API for interaction with
5
+ # third-party ERP vendors.
6
+ class Webhook < Resource
7
+ attr_accessor :id, :active, :attachments, :create_date, :create_uid, :event,
8
+ :messages, :metadata, :metafields, :private_notes, :public_notes,
9
+ :rec_blurb, :rec_name, :recent_deliveries, :secret, :url, :write_date,
10
+ :write_uid
11
+
12
+ class << self
13
+ def archive(id)
14
+ adapter.archive(id)
15
+ end
16
+
17
+ def restore(id)
18
+ adapter.restore(id)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -37,6 +37,7 @@ module ErpIntegration
37
37
  autoload :StockMove, 'erp_integration/stock_move'
38
38
  autoload :SupplierShipment, 'erp_integration/supplier_shipment'
39
39
  autoload :TrackingNumber, 'erp_integration/tracking_number'
40
+ autoload :Webhook, 'erp_integration/webhook'
40
41
 
41
42
  module Resources
42
43
  autoload :Errors, 'erp_integration/resources/errors'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erp_integration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Vermaas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -202,14 +202,14 @@ dependencies:
202
202
  requirements:
203
203
  - - "~>"
204
204
  - !ruby/object:Gem::Version
205
- version: 3.17.0
205
+ version: 3.18.1
206
206
  type: :development
207
207
  prerelease: false
208
208
  version_requirements: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - "~>"
211
211
  - !ruby/object:Gem::Version
212
- version: 3.17.0
212
+ version: 3.18.1
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: parallel
215
215
  requirement: !ruby/object:Gem::Requirement
@@ -289,6 +289,7 @@ files:
289
289
  - lib/erp_integration/fulfil/resources/stock_move.rb
290
290
  - lib/erp_integration/fulfil/resources/supplier_shipment.rb
291
291
  - lib/erp_integration/fulfil/resources/tracking_number.rb
292
+ - lib/erp_integration/fulfil/resources/webhook.rb
292
293
  - lib/erp_integration/fulfil/where_clause.rb
293
294
  - lib/erp_integration/middleware/error_handling.rb
294
295
  - lib/erp_integration/product.rb
@@ -307,6 +308,7 @@ files:
307
308
  - lib/erp_integration/supplier_shipment.rb
308
309
  - lib/erp_integration/tracking_number.rb
309
310
  - lib/erp_integration/version.rb
311
+ - lib/erp_integration/webhook.rb
310
312
  homepage: https://www.github.com/mejuri-inc/erp-integration
311
313
  licenses:
312
314
  - MIT