erp_integration 0.12.0 → 0.14.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/.github/workflows/pull_requests.yml +1 -1
- data/.reek.yml +2 -1
- data/erp_integration.gemspec +1 -1
- data/lib/erp_integration/configuration.rb +4 -0
- data/lib/erp_integration/fulfil/api_resource.rb +34 -20
- data/lib/erp_integration/fulfil/context.rb +47 -0
- data/lib/erp_integration/fulfil/resources/webhook.rb +43 -0
- data/lib/erp_integration/version.rb +1 -1
- data/lib/erp_integration/webhook.rb +22 -0
- data/lib/erp_integration.rb +1 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05a7228a3108da83aa64657c91e0d51aa524a25193d04bdb1cb099725035ad72
|
4
|
+
data.tar.gz: 481ded11b2d65086df6b58059617b38b9a5ec019e8b1136bdd1716372eb17d26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1076e6c9352510f9ad5fcb4d9577bff61bca968560c04b39eb69ef57fc867229c147360ba7f05409689eb16123e81e4a6b97a1c1abf553b9470b2605eb475df
|
7
|
+
data.tar.gz: e7228af01c795a0418cd84114a2ce0a87dde8223a00ae4d4e02e2ab13b7500b39a3d39cc3ffd4b567e8e957b2a440f203e74225b9e8bb66918991ea7f4137fe6
|
data/.reek.yml
CHANGED
data/erp_integration.gemspec
CHANGED
@@ -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.
|
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
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'context'
|
3
4
|
require_relative 'finder_methods'
|
4
5
|
require_relative 'persistence'
|
5
6
|
require_relative 'query_methods'
|
@@ -7,6 +8,7 @@ require_relative 'query_methods'
|
|
7
8
|
module ErpIntegration
|
8
9
|
module Fulfil
|
9
10
|
class ApiResource
|
11
|
+
include Context
|
10
12
|
include Enumerable
|
11
13
|
include FinderMethods
|
12
14
|
include Persistence
|
@@ -19,26 +21,6 @@ module ErpIntegration
|
|
19
21
|
@resource_klass = resource_klass
|
20
22
|
end
|
21
23
|
|
22
|
-
# The `where` and `includes` methods lazyly build a search/read query
|
23
|
-
# for Fulfil. By calling `all`, the prepared search/read query will actually
|
24
|
-
# be executed and the results will be fetched.
|
25
|
-
# @return [Array] An enumerable collection object with all API results.
|
26
|
-
def all
|
27
|
-
return @results if defined?(@results)
|
28
|
-
|
29
|
-
@results =
|
30
|
-
client.put(
|
31
|
-
"model/#{model_name}/search_read",
|
32
|
-
Query.new(selected_fields, where_clauses)
|
33
|
-
).map { |item| resource_klass.new(item) }
|
34
|
-
end
|
35
|
-
|
36
|
-
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
37
|
-
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
38
|
-
def each(&block)
|
39
|
-
all.each(&block)
|
40
|
-
end
|
41
|
-
|
42
24
|
# The `client` exposes the `ErpIntegration::Fulfil::Client` to the class.
|
43
25
|
# @return [ErpIntegration::Fulfil::Client] The HTTP client for Fulfil.
|
44
26
|
def self.client
|
@@ -70,6 +52,38 @@ module ErpIntegration
|
|
70
52
|
def self.model_name
|
71
53
|
instance_variable_get(:@model_name)
|
72
54
|
end
|
55
|
+
|
56
|
+
# The `where` and `includes` methods lazyly build a search/read query
|
57
|
+
# for Fulfil. By calling `all`, the prepared search/read query will actually
|
58
|
+
# be executed and the results will be fetched.
|
59
|
+
# @return [Array] An enumerable collection object with all API results.
|
60
|
+
def all
|
61
|
+
return @results if defined?(@results)
|
62
|
+
|
63
|
+
@results =
|
64
|
+
client.put(
|
65
|
+
api_resource_path,
|
66
|
+
Query.new(selected_fields, where_clauses)
|
67
|
+
).map { |item| resource_klass.new(item) }
|
68
|
+
end
|
69
|
+
|
70
|
+
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
71
|
+
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
72
|
+
def each(&block)
|
73
|
+
all.each(&block)
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# Builds the relative resource path and adds the context if needed.
|
79
|
+
#
|
80
|
+
# @return [String]
|
81
|
+
def api_resource_path
|
82
|
+
base_path = "model/#{model_name}/search_read"
|
83
|
+
return base_path unless context?
|
84
|
+
|
85
|
+
"#{base_path}?context=#{context.to_json}"
|
86
|
+
end
|
73
87
|
end
|
74
88
|
end
|
75
89
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
# When making HTTP requests to the Fulfil API endpoints, it's possible to define
|
6
|
+
# the warehouses that should be considered part of the querying context.
|
7
|
+
#
|
8
|
+
# This means that it's possible to fetch the stock levels for a specific "warehouse"
|
9
|
+
# when it's specified in the context of the HTTP request to the API endpoints of
|
10
|
+
# Fulfil.
|
11
|
+
#
|
12
|
+
# @example without any context, the main warehouse will be used as configured
|
13
|
+
# in Fulfil through the application settings.
|
14
|
+
#
|
15
|
+
# $ ErpIntegration::Product.find_by(sku: "PT123").quantity_available
|
16
|
+
# => 25
|
17
|
+
#
|
18
|
+
# @example with context, the given warehouse will be used to find the requested
|
19
|
+
# data in Fulfil.
|
20
|
+
#
|
21
|
+
# $ ErpIntegration::Product.with_context(locations: [25]).find_by(sku: "PT123").quantity_available
|
22
|
+
# => 15
|
23
|
+
module Context
|
24
|
+
extend ActiveSupport::Concern
|
25
|
+
|
26
|
+
included do
|
27
|
+
attr_accessor :context
|
28
|
+
end
|
29
|
+
|
30
|
+
# Verifies whether or not the context is set.
|
31
|
+
#
|
32
|
+
# @return [Boolean]
|
33
|
+
def context?
|
34
|
+
!@context.nil? && !@context.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
# Allows setting the context for the HTTP request to the Fulfil API endpoints.
|
38
|
+
#
|
39
|
+
# @param context [Hash] The context for the HTTP request.
|
40
|
+
# @return [ErpIntegration::Fulfil::ApiResource]
|
41
|
+
def with_context(context)
|
42
|
+
@context = (@context || {}).merge(context)
|
43
|
+
self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -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
|
@@ -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
|
data/lib/erp_integration.rb
CHANGED
@@ -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.
|
4
|
+
version: 0.14.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
|
+
date: 2022-11-30 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.
|
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.
|
212
|
+
version: 3.18.1
|
213
213
|
- !ruby/object:Gem::Dependency
|
214
214
|
name: parallel
|
215
215
|
requirement: !ruby/object:Gem::Requirement
|
@@ -268,6 +268,7 @@ files:
|
|
268
268
|
- lib/erp_integration/errors.rb
|
269
269
|
- lib/erp_integration/fulfil/api_resource.rb
|
270
270
|
- lib/erp_integration/fulfil/client.rb
|
271
|
+
- lib/erp_integration/fulfil/context.rb
|
271
272
|
- lib/erp_integration/fulfil/finder_methods.rb
|
272
273
|
- lib/erp_integration/fulfil/persistence.rb
|
273
274
|
- lib/erp_integration/fulfil/query.rb
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- lib/erp_integration/fulfil/resources/stock_move.rb
|
289
290
|
- lib/erp_integration/fulfil/resources/supplier_shipment.rb
|
290
291
|
- lib/erp_integration/fulfil/resources/tracking_number.rb
|
292
|
+
- lib/erp_integration/fulfil/resources/webhook.rb
|
291
293
|
- lib/erp_integration/fulfil/where_clause.rb
|
292
294
|
- lib/erp_integration/middleware/error_handling.rb
|
293
295
|
- lib/erp_integration/product.rb
|
@@ -306,6 +308,7 @@ files:
|
|
306
308
|
- lib/erp_integration/supplier_shipment.rb
|
307
309
|
- lib/erp_integration/tracking_number.rb
|
308
310
|
- lib/erp_integration/version.rb
|
311
|
+
- lib/erp_integration/webhook.rb
|
309
312
|
homepage: https://www.github.com/mejuri-inc/erp-integration
|
310
313
|
licenses:
|
311
314
|
- MIT
|
@@ -329,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
329
332
|
- !ruby/object:Gem::Version
|
330
333
|
version: '0'
|
331
334
|
requirements: []
|
332
|
-
rubygems_version: 3.
|
335
|
+
rubygems_version: 3.3.7
|
333
336
|
signing_key:
|
334
337
|
specification_version: 4
|
335
338
|
summary: Connects Mejuri with third-party ERP vendors
|