fulfil-io 0.4.5 → 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 +8 -0
- data/README.md +13 -0
- data/lib/fulfil/client.rb +19 -6
- data/lib/fulfil/interactive_report.rb +33 -0
- data/lib/fulfil/version.rb +1 -1
- data/lib/fulfil.rb +1 -0
- metadata +2 -1
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
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
@@ -11,8 +11,11 @@ module Fulfil
|
|
11
11
|
|
12
12
|
class Client
|
13
13
|
class NotAuthorizedError < StandardError; end
|
14
|
+
|
14
15
|
class UnknownHTTPError < StandardError; end
|
16
|
+
|
15
17
|
class ConnectionError < StandardError; end
|
18
|
+
|
16
19
|
class ResponseError < StandardError; end
|
17
20
|
|
18
21
|
def initialize(subdomain: SUBDOMAIN, token: OAUTH_TOKEN, headers: { 'X-API-KEY' => API_KEY }, debug: false)
|
@@ -71,7 +74,7 @@ module Fulfil
|
|
71
74
|
parse(results: results)
|
72
75
|
end
|
73
76
|
|
74
|
-
def put(model
|
77
|
+
def put(model: nil, id: nil, endpoint: nil, body: {})
|
75
78
|
uri = URI(model_url(model: model, id: id, endpoint: endpoint))
|
76
79
|
|
77
80
|
result = request(verb: :put, endpoint: uri, json: body)
|
@@ -85,6 +88,12 @@ module Fulfil
|
|
85
88
|
parse(result: result)
|
86
89
|
end
|
87
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
|
+
|
88
97
|
private
|
89
98
|
|
90
99
|
def parse(result: nil, results: [])
|
@@ -103,15 +112,19 @@ module Fulfil
|
|
103
112
|
results.map { |result| Fulfil::ResponseParser.parse(item: result) }
|
104
113
|
end
|
105
114
|
|
115
|
+
def domain
|
116
|
+
"https://#{@subdomain}.fulfil.io"
|
117
|
+
end
|
118
|
+
|
106
119
|
def base_url
|
107
|
-
|
120
|
+
[domain, 'api', 'v2'].join('/')
|
108
121
|
end
|
109
122
|
|
110
123
|
def model_url(model:, id: nil, endpoint: nil)
|
111
|
-
[base_url, model, id, endpoint].compact.join('/')
|
124
|
+
[base_url, 'model', model, id, endpoint].compact.join('/')
|
112
125
|
end
|
113
126
|
|
114
|
-
def request(verb: :get,
|
127
|
+
def request(endpoint:, verb: :get, **args)
|
115
128
|
response = client.request(verb, endpoint, args)
|
116
129
|
|
117
130
|
if response.status.ok? || response.status.created?
|
@@ -131,8 +144,8 @@ module Fulfil
|
|
131
144
|
rescue HTTP::ConnectionError => e
|
132
145
|
puts "Couldn't connect"
|
133
146
|
raise ConnectionError, "Can't connect to #{base_url}"
|
134
|
-
rescue HTTP::ResponseError =>
|
135
|
-
raise ResponseError, "Can't process response: #{
|
147
|
+
rescue HTTP::ResponseError => e
|
148
|
+
raise ResponseError, "Can't process response: #{e}"
|
136
149
|
[]
|
137
150
|
end
|
138
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
|
@@ -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
|