fulfil-io 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +35 -3
- data/lib/fulfil/client.rb +39 -7
- data/lib/fulfil/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22ec67bfb2b90dbcdb4eef09efa189b25f11aada22ff2fa66d115b1c9cb26e06
|
4
|
+
data.tar.gz: 48675559980e3ae07eb4a10938cfec33df858c82126faf2152a7a6c069cf3a79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ac80544c088e239f250f937c5b5f20c95ac818bbe394f3e55b4c32d9800301f534bb3a922885c55ba870bb10f5448612a0cc181c6cbef9e4cd91dfa035d4c7
|
7
|
+
data.tar.gz: fbfb4ba1116956cdf9d3d2f2234fe53067ad31b9ffb87c36b62d01e1c3e1c31c84d7abfcbe29222b3aca58e097017bfd303f3903c1fc553d932ac55c44d64c1c
|
data/CHANGELOG.md
CHANGED
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,38 @@ pp sales
|
|
68
68
|
# "rec_name"=>""}]
|
69
69
|
```
|
70
70
|
|
71
|
+
### Writing
|
72
|
+
|
73
|
+
As of v0.3.0, we've added very basic support for creates and updates via
|
74
|
+
`Fulfil::Client#post` and `Fulfil::Client#put`.
|
75
|
+
|
76
|
+
*Create Example*
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
fulfil = Fulfil::Client.new
|
80
|
+
|
81
|
+
sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
|
82
|
+
|
83
|
+
sale = {
|
84
|
+
# Full Sale attributes here
|
85
|
+
}
|
86
|
+
|
87
|
+
fulfil.post(model: sale_model, body: sale)
|
88
|
+
```
|
89
|
+
|
90
|
+
*Update Example*
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
fulfil = Fulfil::Client.new
|
94
|
+
|
95
|
+
sale_model = Fulfil::Model.new(client: fulfil, model_name: 'sale.sale')
|
96
|
+
sale = sale_model.find(id: 1234)
|
97
|
+
|
98
|
+
sale['channel'] = 4
|
99
|
+
|
100
|
+
fulfil.put(model: sale_model, body: sale)
|
101
|
+
```
|
102
|
+
|
71
103
|
## Development
|
72
104
|
|
73
105
|
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'
|
@@ -50,9 +52,35 @@ module Fulfil
|
|
50
52
|
parse(results: results)
|
51
53
|
end
|
52
54
|
|
55
|
+
def post(model:, body: {})
|
56
|
+
uri = URI(model_url(model: model))
|
57
|
+
|
58
|
+
results = request(verb: :post, endpoint: uri, json: body)
|
59
|
+
parse(results: results)
|
60
|
+
end
|
61
|
+
|
62
|
+
def put(model:, id:, endpoint: nil, body: {})
|
63
|
+
uri = URI(model_url(model: model, id: id, endpoint: endpoint))
|
64
|
+
|
65
|
+
result = request(verb: :put, endpoint: uri, json: body)
|
66
|
+
parse(result: result)
|
67
|
+
end
|
68
|
+
|
53
69
|
private
|
54
70
|
|
55
71
|
def parse(result: nil, results: [])
|
72
|
+
if result.present?
|
73
|
+
parse_single(result: result)
|
74
|
+
else
|
75
|
+
parse_multiple(results: results)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def parse_single(result:)
|
80
|
+
Fulfil::ResponseParser.parse(item: result)
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_multiple(results:)
|
56
84
|
results.map { |result| Fulfil::ResponseParser.parse(item: result) }
|
57
85
|
end
|
58
86
|
|
@@ -60,26 +88,30 @@ module Fulfil
|
|
60
88
|
"https://#{@subdomain}.fulfil.io/api/v2/model"
|
61
89
|
end
|
62
90
|
|
63
|
-
def model_url(model:)
|
64
|
-
[base_url, model].join('/')
|
91
|
+
def model_url(model:, id: nil, endpoint: nil)
|
92
|
+
[base_url, model, id, endpoint].compact.join('/')
|
65
93
|
end
|
66
94
|
|
67
95
|
def request(verb: :get, endpoint:, **args)
|
68
96
|
response = client.request(verb, endpoint, args)
|
69
97
|
|
70
|
-
if response.status.ok?
|
98
|
+
if response.status.ok? || response.status.created?
|
71
99
|
response.parse
|
72
100
|
elsif response.code == 401
|
73
|
-
raise StandardError,
|
101
|
+
raise StandardError, 'Not authorized'
|
74
102
|
else
|
75
|
-
|
76
|
-
raise
|
103
|
+
puts response.body.to_s
|
104
|
+
raise Error, 'Error encountered while processing response:'
|
77
105
|
end
|
78
|
-
rescue HTTP::
|
106
|
+
rescue HTTP::Error => e
|
107
|
+
puts e
|
108
|
+
raise Error, 'Unhandled HTTP error encountered'
|
109
|
+
rescue HTTP::ConnectionError => e
|
79
110
|
puts "Couldn't connect"
|
80
111
|
raise Error, "Can't connect to #{base_url}"
|
81
112
|
rescue HTTP::ResponseError => ex
|
82
113
|
raise Error, "Can't process response: #{ex}"
|
114
|
+
[]
|
83
115
|
end
|
84
116
|
|
85
117
|
def client
|
data/lib/fulfil/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulfil-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2020-
|
12
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -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
|
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
137
|
rubygems_version: 3.0.3
|
138
|
-
signing_key:
|
138
|
+
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Interact with the Fulfil.io API
|
141
141
|
test_files: []
|