erp_integration 0.17.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/erp_integration/fulfil/api_resource.rb +28 -1
- data/lib/erp_integration/fulfil/pagination_methods.rb +34 -0
- data/lib/erp_integration/fulfil/query.rb +15 -5
- data/lib/erp_integration/fulfil/query_methods.rb +20 -1
- data/lib/erp_integration/fulfil/where_clause.rb +7 -2
- data/lib/erp_integration/version.rb +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07ca72811d7f1eb2659d9161890f3a43ce8b773e9637e55dea2e7c0f5b6d8d44
|
4
|
+
data.tar.gz: 7ab55ad7cf24cbbf761e344f5a8a4a91fca2110637f28112d47ce49a0b11e639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb0053f0c8d31c3e3fd003aa9c65e141be176f4f60c787a132ffd3dc16300ecdca01be39e2b2c4e7897f5120464957979ab052139e4a381033e5f1467860bedd
|
7
|
+
data.tar.gz: 9987a496c6ee7bbd02f5faa92f3fb93172544ee999444d9f2851bbc30cbb59b3fe1ca10b424187f27e553eb0fd947ebe6118190546e167679c0166e4f840f9e5
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'context'
|
4
4
|
require_relative 'finder_methods'
|
5
|
+
require_relative 'pagination_methods'
|
5
6
|
require_relative 'persistence'
|
6
7
|
require_relative 'query_methods'
|
7
8
|
|
@@ -11,6 +12,7 @@ module ErpIntegration
|
|
11
12
|
include Context
|
12
13
|
include Enumerable
|
13
14
|
include FinderMethods
|
15
|
+
include PaginationMethods
|
14
16
|
include Persistence
|
15
17
|
include QueryMethods
|
16
18
|
|
@@ -63,10 +65,35 @@ module ErpIntegration
|
|
63
65
|
@results =
|
64
66
|
client.put(
|
65
67
|
api_resource_path,
|
66
|
-
Query.new(
|
68
|
+
Query.new(
|
69
|
+
fields: selected_fields,
|
70
|
+
filters: where_clauses,
|
71
|
+
alternative_filters: or_clauses,
|
72
|
+
offset: offset_clause,
|
73
|
+
limit: limit_clause
|
74
|
+
)
|
67
75
|
).map { |item| resource_klass.new(item) }
|
68
76
|
end
|
69
77
|
|
78
|
+
# As with the `all` method, the `query methods` lazyly build a search/read
|
79
|
+
# or search/count query for Fulfil.
|
80
|
+
# By calling `count`, the prepared search/count will actually be executed and
|
81
|
+
# the result will be fetched
|
82
|
+
# @return [Integer] The count of records that match with the query in Fulfil
|
83
|
+
def count
|
84
|
+
return @count if defined?(@count)
|
85
|
+
|
86
|
+
@count =
|
87
|
+
client.put(
|
88
|
+
"model/#{model_name}/search_count",
|
89
|
+
Query.new(
|
90
|
+
fields: nil,
|
91
|
+
filters: where_clauses,
|
92
|
+
alternative_filters: or_clauses
|
93
|
+
).to_h.except(:fields, :offset, :limit)
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
70
97
|
# The `each` method turns the `ApiResource` instance into an enumerable object.
|
71
98
|
# For more information, see https://ruby-doc.org/core-3.0.2/Enumerable.html
|
72
99
|
def each(&block)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ErpIntegration
|
4
|
+
module Fulfil
|
5
|
+
module PaginationMethods
|
6
|
+
DEFAULT_OFFSET = 0
|
7
|
+
MAX_LIMIT = 500 # Max limit set by FF
|
8
|
+
|
9
|
+
attr_accessor :offset_clause, :limit_clause
|
10
|
+
|
11
|
+
# Fulfil by default is returning us the first 500 records on every query that we made.
|
12
|
+
# The `offset` method, as the name sais, will allow us to move the offset of the results.
|
13
|
+
# @example
|
14
|
+
# $ ErpIntegration::SalesOrder.offset(10).all
|
15
|
+
# # => <ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @offset=10 />] />
|
16
|
+
def offset(offset)
|
17
|
+
self.offset_clause = offset
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
# Fulfil by default is returning us the first 500 records on every query that we made.
|
23
|
+
# The `limit` method will allow us to modify the amount of records that we want to receive.
|
24
|
+
# @example
|
25
|
+
# $ ErpIntegration::SalesOrder.limit(5).all
|
26
|
+
# # => <ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @limit=5 />] />
|
27
|
+
def limit(limit)
|
28
|
+
self.limit_clause = [limit, MAX_LIMIT].min
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -18,22 +18,32 @@ module ErpIntegration
|
|
18
18
|
# @example
|
19
19
|
# Faraday.post("/api-endpoint", Query.new([:id, 'product.id'], [WhereClause.new(key: :id, value: 100)]))
|
20
20
|
class Query
|
21
|
-
|
21
|
+
delegate :to_json, to: :to_h
|
22
|
+
|
23
|
+
attr_reader :fields, :filters, :offset, :limit
|
24
|
+
|
22
25
|
DEFAULT_FIELDS = %w[id].freeze
|
23
26
|
|
24
27
|
# @param fields [Array<String|Symbol>] A list of fields for Fulfil.
|
25
28
|
# @param filters [Array<WhereClause>] A list of where clauses for Fulfil.
|
26
|
-
|
29
|
+
# @param alternative_filters [Array<OrClause>] A list of or clauses for Fulfil.
|
30
|
+
# @param offset [Integer] Offset for pagination.
|
31
|
+
# @param limit [Integer] Limit for pagination.
|
32
|
+
def initialize(fields:, filters:, alternative_filters: [], offset: nil, limit: nil)
|
27
33
|
@fields = (fields || DEFAULT_FIELDS).map(&:to_s).uniq
|
28
34
|
@filters = (filters || []).map(&:to_filter).uniq
|
29
35
|
@filters += alternative_filters.map(&:to_filter).uniq if alternative_filters&.any?
|
36
|
+
@offset = offset
|
37
|
+
@limit = limit
|
30
38
|
end
|
31
39
|
|
32
|
-
def
|
40
|
+
def to_h
|
33
41
|
{
|
34
42
|
fields: @fields,
|
35
|
-
filters: @filters
|
36
|
-
|
43
|
+
filters: @filters,
|
44
|
+
offset: @offset,
|
45
|
+
limit: @limit
|
46
|
+
}
|
37
47
|
end
|
38
48
|
end
|
39
49
|
end
|
@@ -71,12 +71,13 @@ module ErpIntegration
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def where!(args)
|
74
|
+
domain = args.delete(:domain)
|
74
75
|
comparison_operator = args.delete(:comparison_operator)
|
75
76
|
|
76
77
|
args.each_pair do |key, value|
|
77
78
|
self.where_clauses =
|
78
79
|
(where_clauses || []) << WhereClause.new(
|
79
|
-
key: key, value: value, comparison_operator: comparison_operator
|
80
|
+
key: key, value: value, domain: domain, comparison_operator: comparison_operator
|
80
81
|
)
|
81
82
|
end
|
82
83
|
|
@@ -124,6 +125,24 @@ module ErpIntegration
|
|
124
125
|
self
|
125
126
|
end
|
126
127
|
|
128
|
+
# The `where_domain` method provides an interface for querying resources
|
129
|
+
# in Fulfil when filtered attributes require specifying
|
130
|
+
# the name of the domain model in which they are located.
|
131
|
+
#
|
132
|
+
# @example
|
133
|
+
# $ ErpIntegration::SalesOrder.where_domain('stock.shipment.out', 'shipment.state': 'done').all
|
134
|
+
# # => <ErpIntegration::Fulfil::Collection @items=[<ErpIntegration::SalesOrder @id=100 />] />
|
135
|
+
#
|
136
|
+
# Adds the domain model name as a fourth argument to each filers parameter
|
137
|
+
#
|
138
|
+
# @example
|
139
|
+
# :filters=>[
|
140
|
+
# ['shipment.state', '=', 'done', 'stock.shipment.out']
|
141
|
+
# ]
|
142
|
+
def where_domain(domain, args)
|
143
|
+
where(args.merge!(domain: domain))
|
144
|
+
end
|
145
|
+
|
127
146
|
def where_ilike(args)
|
128
147
|
where(args.merge(comparison_operator: 'ilike'))
|
129
148
|
end
|
@@ -23,16 +23,21 @@ module ErpIntegration
|
|
23
23
|
|
24
24
|
DEFAULT_COMPARISON_OPERATOR = '='
|
25
25
|
|
26
|
-
|
26
|
+
# @param key [String] The name of filtered attribute.
|
27
|
+
# @param value [String] The value by filtering will be performed.
|
28
|
+
# @param domain [String] The domain model name to specify filtering attributes location.
|
29
|
+
# @param comparison_operator [String] The way the key and the value are compared.
|
30
|
+
def initialize(key:, value:, domain: nil, comparison_operator: DEFAULT_COMPARISON_OPERATOR)
|
27
31
|
@comparison_operator = verify_comparison_operator(comparison_operator)
|
28
32
|
@key = key.to_s
|
29
33
|
@value = value
|
34
|
+
@domain = domain
|
30
35
|
end
|
31
36
|
|
32
37
|
# Transforms the `WhereClause` into a filter object for Fulfil.
|
33
38
|
# @return [Array<String>] The formatted filter for Fulfil.
|
34
39
|
def to_filter
|
35
|
-
[@key, @comparison_operator, @value]
|
40
|
+
[@key, @comparison_operator, @value, @domain].compact
|
36
41
|
end
|
37
42
|
|
38
43
|
# The `===` allows comparing different WhereClause objects. Under the hood,
|
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.19.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: 2023-01-
|
11
|
+
date: 2023-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -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: []
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/erp_integration/fulfil/context.rb
|
273
273
|
- lib/erp_integration/fulfil/finder_methods.rb
|
274
274
|
- lib/erp_integration/fulfil/or_clause.rb
|
275
|
+
- lib/erp_integration/fulfil/pagination_methods.rb
|
275
276
|
- lib/erp_integration/fulfil/persistence.rb
|
276
277
|
- lib/erp_integration/fulfil/query.rb
|
277
278
|
- lib/erp_integration/fulfil/query_methods.rb
|
@@ -320,7 +321,7 @@ metadata:
|
|
320
321
|
homepage_uri: https://www.github.com/mejuri-inc/erp-integration
|
321
322
|
source_code_uri: https://www.github.com/mejuri-inc/erp-integration
|
322
323
|
changelog_uri: https://www.github.com/mejuri-inc/erp-integration/blob/main/CHANGELOG.md
|
323
|
-
post_install_message:
|
324
|
+
post_install_message:
|
324
325
|
rdoc_options: []
|
325
326
|
require_paths:
|
326
327
|
- lib
|
@@ -335,8 +336,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
335
336
|
- !ruby/object:Gem::Version
|
336
337
|
version: '0'
|
337
338
|
requirements: []
|
338
|
-
|
339
|
-
|
339
|
+
rubyforge_project:
|
340
|
+
rubygems_version: 2.7.11
|
341
|
+
signing_key:
|
340
342
|
specification_version: 4
|
341
343
|
summary: Connects Mejuri with third-party ERP vendors
|
342
344
|
test_files: []
|