fulfil-io 0.2.0 → 0.4.4
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 +4 -4
- data/CHANGELOG.md +35 -9
- data/README.md +45 -3
- data/lib/fulfil/client.rb +54 -9
- data/lib/fulfil/model.rb +4 -0
- data/lib/fulfil/response_parser.rb +14 -2
- data/lib/fulfil/version.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7be62208f07b3dabac64da70cd97d7ef5d5e513a363d830206ffc6ad25ebffc5
|
4
|
+
data.tar.gz: ddba02ac333a132dcce3886f51b35865d58f4a999adba7f1f10a9ee3cec5e344
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02e3e8e5ae922598b1971b96ba26ba2a17c6f05cc4c2ea319bc0e3d69b75fdfc9115ee860b43d4c2965e292f80470ea17d9c07819d0d30aef03610fa1611ae85
|
7
|
+
data.tar.gz: 000740a6f8cff338590329900671bf297acfd41c83f38c5197bac711706ac934b37e39e55ec5683575b6e9ffbfead3f73b6d766afb4b0d8a5e357aa6db9c6c4b
|
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,43 @@
|
|
1
|
-
## 0.
|
1
|
+
## 0.4.4
|
2
|
+
|
3
|
+
* Pin http dependency to ~> 4.4.0. 5.0+ introduces a frozen string error.
|
4
|
+
|
5
|
+
## 0.4.3
|
6
|
+
|
7
|
+
* Add Client errors for more granular handling.
|
8
|
+
* Send along info when a `NotAuthorizedError` is raised.
|
9
|
+
|
10
|
+
## 0.4.2
|
2
11
|
|
3
|
-
|
4
|
-
|
12
|
+
* Raise an `UnhandledTypeError` and reveal the offender.
|
13
|
+
* Convert timedelta data types to Decimals.
|
14
|
+
* Don't use `.present?` to check if response is a Hash.
|
5
15
|
|
6
|
-
|
7
|
-
' class.
|
16
|
+
## 0.4.1
|
8
17
|
|
9
|
-
|
18
|
+
* @cdmwebs screwed up the release process, so this is a tiny bump to fix. No
|
19
|
+
code changes.
|
10
20
|
|
11
|
-
|
21
|
+
## 0.4.0
|
22
|
+
|
23
|
+
* Add `Client#count` and `Model#count`.
|
24
|
+
|
25
|
+
## 0.3.0
|
26
|
+
|
27
|
+
* Add basic write support via `Fulfil::Client#post` and `Fulfil::Client#put`.
|
28
|
+
|
29
|
+
## 0.2.0
|
12
30
|
|
13
|
-
|
31
|
+
* Make token optional and allow specifying headers at least for enabling
|
32
|
+
authentication via 'X-API-KEY' header , because initially implemented in
|
33
|
+
0.1.0 bearer auth isn't working.
|
34
|
+
* Fix Query `build_search_term` and `build_exclude_term` to be compatible with
|
35
|
+
Ruby < 2.4, analyzing value for 'Fixnum ' class.
|
36
|
+
* Fix the gem's name in gemspec to 'fulfil-io', as registered at RubyGems.
|
37
|
+
* Remove Rake version constraint from gemspec.
|
38
|
+
* Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be
|
39
|
+
stored in git for a gem.
|
14
40
|
|
15
41
|
## 0.1.0
|
16
42
|
|
17
|
-
* Initial gem release
|
43
|
+
* Initial gem release.
|
data/README.md
CHANGED
@@ -28,9 +28,9 @@ Environment variables:
|
|
28
28
|
- FULFIL_TOKEN - required for oauth bearer authentication
|
29
29
|
- FULFIL_API_KEY - required for authentication via the X-API-KEY request header
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
**Note:** When FULFIL_TOKEN is present, the FULFIL_API_KEY will be ignored. So,
|
32
|
+
if oauth doesn't work, returning an Unauthorized error, to use the
|
33
|
+
FULFIL_API_KEY, the FULFIL_TOKEN shouldn't be specified.
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
require 'fulfil' # this is necessary only in case of running without bundler
|
@@ -68,6 +68,48 @@ pp sales
|
|
68
68
|
# "rec_name"=>""}]
|
69
69
|
```
|
70
70
|
|
71
|
+
### Count
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
client = Fulfil::Client.new
|
75
|
+
model = Fulfil::Model.new(client: client, model_name: 'stock.shipment.out')
|
76
|
+
model.count(domain: [['shipping_batch.state', '=', 'open']])
|
77
|
+
|
78
|
+
# Returns 7440
|
79
|
+
```
|
80
|
+
|
81
|
+
### Writing
|
82
|
+
|
83
|
+
As of v0.3.0, we've added very basic support for creates and updates via
|
84
|
+
`Fulfil::Client#post` and `Fulfil::Client#put`.
|
85
|
+
|
86
|
+
*Create Example*
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
fulfil = Fulfil::Client.new
|
90
|
+
|
91
|
+
sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
|
92
|
+
|
93
|
+
sale = {
|
94
|
+
# Full Sale attributes here
|
95
|
+
}
|
96
|
+
|
97
|
+
fulfil.post(model: sale_model, body: sale)
|
98
|
+
```
|
99
|
+
|
100
|
+
*Update Example*
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
fulfil = Fulfil::Client.new
|
104
|
+
|
105
|
+
sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
|
106
|
+
sale = sale_model.find(id: 1234)
|
107
|
+
|
108
|
+
sale['channel'] = 4
|
109
|
+
|
110
|
+
fulfil.put(model: sale_model, body: sale)
|
111
|
+
```
|
112
|
+
|
71
113
|
## Development
|
72
114
|
|
73
115
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
data/lib/fulfil/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'http'
|
2
4
|
require 'logger'
|
3
5
|
require 'fulfil/response_parser'
|
@@ -8,6 +10,11 @@ module Fulfil
|
|
8
10
|
OAUTH_TOKEN = ENV['FULFIL_TOKEN']
|
9
11
|
|
10
12
|
class Client
|
13
|
+
class NotAuthorizedError < StandardError; end
|
14
|
+
class UnknownHTTPError < StandardError; end
|
15
|
+
class ConnectionError < StandardError; end
|
16
|
+
class ResponseError < StandardError; end
|
17
|
+
|
11
18
|
def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
|
12
19
|
@subdomain = subdomain
|
13
20
|
@token = token
|
@@ -50,9 +57,42 @@ module Fulfil
|
|
50
57
|
parse(results: results)
|
51
58
|
end
|
52
59
|
|
60
|
+
def count(model:, domain:)
|
61
|
+
uri = URI("#{model_url(model: model)}/search_count")
|
62
|
+
body = [domain]
|
63
|
+
|
64
|
+
request(verb: :put, endpoint: uri, json: body)
|
65
|
+
end
|
66
|
+
|
67
|
+
def post(model:, body: {})
|
68
|
+
uri = URI(model_url(model: model))
|
69
|
+
|
70
|
+
results = request(verb: :post, endpoint: uri, json: body)
|
71
|
+
parse(results: results)
|
72
|
+
end
|
73
|
+
|
74
|
+
def put(model:, id:, endpoint: nil, body: {})
|
75
|
+
uri = URI(model_url(model: model, id: id, endpoint: endpoint))
|
76
|
+
|
77
|
+
result = request(verb: :put, endpoint: uri, json: body)
|
78
|
+
parse(result: result)
|
79
|
+
end
|
80
|
+
|
53
81
|
private
|
54
82
|
|
55
83
|
def parse(result: nil, results: [])
|
84
|
+
if result
|
85
|
+
parse_single(result: result)
|
86
|
+
else
|
87
|
+
parse_multiple(results: results)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def parse_single(result:)
|
92
|
+
Fulfil::ResponseParser.parse(item: result)
|
93
|
+
end
|
94
|
+
|
95
|
+
def parse_multiple(results:)
|
56
96
|
results.map { |result| Fulfil::ResponseParser.parse(item: result) }
|
57
97
|
end
|
58
98
|
|
@@ -60,26 +100,31 @@ module Fulfil
|
|
60
100
|
"https://#{@subdomain}.fulfil.io/api/v2/model"
|
61
101
|
end
|
62
102
|
|
63
|
-
def model_url(model:)
|
64
|
-
[base_url, model].join('/')
|
103
|
+
def model_url(model:, id: nil, endpoint: nil)
|
104
|
+
[base_url, model, id, endpoint].compact.join('/')
|
65
105
|
end
|
66
106
|
|
67
107
|
def request(verb: :get, endpoint:, **args)
|
68
108
|
response = client.request(verb, endpoint, args)
|
69
109
|
|
70
|
-
if response.status.ok?
|
110
|
+
if response.status.ok? || response.status.created?
|
71
111
|
response.parse
|
72
112
|
elsif response.code == 401
|
73
|
-
|
113
|
+
error = response.parse
|
114
|
+
raise NotAuthorizedError, "Not authorized: #{error['error']}: #{error['error_description']}"
|
74
115
|
else
|
75
|
-
|
76
|
-
raise
|
116
|
+
puts response.body.to_s
|
117
|
+
raise Error, 'Error encountered while processing response:'
|
77
118
|
end
|
78
|
-
rescue HTTP::
|
119
|
+
rescue HTTP::Error => e
|
120
|
+
puts e
|
121
|
+
raise UnknownHTTPError, 'Unhandled HTTP error encountered'
|
122
|
+
rescue HTTP::ConnectionError => e
|
79
123
|
puts "Couldn't connect"
|
80
|
-
raise
|
124
|
+
raise ConnectionError, "Can't connect to #{base_url}"
|
81
125
|
rescue HTTP::ResponseError => ex
|
82
|
-
raise
|
126
|
+
raise ResponseError, "Can't process response: #{ex}"
|
127
|
+
[]
|
83
128
|
end
|
84
129
|
|
85
130
|
def client
|
data/lib/fulfil/model.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module Fulfil
|
2
2
|
module ResponseParser
|
3
|
+
class UnhandledTypeError < StandardError
|
4
|
+
attr_reader :value
|
5
|
+
|
6
|
+
def initialize(msg, value)
|
7
|
+
@value = value
|
8
|
+
super(msg)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
# Handle value objects, for example:
|
4
13
|
#
|
5
14
|
# "order_date": {
|
@@ -19,10 +28,13 @@ module Fulfil
|
|
19
28
|
when 'datetime'
|
20
29
|
time = value.dig('iso_string')
|
21
30
|
DateTime.parse(time)
|
22
|
-
when 'Decimal'
|
31
|
+
when 'Decimal', 'timedelta'
|
23
32
|
value.dig('decimal').to_f
|
24
33
|
else
|
25
|
-
raise UnhandledTypeError
|
34
|
+
raise UnhandledTypeError.new(
|
35
|
+
"received a value that we don't know how to handle: #{json_class}",
|
36
|
+
json_class
|
37
|
+
)
|
26
38
|
end
|
27
39
|
end
|
28
40
|
|
data/lib/fulfil/version.rb
CHANGED
metadata
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulfil-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moore
|
8
8
|
- Kat Fairbanks
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 4.4.1
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 4.4.1
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
-
description:
|
98
|
+
description:
|
99
99
|
email:
|
100
100
|
- chris@knowndecimal.com
|
101
101
|
executables: []
|
@@ -119,7 +119,7 @@ homepage: https://github.com/knowndecimal/fulfil
|
|
119
119
|
licenses:
|
120
120
|
- MIT
|
121
121
|
metadata: {}
|
122
|
-
post_install_message:
|
122
|
+
post_install_message:
|
123
123
|
rdoc_options: []
|
124
124
|
require_paths:
|
125
125
|
- lib
|
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
137
|
+
rubygems_version: 3.1.4
|
138
|
+
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Interact with the Fulfil.io API
|
141
141
|
test_files: []
|