erp_integration 0.17.0 → 0.18.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: 18ec55a600cfb88679e7c8ac4a8e397cd304312a5f85a7c2e54d63307d7c86ff
4
- data.tar.gz: 106c3c7f314668d09bb8589d1ea5243e4586a705871f891edf95efd0d9228028
3
+ metadata.gz: 06ef5b266cf00ceea7a3f9edda9f8a97245126b091cdae782ba847b02db82d55
4
+ data.tar.gz: b03d2ba35b1d16d810d00c1e23b608277ed636d565ce320dd2db15149dee7d4d
5
5
  SHA512:
6
- metadata.gz: 9b8cd54866c82420eed9237a40d8d668494763ed7ef15ac588a15d73260e163eb416a1fb8bc316cd4e08624dddfc70a99e99b3056b046ed4ebb0601298ae0728
7
- data.tar.gz: 90e3145efef13b1d5f6307dd75a74811604cc2766f643970847d3570ff7dcba62fa11c252590b94d9f43f46df2b42352e1de754cf3a55a17f2472ce89a8fc980
6
+ metadata.gz: 2210bedf6de54f4fcc4e215f6e7f9a357e4398b89555a1348c1baca68be74d763062b256b4f99ae08bd370646f23742f274d00ff3747370e06a54aca8747f2ff
7
+ data.tar.gz: 3b8a4877b3730a41b651ab6e2e637a14f2599b3718d3a9f3da8b2c2b1371478f8d520cae94a63835a45cfddf8cd5f175622bd61fdfad1502af99f201ff35ea29
@@ -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(selected_fields, where_clauses, or_clauses)
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
- attr_reader :fields, :filters
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
- def initialize(fields, filters, alternative_filters = [])
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 to_json(*_object)
40
+ def to_h
33
41
  {
34
42
  fields: @fields,
35
- filters: @filters
36
- }.to_json
43
+ filters: @filters,
44
+ offset: @offset,
45
+ limit: @limit
46
+ }
37
47
  end
38
48
  end
39
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ErpIntegration
4
- VERSION = '0.17.0'
4
+ VERSION = '0.18.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.17.0
4
+ version: 0.18.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: 2023-01-12 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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