bootic_client 0.0.14 → 0.0.15
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/.travis.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +27 -1
- data/lib/bootic_client/client.rb +6 -6
- data/lib/bootic_client/version.rb +1 -1
- data/spec/client_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 108342ffa36bdaa0249839395c81134746d41cbb
|
4
|
+
data.tar.gz: 65e2f9a55e7f6b8066164a9237d29a6b9a61fc96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf0a58fe90751a1f8bb9a50a6ad226f0e0e5131812a7ee9dedc1222c4410aa5797ecf1ce2789c18087362f091180b736c19f0ba71c63873790afe5cc9e4af60b
|
7
|
+
data.tar.gz: 5330b361a1a03701db99f4a05be166544cd829348f42cea28af6c8e92cabb2f3b9b7307ce16f8234d3b8daa1d7af7d6870e55b2e0a0a080d9c83cac7599c07d9
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v0.0.14](https://github.com/bootic/bootic_client.rb/tree/v0.0.14) (2016-04-26)
|
4
|
+
[Full Changelog](https://github.com/bootic/bootic_client.rb/compare/v0.0.13...v0.0.14)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Base64-encode IO instances before POST|PUT|PATH [\#6](https://github.com/bootic/bootic_client.rb/pull/6) ([ismasan](https://github.com/ismasan))
|
9
|
+
|
3
10
|
## [v0.0.13](https://github.com/bootic/bootic_client.rb/tree/v0.0.13) (2016-01-12)
|
4
11
|
[Full Changelog](https://github.com/bootic/bootic_client.rb/compare/v0.0.12...v0.0.13)
|
5
12
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -167,7 +167,7 @@ end
|
|
167
167
|
|
168
168
|
### Working with Files and IO instances
|
169
169
|
|
170
|
-
Instances of `File
|
170
|
+
Instances of `File`, other readable `IO` objects (and in fact anything that responds to `#read`) will be base64-encoded internally before JSON-encoding payloads for `POST`, `PUT` and `PATCH` requests.
|
171
171
|
|
172
172
|
```ruby
|
173
173
|
asset = product.create_product_asset(
|
@@ -176,6 +176,32 @@ asset = product.create_product_asset(
|
|
176
176
|
)
|
177
177
|
```
|
178
178
|
|
179
|
+
Because anything that responds to `#read` will be interpreted as file data and base64-encoded, you can also pass instances of `open-uri`.
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
require "open-uri"
|
183
|
+
|
184
|
+
asset = product.create_product_asset(
|
185
|
+
filename: 'foo.jpg',
|
186
|
+
data: open("https://some.server.com/some/image.jpg") # this will base64-encode the file data in the `data` field.
|
187
|
+
)
|
188
|
+
```
|
189
|
+
|
190
|
+
.. or even your own readers
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
class MyReader
|
194
|
+
def read
|
195
|
+
"some data here"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
asset = product.create_product_asset(
|
200
|
+
filename: 'foo.jpg',
|
201
|
+
data: MyReader.new # this will base64-encode the file data in the `data` field.
|
202
|
+
)
|
203
|
+
```
|
204
|
+
|
179
205
|
## Relation docs
|
180
206
|
|
181
207
|
All resource link relations include a "docs" URL so you can learn more about that particular resource.
|
data/lib/bootic_client/client.rb
CHANGED
@@ -16,7 +16,8 @@ module BooticClient
|
|
16
16
|
|
17
17
|
def initialize(options = {}, &block)
|
18
18
|
@options = {
|
19
|
-
logging: false
|
19
|
+
logging: false,
|
20
|
+
faraday_adapter: [:net_http_persistent],
|
20
21
|
}.merge(options.dup)
|
21
22
|
|
22
23
|
@options[:cache_store] = @options[:cache_store] || Faraday::HttpCache::MemoryStore.new
|
@@ -69,7 +70,7 @@ module BooticClient
|
|
69
70
|
f.response :logger, options[:logger] if options[:logging]
|
70
71
|
f.response :json
|
71
72
|
yield f if block_given?
|
72
|
-
f.adapter :
|
73
|
+
f.adapter *Array(options[:faraday_adapter])
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
@@ -102,11 +103,10 @@ module BooticClient
|
|
102
103
|
def sanitized(payload)
|
103
104
|
return payload unless payload.kind_of?(Hash)
|
104
105
|
payload.each_with_object({}) do |(k, v), memo|
|
105
|
-
memo[k] =
|
106
|
-
when IO
|
107
|
-
Base64.encode64 v.read
|
108
|
-
when Hash
|
106
|
+
memo[k] = if v.kind_of?(Hash)
|
109
107
|
sanitized v
|
108
|
+
elsif v.respond_to?(:read)
|
109
|
+
Base64.encode64 v.read
|
110
110
|
else
|
111
111
|
v
|
112
112
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'json'
|
3
|
+
require "open-uri"
|
3
4
|
|
4
5
|
describe BooticClient::Client do
|
5
6
|
require 'webmock/rspec'
|
@@ -204,6 +205,16 @@ describe BooticClient::Client do
|
|
204
205
|
it 'POSTs request with base64-encoded file and parses response' do
|
205
206
|
expect(client.post(root_url, {foo: 'bar', data: file}, request_headers).body['message']).to eql('Hello!')
|
206
207
|
end
|
208
|
+
|
209
|
+
it "works with anything that responds to #read" do
|
210
|
+
reader = double("reader", read: File.read(fixture_path("file.gif")))
|
211
|
+
expect(client.post(root_url, {foo: 'bar', data: reader}, request_headers).body['message']).to eql('Hello!')
|
212
|
+
end
|
213
|
+
|
214
|
+
it "works with open-uri" do
|
215
|
+
reader = open(fixture_path("file.gif"))
|
216
|
+
expect(client.post(root_url, {foo: 'bar', data: reader}, request_headers).body['message']).to eql('Hello!')
|
217
|
+
end
|
207
218
|
end
|
208
219
|
|
209
220
|
[:put, :patch].each do |verb|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootic_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|