erp_integration 0.12.0 → 0.13.0

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: f838562b7bce4ffaab0944a370300bfa1c9d2f43d71777342a34be928857622b
4
- data.tar.gz: f693bb521585a843abe5afd0fa1637a6235198a0a466cfe116130bd8f4906c81
3
+ metadata.gz: 33c09fbc8ebeff2b8b907e88e8b9bc147aefba15d5f7c1245de69cf66b24a8e6
4
+ data.tar.gz: c4ffdceea9bd5510bbee71647868e54a1ef36cc58bd7832a9333216811a3dd81
5
5
  SHA512:
6
- metadata.gz: a008498534cd8274a24dcb37fe11c090126f128756d388173c908a29458aedc7fe8f8b70a53652c5499aafad5f27896ca61c7648c8bf3dacb8d032e0d21a66a3
7
- data.tar.gz: 99ac0de4fa2bfb6a1a6bbbc709bb8b84eac47157561e45a16e5df4827f8e8b12ecfd7222ba262a626546b20fee27919655a01b6b25a820cd31bda389d083c519
6
+ metadata.gz: 4e7a15d4a90a16905aab8c8be40e751c3b16148ad616631e6adad6033fdf444eeaeb9d6f37e30ba4639f17f5a1a7e800281051a2e98e44aa93936e74eed7c0de
7
+ data.tar.gz: bfba3edd52a0529d5ca11457b12ab255c3aed41fb2ca08df17c2c09333fa7c22c76ce96a0b96436c84327b62442d4129429d5a928863e5185c3724d926ddcef2
@@ -15,4 +15,4 @@ jobs:
15
15
  steps:
16
16
  - uses: seferov/pr-lint-action@master
17
17
  with:
18
- title-regex: '^\[RELEASE|NO-TICKET|DL|AD|DU|AR|IN|MT-\d*\](\ )'
18
+ title-regex: '^\[RELEASE|NO-TICKET|DL|UDL|AD|DU|AR|IN|CON|DIS|AS|MT|DEL-\d*\](\ )'
data/.reek.yml CHANGED
@@ -79,7 +79,8 @@ detectors:
79
79
  max_instance_variables: 4
80
80
  TooManyMethods:
81
81
  enabled: true
82
- exclude: []
82
+ exclude:
83
+ - ErpIntegration::Configuration # There are a lot of configuration options available.
83
84
  max_methods: 15
84
85
  TooManyStatements:
85
86
  enabled: true
@@ -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.14.0'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ErpIntegration
4
- VERSION = '0.12.0'
4
+ VERSION = '0.13.0'
5
5
  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.12.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-04-04 00:00:00.000000000 Z
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.14.0
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.14.0
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: []