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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bd5c38b36abf80f522f33986103d5d2d94c2ba0
4
- data.tar.gz: 5f11c6edb651d08e49cbbf1e8bd2a89037cfd3e8
3
+ metadata.gz: 108342ffa36bdaa0249839395c81134746d41cbb
4
+ data.tar.gz: 65e2f9a55e7f6b8066164a9237d29a6b9a61fc96
5
5
  SHA512:
6
- metadata.gz: 8afbb75506aa39f78af563d6aa7b926f4fe9993554f9a79288d606af3bf11002423bc9bcfd1a66d633006ee37c8b69a3bb9987d1551d12b41f6c14941f7b77cc
7
- data.tar.gz: fda4d8271434e14c7502329f8b3448f95a570628fed0ac6afb8dd6b380927a95fc4a39b26a77d77ae8d95c33b01a32523af784798c5e37507c03ccc1d7daa04d
6
+ metadata.gz: cf0a58fe90751a1f8bb9a50a6ad226f0e0e5131812a7ee9dedc1222c4410aa5797ecf1ce2789c18087362f091180b736c19f0ba71c63873790afe5cc9e4af60b
7
+ data.tar.gz: 5330b361a1a03701db99f4a05be166544cd829348f42cea28af6c8e92cabb2f3b9b7307ce16f8234d3b8daa1d7af7d6870e55b2e0a0a080d9c83cac7599c07d9
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.2.2
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
@@ -6,5 +6,5 @@ gemspec
6
6
  group :test do
7
7
  gem 'byebug' if RUBY_VERSION.to_i >= 2
8
8
  gem 'vcr', '~> 2.4'
9
- gem 'webmock', '>= 1.20'
9
+ gem 'webmock', '1.22.3'
10
10
  end
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` and other readable `IO` objects will be base64-encoded internally before JSON-encoding payloads for `POST`, `PUT` and `PATCH` requests.
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.
@@ -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 :net_http_persistent
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] = case v
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
@@ -1,3 +1,3 @@
1
1
  module BooticClient
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  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.14
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-04-26 00:00:00.000000000 Z
11
+ date: 2016-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday