fulfil-io 0.4.2 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -13
- data/README.md +13 -0
- data/lib/fulfil/client.rb +37 -9
- data/lib/fulfil/interactive_report.rb +33 -0
- data/lib/fulfil/version.rb +1 -1
- data/lib/fulfil.rb +1 -0
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21d5119cc38db9e9a414775dcfc9b37d53ca5fa3ff05218c4ae81bbc912d0695
|
4
|
+
data.tar.gz: a4bf8e9ae17a2993c1a3644d298e39f71c78b1eddc40f6bb20d35bdb25ad1ba5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1fc2fe57cb22c234b12ffe3c0182030baa3be525971eaa7a2f21470e36f5ef9f6957919ba3675574c1159c79ff3b40f28b11167927ce8f852e70fed667f01b3
|
7
|
+
data.tar.gz: 1406056b1b4f566163829b91dd96822c1705286528581567f74d1c383146652a10e0788fd1b80bab81fa79088a32a65440c72483f70fc8c22ae073e9115f19fa
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 0.4.7
|
2
|
+
|
3
|
+
* Bugfix: Accidentally removed the model parameter from the URL.
|
4
|
+
|
5
|
+
## 0.4.6
|
6
|
+
|
7
|
+
* Add InteractiveReport support.
|
8
|
+
|
9
|
+
## 0.4.5
|
10
|
+
|
11
|
+
* Add #delete to client.
|
12
|
+
* Set up Dependabot on GitHub.
|
13
|
+
|
14
|
+
## 0.4.4
|
15
|
+
|
16
|
+
* Pin http dependency to ~> 4.4.0. 5.0+ introduces a frozen string error.
|
17
|
+
|
18
|
+
## 0.4.3
|
19
|
+
|
20
|
+
* Add Client errors for more granular handling.
|
21
|
+
* Send along info when a `NotAuthorizedError` is raised.
|
22
|
+
|
1
23
|
## 0.4.2
|
2
24
|
|
3
25
|
* Raise an `UnhandledTypeError` and reveal the offender.
|
@@ -6,7 +28,8 @@
|
|
6
28
|
|
7
29
|
## 0.4.1
|
8
30
|
|
9
|
-
* @cdmwebs screwed up the release process, so this is a tiny bump to fix. No
|
31
|
+
* @cdmwebs screwed up the release process, so this is a tiny bump to fix. No
|
32
|
+
code changes.
|
10
33
|
|
11
34
|
## 0.4.0
|
12
35
|
|
@@ -18,18 +41,16 @@
|
|
18
41
|
|
19
42
|
## 0.2.0
|
20
43
|
|
21
|
-
|
22
|
-
, because initially implemented in
|
23
|
-
|
24
|
-
|
25
|
-
' class.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
- Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be stored in git for a gem.
|
44
|
+
* Make token optional and allow specifying headers at least for enabling
|
45
|
+
authentication via 'X-API-KEY' header , because initially implemented in
|
46
|
+
0.1.0 bearer auth isn't working.
|
47
|
+
* Fix Query `build_search_term` and `build_exclude_term` to be compatible with
|
48
|
+
Ruby < 2.4, analyzing value for 'Fixnum ' class.
|
49
|
+
* Fix the gem's name in gemspec to 'fulfil-io', as registered at RubyGems.
|
50
|
+
* Remove Rake version constraint from gemspec.
|
51
|
+
* Add Gemfile.lock to .gitignore and remove it from git-tree - it shouldn't be
|
52
|
+
stored in git for a gem.
|
32
53
|
|
33
54
|
## 0.1.0
|
34
55
|
|
35
|
-
* Initial gem release
|
56
|
+
* Initial gem release.
|
data/README.md
CHANGED
@@ -109,6 +109,19 @@ sale['channel'] = 4
|
|
109
109
|
|
110
110
|
fulfil.put(model: sale_model, body: sale)
|
111
111
|
```
|
112
|
+
### Interactive Reports
|
113
|
+
|
114
|
+
As of v0.4.6, interactive report support exists in a basic form.
|
115
|
+
You're able to execute reports with basic params. Responses are
|
116
|
+
transformed to JSON structures.
|
117
|
+
|
118
|
+
```ruby
|
119
|
+
fulfil = Fulfil::Client.new
|
120
|
+
|
121
|
+
report = Fulfil::Report.new(client: fulfil, report_name: 'account.tax.summary.ireport')
|
122
|
+
|
123
|
+
report.execute(start_date: Date.new(2020, 12, 1), end_date: Date.new(2020, 12, 31))
|
124
|
+
```
|
112
125
|
|
113
126
|
## Development
|
114
127
|
|
data/lib/fulfil/client.rb
CHANGED
@@ -10,6 +10,14 @@ module Fulfil
|
|
10
10
|
OAUTH_TOKEN = ENV['FULFIL_TOKEN']
|
11
11
|
|
12
12
|
class Client
|
13
|
+
class NotAuthorizedError < StandardError; end
|
14
|
+
|
15
|
+
class UnknownHTTPError < StandardError; end
|
16
|
+
|
17
|
+
class ConnectionError < StandardError; end
|
18
|
+
|
19
|
+
class ResponseError < StandardError; end
|
20
|
+
|
13
21
|
def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
|
14
22
|
@subdomain = subdomain
|
15
23
|
@token = token
|
@@ -66,13 +74,26 @@ module Fulfil
|
|
66
74
|
parse(results: results)
|
67
75
|
end
|
68
76
|
|
69
|
-
def put(model
|
77
|
+
def put(model: nil, id: nil, endpoint: nil, body: {})
|
70
78
|
uri = URI(model_url(model: model, id: id, endpoint: endpoint))
|
71
79
|
|
72
80
|
result = request(verb: :put, endpoint: uri, json: body)
|
73
81
|
parse(result: result)
|
74
82
|
end
|
75
83
|
|
84
|
+
def delete(model:, id:)
|
85
|
+
uri = URI(model_url(model: model, id: id))
|
86
|
+
|
87
|
+
result = request(verb: :delete, endpoint: uri)
|
88
|
+
parse(result: result)
|
89
|
+
end
|
90
|
+
|
91
|
+
def interactive_report(endpoint:, body: nil)
|
92
|
+
uri = URI("#{base_url}/model/#{endpoint}")
|
93
|
+
result = request(verb: :put, endpoint: uri, json: body)
|
94
|
+
parse(result: result)
|
95
|
+
end
|
96
|
+
|
76
97
|
private
|
77
98
|
|
78
99
|
def parse(result: nil, results: [])
|
@@ -91,33 +112,40 @@ module Fulfil
|
|
91
112
|
results.map { |result| Fulfil::ResponseParser.parse(item: result) }
|
92
113
|
end
|
93
114
|
|
115
|
+
def domain
|
116
|
+
"https://#{@subdomain}.fulfil.io"
|
117
|
+
end
|
118
|
+
|
94
119
|
def base_url
|
95
|
-
|
120
|
+
[domain, 'api', 'v2'].join('/')
|
96
121
|
end
|
97
122
|
|
98
123
|
def model_url(model:, id: nil, endpoint: nil)
|
99
|
-
[base_url, model, id, endpoint].compact.join('/')
|
124
|
+
[base_url, 'model', model, id, endpoint].compact.join('/')
|
100
125
|
end
|
101
126
|
|
102
|
-
def request(verb: :get,
|
127
|
+
def request(endpoint:, verb: :get, **args)
|
103
128
|
response = client.request(verb, endpoint, args)
|
104
129
|
|
105
130
|
if response.status.ok? || response.status.created?
|
106
131
|
response.parse
|
132
|
+
elsif response.code == 204
|
133
|
+
[]
|
107
134
|
elsif response.code == 401
|
108
|
-
|
135
|
+
error = response.parse
|
136
|
+
raise NotAuthorizedError, "Not authorized: #{error['error']}: #{error['error_description']}"
|
109
137
|
else
|
110
138
|
puts response.body.to_s
|
111
139
|
raise Error, 'Error encountered while processing response:'
|
112
140
|
end
|
113
141
|
rescue HTTP::Error => e
|
114
142
|
puts e
|
115
|
-
raise
|
143
|
+
raise UnknownHTTPError, 'Unhandled HTTP error encountered'
|
116
144
|
rescue HTTP::ConnectionError => e
|
117
145
|
puts "Couldn't connect"
|
118
|
-
raise
|
119
|
-
rescue HTTP::ResponseError =>
|
120
|
-
raise
|
146
|
+
raise ConnectionError, "Can't connect to #{base_url}"
|
147
|
+
rescue HTTP::ResponseError => e
|
148
|
+
raise ResponseError, "Can't process response: #{e}"
|
121
149
|
[]
|
122
150
|
end
|
123
151
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Fulfil
|
2
|
+
class InteractiveReport
|
3
|
+
def initialize(client:, report:)
|
4
|
+
@client = client
|
5
|
+
@report = report
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute(start_date:, end_date:)
|
9
|
+
@client.interactive_report(
|
10
|
+
endpoint: report_url,
|
11
|
+
body: [{
|
12
|
+
start_date: serialize_date(start_date),
|
13
|
+
end_date: serialize_date(end_date)
|
14
|
+
}]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def report_url
|
21
|
+
"#{@report}/execute"
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize_date(date)
|
25
|
+
{
|
26
|
+
__class__: 'date',
|
27
|
+
year: date.year,
|
28
|
+
month: date.month,
|
29
|
+
day: date.day
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/fulfil/version.rb
CHANGED
data/lib/fulfil.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.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Moore
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-11-30 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
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- Rakefile
|
112
112
|
- lib/fulfil.rb
|
113
113
|
- lib/fulfil/client.rb
|
114
|
+
- lib/fulfil/interactive_report.rb
|
114
115
|
- lib/fulfil/model.rb
|
115
116
|
- lib/fulfil/query.rb
|
116
117
|
- lib/fulfil/response_parser.rb
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
- !ruby/object:Gem::Version
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
+
rubygems_version: 3.1.6
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: Interact with the Fulfil.io API
|