erp_integration 0.12.0 → 0.13.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/fulfil/api_resource.rb +34 -20
- data/lib/erp_integration/fulfil/context.rb +47 -0
- data/lib/erp_integration/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c09fbc8ebeff2b8b907e88e8b9bc147aefba15d5f7c1245de69cf66b24a8e6
|
4
|
+
data.tar.gz: c4ffdceea9bd5510bbee71647868e54a1ef36cc58bd7832a9333216811a3dd81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e7a15d4a90a16905aab8c8be40e751c3b16148ad616631e6adad6033fdf444eeaeb9d6f37e30ba4639f17f5a1a7e800281051a2e98e44aa93936e74eed7c0de
|
7
|
+
data.tar.gz: bfba3edd52a0529d5ca11457b12ab255c3aed41fb2ca08df17c2c09333fa7c22c76ce96a0b96436c84327b62442d4129429d5a928863e5185c3724d926ddcef2
|
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.17.0'
|
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
|
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.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Vermaas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-03 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.17.0
|
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.17.0
|
213
213
|
- !ruby/object:Gem::Dependency
|
214
214
|
name: parallel
|
215
215
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +224,7 @@ dependencies:
|
|
224
224
|
- - '='
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: 1.19.2
|
227
|
-
description:
|
227
|
+
description:
|
228
228
|
email:
|
229
229
|
- stefan@knowndecimal.com
|
230
230
|
executables: []
|
@@ -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
|
@@ -314,7 +315,7 @@ metadata:
|
|
314
315
|
homepage_uri: https://www.github.com/mejuri-inc/erp-integration
|
315
316
|
source_code_uri: https://www.github.com/mejuri-inc/erp-integration
|
316
317
|
changelog_uri: https://www.github.com/mejuri-inc/erp-integration/blob/main/CHANGELOG.md
|
317
|
-
post_install_message:
|
318
|
+
post_install_message:
|
318
319
|
rdoc_options: []
|
319
320
|
require_paths:
|
320
321
|
- lib
|
@@ -330,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
331
|
version: '0'
|
331
332
|
requirements: []
|
332
333
|
rubygems_version: 3.2.22
|
333
|
-
signing_key:
|
334
|
+
signing_key:
|
334
335
|
specification_version: 4
|
335
336
|
summary: Connects Mejuri with third-party ERP vendors
|
336
337
|
test_files: []
|