fulfil-io 0.7.1 → 0.8.1

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: 379e34db2187ee0e41cbc4a530deec467a6f7874c8474c6a5057981ed6ff7ffc
4
- data.tar.gz: da1e1fcf9945729d29554c803fcd954611575ba54f74e7f1c1931fe4e4554731
3
+ metadata.gz: 4c465ec839e9c594b602b0e70f3058214630c38e6b8544ed456a16e5c518aeac
4
+ data.tar.gz: 22d0df9435f0f5432bf16193b40f25cd6f681c796c163f5aac6c6439e940c8c5
5
5
  SHA512:
6
- metadata.gz: 12f8136e71bbe678bac2e3091209b5c56f03f3a70ceb3df50ebca4d88ac32f527e3f29c308affa2180f6e0e6c23964b48fed87801f18173c369f8cc161eb794f
7
- data.tar.gz: 415ab129cabfe1bba36c7fd9bd94b083eeeb64fe0ff71ad508a6f29e74111ab863c281d4da93020b44ec54b1d9ef3fc1ac19ef1809e74af08091deb8824bac1f
6
+ metadata.gz: dfa7f4dde51c08ff6f4b33520817db32a374b99dc41543926256277cb70ead338cd24987c1cefde9100a53492c848e6c87ce7e19308be7d2e5188b9b26060f9e
7
+ data.tar.gz: 4462c5a7b4526802270e1eb80941077faa956b6822e5fe034b84cbdb72021f50d610e461b22419ea4b8d3aa9d1c90be529ab3ad36fbb9b91308de084b4853414
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## 0.8.1
2
+
3
+ * Add logger to configuration by @cdmwebs in https://github.com/knowndecimal/fulfil/pull/49
4
+
5
+ ## 0.8.0
6
+
7
+ * Add rubocop by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/35
8
+ * Remove _now from testing example by @swanny85 in https://github.com/knowndecimal/fulfil/pull/32
9
+ * Add SimpleCov for test coverage by @cdmwebs in https://github.com/knowndecimal/fulfil/pull/38
10
+ * Add support for Fulfil sale duplication by @swanny85 in https://github.com/knowndecimal/fulfil/pull/48
11
+
12
+ ## 0.6.1
13
+
14
+ * Fixes a typo in the examples of the readme by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/25
15
+ * Fix requiring gemfiles manually by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/27
16
+
17
+ ## 0.6.0
18
+
19
+ * Streamline the usage of environment variables. by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/18
20
+ * Update http requirement from ~> 4.4.1 to >= 4.4.1, < 5.1.0 by @dependabot in https://github.com/knowndecimal/fulfil/pull/12
21
+ * Remove extremely precise User-Agent from mocks. by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/20
22
+ * Use GitHub Actions instead of Travis CI and Circle CI by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/21
23
+ * Remove persistent connection and client caching by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/22
24
+ * Add rate limit detection by @stefanvermaas in https://github.com/knowndecimal/fulfil/pull/24
25
+
26
+ ## 0.5.0
27
+
28
+ * Better response parsing and error handling.
29
+ * Documentation updates.
30
+ * Add release script.
31
+
1
32
  ## 0.4.9
2
33
 
3
34
  * Add client tests and stub with Webmock.
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Tests](https://github.com/knowndecimal/fulfil/actions/workflows/tests.yml/badge.svg)](https://github.com/knowndecimal/fulfil/actions/workflows/tests.yml)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c6100940d3debd3a3a7c/maintainability)](https://codeclimate.com/github/knowndecimal/fulfil/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c6100940d3debd3a3a7c/test_coverage)](https://codeclimate.com/github/knowndecimal/fulfil/test_coverage)
2
4
 
3
5
  # Fulfil.io Rubygem
4
6
 
@@ -173,6 +175,18 @@ Fulfil.configure do |config|
173
175
  end
174
176
  ```
175
177
 
178
+ ## Retrieve multiple records
179
+
180
+ To retrieve multiple records at once, one can pass the IDs into the find method directly.
181
+
182
+ ```ruby
183
+ FulfilClient.find(
184
+ model: 'sale.sale',
185
+ ids: [1, 2, 3, 4],
186
+ fields: %w[id status]
187
+ )
188
+ ```
189
+
176
190
  ## Development
177
191
 
178
192
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -213,7 +227,7 @@ def test_find_one
213
227
  stub_fulfil_get('sale.sale/213112', 'sale_sale')
214
228
 
215
229
  client = Fulfil::Client.new
216
- response = client.find_one(model: 'sale.sale', id: 213_112)
230
+ response = client.find(model: 'sale.sale', id: 213_112)
217
231
 
218
232
  assert_equal 213_112, response['id']
219
233
  end
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
data/lib/fulfil/client.rb CHANGED
@@ -5,8 +5,8 @@ require 'logger'
5
5
  require 'fulfil/response_parser'
6
6
 
7
7
  module Fulfil
8
- SUBDOMAIN = ENV['FULFIL_SUBDOMAIN']
9
- API_KEY = ENV['FULFIL_API_KEY']
8
+ SUBDOMAIN = ENV.fetch('FULFIL_SUBDOMAIN', nil)
9
+ API_KEY = ENV.fetch('FULFIL_API_KEY', nil)
10
10
 
11
11
  class Client
12
12
  class InvalidClientError < StandardError
@@ -93,6 +93,7 @@ module Fulfil
93
93
  uri = URI(model_url(model: model, id: id, endpoint: endpoint))
94
94
 
95
95
  result = request(verb: :put, endpoint: uri, json: body)
96
+
96
97
  parse(result: result)
97
98
  end
98
99
 
@@ -114,10 +115,10 @@ module Fulfil
114
115
  def oauth_token
115
116
  if ENV['FULFIL_TOKEN']
116
117
  puts "You're using an deprecated environment variable. Please update your " \
117
- 'FULFIL_TOKEN to FULFIL_OAUTH_TOKEN.'
118
+ 'FULFIL_TOKEN to FULFIL_OAUTH_TOKEN.'
118
119
  end
119
120
 
120
- ENV['FULFIL_OAUTH_TOKEN'] || ENV['FULFIL_TOKEN']
121
+ ENV['FULFIL_OAUTH_TOKEN'] || ENV.fetch('FULFIL_TOKEN', nil)
121
122
  end
122
123
 
123
124
  def parse(result: nil, results: [])
@@ -174,10 +175,9 @@ module Fulfil
174
175
  end
175
176
 
176
177
  def client
177
- client = HTTP.use(logging: @debug ? { logger: Logger.new(STDOUT) } : {})
178
+ client = HTTP.use(logging: @debug ? { logger: config.logger } : {})
178
179
  client = client.auth("Bearer #{@token}") if @token
179
- client = client.headers(@headers)
180
- client
180
+ client.headers(@headers)
181
181
  end
182
182
 
183
183
  def config
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
4
+
3
5
  module Fulfil
4
6
  # The `Fulfil::Configuration` contains the available configuration options
5
7
  # for the `Fulfil` gem.
@@ -22,9 +24,21 @@ module Fulfil
22
24
  # @return [Proc, nil]
23
25
  attr_accessor :rate_limit_notification_handler
24
26
 
27
+ # Allows the client to configure a logger. Logs are output to $stderr by default.
28
+ #
29
+ # @example Use a logger to log the API rate limit hits
30
+ # Fulfil.configure do |config|
31
+ # config.logger = Logger.new($stderr)
32
+ # end
33
+ #
34
+ # @return [Logger, nil]
35
+ #
36
+ attr_accessor :logger
37
+
25
38
  def initialize
26
39
  @retry_on_rate_limit = false
27
40
  @retry_on_rate_limit_wait = 1
41
+ @logger = Logger.new($stderr)
28
42
  end
29
43
 
30
44
  def retry_on_rate_limit?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fulfil
2
4
  class InteractiveReport
3
5
  def initialize(client:, report:)
@@ -37,4 +39,4 @@ module Fulfil
37
39
  }
38
40
  end
39
41
  end
40
- end
42
+ end
data/lib/fulfil/model.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fulfil/query'
2
4
 
3
5
  module Fulfil
@@ -12,15 +14,15 @@ module Fulfil
12
14
 
13
15
  # Delegate this to the client, including the model_name so we don't have to
14
16
  # type it every time.
15
- def find(model: model_name, id:)
17
+ def find(id:, model: model_name)
16
18
  @client.find(model: model, id: id)
17
19
  end
18
20
 
19
21
  # Delegate this to the client, including the model_name so we don't have to
20
22
  # type it every time.
21
23
  def search(
22
- model: model_name,
23
24
  domain:,
25
+ model: model_name,
24
26
  fields: %w[id rec_name],
25
27
  limit: nil,
26
28
  offset: nil,
@@ -51,7 +53,7 @@ module Fulfil
51
53
 
52
54
  def attributes
53
55
  results = @client.search(model: model_name, domain: [], limit: 1)
54
- @client.find(model: model_name, id: results.first.dig('id'))
56
+ @client.find(model: model_name, id: results.first['id'])
55
57
  end
56
58
 
57
59
  def fetch_associated(models:, association_name:, source_key:, fields:)
@@ -66,7 +68,7 @@ module Fulfil
66
68
  model: association_name, ids: associated_ids, fields: fields
67
69
  )
68
70
 
69
- associated_models_by_id = associated_models.map { |m| [m['id'], m] }.to_h
71
+ associated_models_by_id = associated_models.to_h { |m| [m['id'], m] }
70
72
 
71
73
  models.each do |model|
72
74
  filtered_models =
data/lib/fulfil/query.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fulfil
2
4
  class Query
3
5
  def initialize
@@ -9,11 +11,12 @@ module Fulfil
9
11
  end
10
12
 
11
13
  def search(*args)
12
- options = args.first { |arg| arg.is_a?(Hash) && arg.keys.include?(:options) }.fetch(:options, {})
14
+ options = args.first { |arg| arg.is_a?(Hash) && arg.key?(:options) }.fetch(:options, {})
13
15
 
14
16
  args.each do |arg|
15
17
  arg.each do |field, value|
16
18
  next if value == options
19
+
17
20
  @matchers.concat(build_search_term(field: field, value: value, options: options))
18
21
  end
19
22
  end
@@ -22,17 +25,18 @@ module Fulfil
22
25
  end
23
26
 
24
27
  def exclude(*args)
25
- options = args.first { |arg| arg.is_a?(Hash) && arg.keys.include?(:options) }.fetch(:options, {})
28
+ options = args.first { |arg| arg.is_a?(Hash) && arg.key?(:options) }.fetch(:options, {})
26
29
 
27
30
  terms = args.flat_map do |arg|
28
- arg.map do |field, value|
29
- next if value == options
30
- build_exclude_term(field: field, value: value, options: options)
31
- end
32
- end
31
+ arg.map do |field, value|
32
+ next if value == options
33
+
34
+ build_exclude_term(field: field, value: value, options: options)
35
+ end
36
+ end
33
37
 
34
38
  if terms.length > 1
35
- @matchers.push(["OR"].concat(terms))
39
+ @matchers.push(['OR'].concat(terms))
36
40
  else
37
41
  @matchers.concat(terms.first)
38
42
  end
@@ -62,7 +66,7 @@ module Fulfil
62
66
  #
63
67
  # IN, NOT IN: (Array)
64
68
  #
65
- def build_search_term(prefix: nil, field:, value:, options:)
69
+ def build_search_term(field:, value:, options:, prefix: nil)
66
70
  key = [prefix, field.to_s].compact.join('.')
67
71
 
68
72
  case value.class.name
@@ -73,7 +77,7 @@ module Fulfil
73
77
  when 'Range'
74
78
  [
75
79
  [key, '>=', value.first],
76
- [key, '<=', value.last],
80
+ [key, '<=', value.last]
77
81
  ]
78
82
  when 'String'
79
83
  if options[:case_sensitive]
@@ -82,15 +86,15 @@ module Fulfil
82
86
  [[key, 'ilike', value]]
83
87
  end
84
88
  when 'Hash'
85
- value.flat_map { |nested_field, nested_value|
89
+ value.flat_map do |nested_field, nested_value|
86
90
  build_search_term(prefix: field, field: nested_field, value: nested_value, options: options)
87
- }
91
+ end
88
92
  else
89
93
  raise "Unhandled value type: #{value} (#{value.class.name})"
90
94
  end
91
95
  end
92
96
 
93
- def build_exclude_term(prefix: nil, field:, value:, options:)
97
+ def build_exclude_term(field:, value:, options:, prefix: nil)
94
98
  key = [prefix, field.to_s].compact.join('.')
95
99
 
96
100
  case value.class.name
@@ -101,12 +105,12 @@ module Fulfil
101
105
  when 'Range'
102
106
  [
103
107
  [key, '<', value.first],
104
- [key, '>', value.last],
108
+ [key, '>', value.last]
105
109
  ]
106
110
  when 'Hash'
107
- value.flat_map { |nested_field, nested_value|
111
+ value.flat_map do |nested_field, nested_value|
108
112
  build_exclude_term(prefix: field, field: nested_field, value: nested_value, options: options)
109
- }
113
+ end
110
114
  else
111
115
  raise "Unhandled value type: #{value} (#{value.class.name})"
112
116
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fulfil
2
4
  module ResponseParser
3
5
  class UnhandledTypeError < StandardError
@@ -17,19 +19,19 @@ module Fulfil
17
19
  # }
18
20
  #
19
21
  def self.mapped_value_field(value:)
20
- return value unless value.is_a?(Hash) && value.dig('__class__')
22
+ return value unless value.is_a?(Hash) && value['__class__']
21
23
 
22
- json_class = value.dig('__class__')
24
+ json_class = value['__class__']
23
25
 
24
26
  case json_class
25
27
  when 'date'
26
- date = value.dig('iso_string')
28
+ date = value['iso_string']
27
29
  Date.parse(date)
28
30
  when 'datetime'
29
- time = value.dig('iso_string')
31
+ time = value['iso_string']
30
32
  DateTime.parse(time)
31
33
  when 'Decimal', 'timedelta'
32
- value.dig('decimal').to_f
34
+ value['decimal'].to_f
33
35
  else
34
36
  raise UnhandledTypeError.new(
35
37
  "received a value that we don't know how to handle: #{json_class}",
@@ -46,15 +48,19 @@ module Fulfil
46
48
  [group_key, mapped_value_field(value: kv_tuples[0][1])]
47
49
  else
48
50
  id = kv_tuples[0]
49
- attrs = kv_tuples[1..-1].map { |tuple| [tuple[0][1..-1], tuple[1]] }
51
+ attrs = kv_tuples[1..].map { |tuple| [tuple[0][1..], tuple[1]] }
50
52
  [group_key, [['id', id[1]]].concat(group(attrs)).to_h]
51
53
  end
52
54
  end
53
55
  end
54
56
 
55
57
  def self.parse(item:)
56
- key_value_tuples = item.to_a.map { |item_tuple| [item_tuple[0].split('.'), item_tuple[1]] }
57
- group(key_value_tuples).to_h
58
+ case item
59
+ when Hash
60
+ group(item.map { |(key, value)| [key.split('.'), value] }).to_h
61
+ else
62
+ item
63
+ end
58
64
  end
59
65
  end
60
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fulfil
4
- VERSION = "0.7.1"
4
+ VERSION = '0.8.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fulfil-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moore
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-09-23 00:00:00.000000000 Z
13
+ date: 2023-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http
@@ -32,110 +32,6 @@ dependencies:
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: 5.2.0
35
- - !ruby/object:Gem::Dependency
36
- name: bundler
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '2.0'
42
- type: :development
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '2.0'
49
- - !ruby/object:Gem::Dependency
50
- name: minitest
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '5.0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '5.0'
63
- - !ruby/object:Gem::Dependency
64
- name: minitest-reporters
65
- requirement: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '1.3'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '1.3'
77
- - !ruby/object:Gem::Dependency
78
- name: oauth2
79
- requirement: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '1.4'
84
- type: :development
85
- prerelease: false
86
- version_requirements: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '1.4'
91
- - !ruby/object:Gem::Dependency
92
- name: rake
93
- requirement: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
- type: :development
99
- prerelease: false
100
- version_requirements: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - ">="
103
- - !ruby/object:Gem::Version
104
- version: '0'
105
- - !ruby/object:Gem::Dependency
106
- name: webmock
107
- requirement: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- type: :development
113
- prerelease: false
114
- version_requirements: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- - !ruby/object:Gem::Dependency
120
- name: dotenv
121
- requirement: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: '2.7'
126
- - - ">="
127
- - !ruby/object:Gem::Version
128
- version: 2.7.6
129
- type: :development
130
- prerelease: false
131
- version_requirements: !ruby/object:Gem::Requirement
132
- requirements:
133
- - - "~>"
134
- - !ruby/object:Gem::Version
135
- version: '2.7'
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: 2.7.6
139
35
  description:
140
36
  email:
141
37
  - chris@knowndecimal.com
@@ -166,7 +62,8 @@ files:
166
62
  homepage: https://github.com/knowndecimal/fulfil
167
63
  licenses:
168
64
  - MIT
169
- metadata: {}
65
+ metadata:
66
+ rubygems_mfa_required: 'true'
170
67
  post_install_message:
171
68
  rdoc_options: []
172
69
  require_paths:
@@ -175,14 +72,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
72
  requirements:
176
73
  - - ">="
177
74
  - !ruby/object:Gem::Version
178
- version: '2.4'
75
+ version: '2.6'
179
76
  required_rubygems_version: !ruby/object:Gem::Requirement
180
77
  requirements:
181
78
  - - ">="
182
79
  - !ruby/object:Gem::Version
183
80
  version: '0'
184
81
  requirements: []
185
- rubygems_version: 3.3.12
82
+ rubygems_version: 3.3.7
186
83
  signing_key:
187
84
  specification_version: 4
188
85
  summary: Interact with the Fulfil.io API