fulfil-io 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/Rakefile +8 -6
- data/lib/fulfil/client.rb +7 -7
- data/lib/fulfil/interactive_report.rb +3 -1
- data/lib/fulfil/model.rb +6 -4
- data/lib/fulfil/query.rb +20 -16
- data/lib/fulfil/response_parser.rb +14 -8
- data/lib/fulfil/version.rb +1 -1
- metadata +5 -108
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e82498f50af6f27434982cbeb6bb3faec54a085e999f4d86293d4378afb801a
|
4
|
+
data.tar.gz: d2596d9afedaf2f67aa3f573c139d1c5a03b706e638fdf2407fc482f25336d6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67ad033ab2a666abc04747a37e1d4859690158cfdf1c6455cdc3e3383ccfd6aa74b556def1b02e7584945120b426357ed4a85fa1f1feaa74ad118fbe6161280c
|
7
|
+
data.tar.gz: 1ade1a109a650b56c76fcaea49ed71d92b87d8f87e6659748ea5c739d6e6f1715ec6099835f2faefd7c515e8482054d580c17b0fcb74342c2cc214d40fabaeee
|
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.
|
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
|
-
|
2
|
-
|
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 <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
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
|
9
|
-
API_KEY = ENV
|
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
|
-
|
118
|
+
'FULFIL_TOKEN to FULFIL_OAUTH_TOKEN.'
|
118
119
|
end
|
119
120
|
|
120
|
-
ENV['FULFIL_OAUTH_TOKEN'] || ENV
|
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(
|
178
|
+
client = HTTP.use(logging: @debug ? { logger: Logger.new($stdout) } : {})
|
178
179
|
client = client.auth("Bearer #{@token}") if @token
|
179
|
-
client
|
180
|
-
client
|
180
|
+
client.headers(@headers)
|
181
181
|
end
|
182
182
|
|
183
183
|
def config
|
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
|
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
|
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.
|
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.
|
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.
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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([
|
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(
|
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
|
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(
|
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
|
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
|
22
|
+
return value unless value.is_a?(Hash) && value['__class__']
|
21
23
|
|
22
|
-
json_class = value
|
24
|
+
json_class = value['__class__']
|
23
25
|
|
24
26
|
case json_class
|
25
27
|
when 'date'
|
26
|
-
date = value
|
28
|
+
date = value['iso_string']
|
27
29
|
Date.parse(date)
|
28
30
|
when 'datetime'
|
29
|
-
time = value
|
31
|
+
time = value['iso_string']
|
30
32
|
DateTime.parse(time)
|
31
33
|
when 'Decimal', 'timedelta'
|
32
|
-
value
|
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
|
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
|
-
|
57
|
-
|
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
|
data/lib/fulfil/version.rb
CHANGED
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.
|
4
|
+
version: 0.8.0
|
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:
|
13
|
+
date: 2023-04-20 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,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
72
|
requirements:
|
176
73
|
- - ">="
|
177
74
|
- !ruby/object:Gem::Version
|
178
|
-
version: '2.
|
75
|
+
version: '2.6'
|
179
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
77
|
requirements:
|
181
78
|
- - ">="
|