ink_file_picker 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +8 -4
- data/CHANGELOG.md +5 -1
- data/README.md +3 -3
- data/ink_file_picker.gemspec +2 -3
- data/lib/ink_file_picker.rb +8 -11
- data/lib/ink_file_picker/client.rb +12 -10
- data/lib/ink_file_picker/configuration.rb +1 -1
- data/lib/ink_file_picker/file_handle.rb +1 -1
- data/lib/ink_file_picker/policy.rb +5 -3
- data/lib/ink_file_picker/response.rb +7 -2
- data/lib/ink_file_picker/url_builder.rb +3 -1
- data/lib/ink_file_picker/utils.rb +22 -0
- data/lib/ink_file_picker/version.rb +1 -1
- data/spec/ink_file_picker/client_spec.rb +60 -32
- data/spec/ink_file_picker/configuration_spec.rb +4 -4
- data/spec/ink_file_picker/policy_spec.rb +19 -2
- data/spec/ink_file_picker_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +16 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4719c0f6e4a7133f778fbe0a526bfb789a4c1cde
|
4
|
+
data.tar.gz: b52840576ea9e984cc36b991e1cc91821d05765a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f586ec60871af2f0d1911680ac2f9435665a46c764dc9dedb36883bdd6d32fbcab8b74c9207a082cd3ef6d513d6963c0e0ad1680173dca16240bb3b769923bd7
|
7
|
+
data.tar.gz: c2341290c994729ceb7f26c9773b3fb88bdaf19b8e8fe3b63499ab8d042f88b186c8b63dfa642869a8e27ba5aaa4a2273707fb6e76a520bca4bd8c52cdeee95e
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.0.4
|
2
|
+
* Dropped ActiveSupport as a dependency. Should make life easier for everyone.
|
3
|
+
* Expiry on the policy can be given as an object acting as Time, as long as #to_i
|
4
|
+
returns Epoch time.
|
5
|
+
|
1
6
|
## 0.0.3
|
2
7
|
* Raise UnexpectedResponseError if we receive a 200 OK, but response body is neither "success", nor valid JSON.
|
3
8
|
This may happen if you ask File Picker to download a URL, but the server for the given URL fails to respond
|
@@ -5,7 +10,6 @@
|
|
5
10
|
the UnexpectedResponseError is raised. Other download errors may also be in the response, for instance
|
6
11
|
"Invalid response when trying to read from `http://some.url.com/here.jpg`.
|
7
12
|
|
8
|
-
|
9
13
|
## 0.0.2
|
10
14
|
* You can call to_hash on response objects.
|
11
15
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# InkFilePicker
|
2
2
|
|
3
|
-
Ruby API client for Ink File Picker
|
3
|
+
Ruby API client for filestack.com. Previously known as Ink File Picker and filepicker.io.
|
4
4
|
|
5
5
|
[![Build Status](https://travis-ci.org/Skalar/ink_file_picker.svg?branch=master)](https://travis-ci.org/Skalar/ink_file_picker)
|
6
6
|
|
@@ -49,12 +49,12 @@ response = client.remove url_or_handle_name
|
|
49
49
|
### Read operations
|
50
50
|
```ruby
|
51
51
|
url = client.convert_url url_or_handle_name, w: 100, h: 100
|
52
|
-
url = client.convert_url url_or_handle_name, {w: 100, h: 100}, expiry: 10.
|
52
|
+
url = client.convert_url url_or_handle_name, {w: 100, h: 100}, expiry: (Time.now + 60 * 10).to_i
|
53
53
|
|
54
54
|
# Adds policy and signature, if secret given when client was created.
|
55
55
|
get_params = {} # Get params we'll be adding to the request.
|
56
56
|
url = client.retrieve_url url_or_handle_name
|
57
|
-
url = client.retrieve_url url_or_handle_name, get_params, expiry: 10.
|
57
|
+
url = client.retrieve_url url_or_handle_name, get_params, expiry: (Time.now + 60 * 10).to_i
|
58
58
|
|
59
59
|
|
60
60
|
# Get simple stat on a file, like the Javascript client
|
data/ink_file_picker.gemspec
CHANGED
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activesupport", ">= 3.2.14", "< 5"
|
22
21
|
spec.add_dependency "faraday", "~> 0.9.0"
|
23
22
|
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.5"
|
25
23
|
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12.5"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
27
26
|
end
|
data/lib/ink_file_picker.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
1
|
require "ink_file_picker/version"
|
2
2
|
|
3
|
-
require "active_support/all"
|
4
3
|
require "ink_file_picker/errors"
|
4
|
+
require "ink_file_picker/assignable"
|
5
|
+
require "ink_file_picker/configuration"
|
6
|
+
require "ink_file_picker/file_handle"
|
7
|
+
require "ink_file_picker/url_builder"
|
8
|
+
require "ink_file_picker/response"
|
9
|
+
require "ink_file_picker/client"
|
10
|
+
require "ink_file_picker/policy"
|
11
|
+
require "ink_file_picker/utils"
|
5
12
|
|
6
13
|
module InkFilePicker
|
7
|
-
extend ActiveSupport::Autoload
|
8
|
-
|
9
|
-
autoload :Assignable
|
10
|
-
autoload :Configuration
|
11
|
-
autoload :FileHandle
|
12
|
-
autoload :UrlBuilder
|
13
|
-
autoload :Response
|
14
|
-
autoload :Client
|
15
|
-
autoload :Policy
|
16
|
-
|
17
14
|
# Public: Creates a new Ink File Picker Client.
|
18
15
|
#
|
19
16
|
# configuration - configuration for the client with an API key
|
@@ -12,7 +12,7 @@ module InkFilePicker
|
|
12
12
|
# Public: Store a file from given URL.
|
13
13
|
#
|
14
14
|
# url - URL to resource
|
15
|
-
# policy_attributes - If you use security policies you may send in for instance {
|
15
|
+
# policy_attributes - If you use security policies you may send in for instance {e: (Time.now + 60 * 10)} here
|
16
16
|
#
|
17
17
|
# Returns a hash representing the response where you can read for instance 'url'
|
18
18
|
def store_url(url, policy_attributes = {})
|
@@ -33,7 +33,7 @@ module InkFilePicker
|
|
33
33
|
# file_or_path - File or path to file
|
34
34
|
# content_type - The file's content type
|
35
35
|
# filename - The file's name, optional
|
36
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
36
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
37
37
|
#
|
38
38
|
# Returns a hash representing the response where you can read for instance 'url'
|
39
39
|
def store_file(file_or_path, content_type, filename = nil, policy_attributes = {})
|
@@ -53,7 +53,7 @@ module InkFilePicker
|
|
53
53
|
# Public: Removes a file from file picker.
|
54
54
|
#
|
55
55
|
# handle_or_url - The handle or URL to the file
|
56
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
56
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
57
57
|
#
|
58
58
|
# Returns boolean value
|
59
59
|
def remove(handle_or_url, policy_attributes = {})
|
@@ -67,7 +67,7 @@ module InkFilePicker
|
|
67
67
|
#
|
68
68
|
# handle_or_url - The handle or URL to the file
|
69
69
|
# params - Request params, like {width: true, height: true} to get width and height info. May be empty for default response
|
70
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
70
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
71
71
|
#
|
72
72
|
# Returns hash of headers returned from file picker or false if request was unsuccessful
|
73
73
|
def stat(handle_or_url, params = {}, policy_attributes = {})
|
@@ -79,7 +79,7 @@ module InkFilePicker
|
|
79
79
|
# Public: Generates a you can use for removing an asset on file picker.
|
80
80
|
#
|
81
81
|
# handle_or_url - The handle or URL to the file
|
82
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
82
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
83
83
|
#
|
84
84
|
# Returns a URL to the converted image
|
85
85
|
def remove_url(handle_or_url, policy_attributes = {})
|
@@ -90,7 +90,7 @@ module InkFilePicker
|
|
90
90
|
#
|
91
91
|
# handle_or_url - The handle or URL to the file
|
92
92
|
# params - Convert params, like {w: 100, h:100}
|
93
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
93
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
94
94
|
#
|
95
95
|
# Returns a URL to the converted image
|
96
96
|
def convert_url(handle_or_url, params = {}, policy_attributes = {})
|
@@ -102,7 +102,7 @@ module InkFilePicker
|
|
102
102
|
#
|
103
103
|
# handle_or_url - The handle or URL to the file
|
104
104
|
# params - Params to be added as get params, like {cache: true}
|
105
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
105
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
106
106
|
#
|
107
107
|
# This method is not that usefull unless you have enabled security policy
|
108
108
|
#
|
@@ -115,7 +115,7 @@ module InkFilePicker
|
|
115
115
|
# Public: Generates a stat URL for a given file
|
116
116
|
#
|
117
117
|
# handle_or_url - The handle or URL to the file
|
118
|
-
# policy_attributes - If you use security policies you may send in for instance {expire: 10
|
118
|
+
# policy_attributes - If you use security policies you may send in for instance {expire: (Time.now + 60 * 10)} here
|
119
119
|
#
|
120
120
|
# Returns a URL to the image you can do a HEAD request to in order to get stats
|
121
121
|
def stat_url(handle_or_url, params, policy_attributes = {})
|
@@ -130,10 +130,12 @@ module InkFilePicker
|
|
130
130
|
#
|
131
131
|
# Returns Policy object
|
132
132
|
def policy(attributes)
|
133
|
-
|
133
|
+
defaults = {
|
134
134
|
secret: configuration.secret,
|
135
135
|
expiry: Time.now.to_i + configuration.default_expiry
|
136
|
-
|
136
|
+
}.freeze
|
137
|
+
|
138
|
+
attributes = defaults.merge attributes
|
137
139
|
|
138
140
|
Policy.new attributes
|
139
141
|
end
|
@@ -13,7 +13,9 @@ module InkFilePicker
|
|
13
13
|
assign attributes
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def expiry=(epoch_or_time_object)
|
17
|
+
@expiry = epoch_or_time_object.to_i
|
18
|
+
end
|
17
19
|
|
18
20
|
def policy
|
19
21
|
Base64.urlsafe_encode64 policy_json
|
@@ -25,7 +27,7 @@ module InkFilePicker
|
|
25
27
|
|
26
28
|
|
27
29
|
def to_hash
|
28
|
-
return {} if
|
30
|
+
return {} if Utils::Blank.blank? secret
|
29
31
|
|
30
32
|
{
|
31
33
|
policy: policy,
|
@@ -39,7 +41,7 @@ module InkFilePicker
|
|
39
41
|
out = {}
|
40
42
|
|
41
43
|
POLICY_ATTRIBUTES.each do |attr_name|
|
42
|
-
if value = self[attr_name] and
|
44
|
+
if value = self[attr_name] and !Utils::Blank.blank?(value)
|
43
45
|
out[attr_name] = value
|
44
46
|
end
|
45
47
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
module InkFilePicker
|
2
5
|
# Public: Simple decorator class for response.
|
3
6
|
#
|
4
7
|
# Decorates the response with hash like access to the
|
5
8
|
# parsed body, which is expected to be JSON.
|
6
9
|
class Response
|
10
|
+
extend Forwardable
|
11
|
+
|
7
12
|
DELEGATE_TO_RESPONSE = %w[
|
8
13
|
success? status headers body finished?
|
9
14
|
]
|
@@ -14,8 +19,8 @@ module InkFilePicker
|
|
14
19
|
|
15
20
|
attr_reader :http_response
|
16
21
|
|
17
|
-
|
18
|
-
|
22
|
+
def_delegators :http_response, *DELEGATE_TO_RESPONSE
|
23
|
+
def_delegators :parsed_body, *DELEGATE_TO_PARSED_BODY
|
19
24
|
|
20
25
|
|
21
26
|
def initialize(http_response)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
1
3
|
module InkFilePicker
|
2
4
|
# Public: Takes a file url, adds action to the path (if any), and includes params.
|
3
5
|
class UrlBuilder
|
@@ -11,7 +13,7 @@ module InkFilePicker
|
|
11
13
|
|
12
14
|
def url
|
13
15
|
url = [file_url, action].compact.join '/'
|
14
|
-
url = [url, params
|
16
|
+
url = [url, URI.encode_www_form(params)].join '?' if params.any?
|
15
17
|
|
16
18
|
url
|
17
19
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module InkFilePicker
|
2
|
+
module Utils
|
3
|
+
module Blank
|
4
|
+
STRING_MATCHER = /\A[[:space:]]*\z/
|
5
|
+
|
6
|
+
def self.blank?(object)
|
7
|
+
case object
|
8
|
+
when String
|
9
|
+
STRING_MATCHER === object
|
10
|
+
when Hash, Array
|
11
|
+
object.empty?
|
12
|
+
when TrueClass, Numeric
|
13
|
+
false
|
14
|
+
when FalseClass, NilClass
|
15
|
+
true
|
16
|
+
else
|
17
|
+
object.respond_to?(:empty?) ? !!object.empty? : !self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
describe InkFilePicker::Client do
|
5
|
+
# Helper method, returns a hash represneting get query param
|
6
|
+
def query_to_hash(uri)
|
7
|
+
uri = URI.parse uri
|
8
|
+
Hash[uri.query.split('&').map { |name_value| name_value.split('=') }]
|
9
|
+
end
|
10
|
+
|
4
11
|
let(:attributes) do
|
5
12
|
{
|
6
13
|
key: 'key',
|
@@ -27,7 +34,7 @@ describe InkFilePicker::Client do
|
|
27
34
|
builder.adapter :test, stubs
|
28
35
|
end
|
29
36
|
|
30
|
-
subject.
|
37
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
31
38
|
|
32
39
|
response = subject.store_url url
|
33
40
|
|
@@ -49,7 +56,7 @@ describe InkFilePicker::Client do
|
|
49
56
|
builder.adapter :test, stubs
|
50
57
|
end
|
51
58
|
|
52
|
-
subject.
|
59
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
53
60
|
|
54
61
|
response = subject.store_url url, expiry: 1394363896
|
55
62
|
|
@@ -67,7 +74,7 @@ describe InkFilePicker::Client do
|
|
67
74
|
builder.adapter :test, stubs
|
68
75
|
end
|
69
76
|
|
70
|
-
subject.
|
77
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
71
78
|
|
72
79
|
expect { subject.store_url url, expiry: 1394363896 }.to raise_error InkFilePicker::ClientError
|
73
80
|
end
|
@@ -84,7 +91,7 @@ describe InkFilePicker::Client do
|
|
84
91
|
builder.adapter :test, stubs
|
85
92
|
end
|
86
93
|
|
87
|
-
subject.
|
94
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
88
95
|
|
89
96
|
expect { subject.store_url url, expiry: 1394363896 }.to raise_error InkFilePicker::UnexpectedResponseError
|
90
97
|
end
|
@@ -99,7 +106,7 @@ describe InkFilePicker::Client do
|
|
99
106
|
builder.adapter :test, stubs
|
100
107
|
end
|
101
108
|
|
102
|
-
subject.
|
109
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
103
110
|
|
104
111
|
expect { subject.store_url url, expiry: 1394363896 }.to raise_error InkFilePicker::ServerError
|
105
112
|
end
|
@@ -124,8 +131,8 @@ describe InkFilePicker::Client do
|
|
124
131
|
builder.adapter :test, stubs
|
125
132
|
end
|
126
133
|
|
127
|
-
subject.
|
128
|
-
Faraday::UploadIO.
|
134
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
135
|
+
allow(Faraday::UploadIO).to receive(:new).and_return file_upload # Need same object, so request equals the stub
|
129
136
|
|
130
137
|
response = subject.store_file file, 'image/png'
|
131
138
|
|
@@ -142,8 +149,8 @@ describe InkFilePicker::Client do
|
|
142
149
|
builder.adapter :test, stubs
|
143
150
|
end
|
144
151
|
|
145
|
-
subject.
|
146
|
-
Faraday::UploadIO.
|
152
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
153
|
+
allow(Faraday::UploadIO).to receive(:new).and_return file_upload # Need same object, so request equals the stub
|
147
154
|
|
148
155
|
response = subject.store_file path, 'image/png'
|
149
156
|
|
@@ -162,8 +169,8 @@ describe InkFilePicker::Client do
|
|
162
169
|
builder.adapter :test, stubs
|
163
170
|
end
|
164
171
|
|
165
|
-
subject.
|
166
|
-
Faraday::UploadIO.
|
172
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
173
|
+
allow(Faraday::UploadIO).to receive(:new).and_return file_upload # Need same object, so request equals the stub
|
167
174
|
|
168
175
|
response = subject.store_file file, 'image/png', nil, expiry: 1394363896
|
169
176
|
|
@@ -181,7 +188,7 @@ describe InkFilePicker::Client do
|
|
181
188
|
builder.adapter :test, stubs
|
182
189
|
end
|
183
190
|
|
184
|
-
subject.
|
191
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
185
192
|
|
186
193
|
expect { subject.store_file file, 'image/png', nil, expiry: 1394363896 }.to raise_error InkFilePicker::ClientError
|
187
194
|
end
|
@@ -196,7 +203,7 @@ describe InkFilePicker::Client do
|
|
196
203
|
builder.adapter :test, stubs
|
197
204
|
end
|
198
205
|
|
199
|
-
subject.
|
206
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
200
207
|
|
201
208
|
expect { subject.store_file file, 'image/png', nil, expiry: 1394363896 }.to raise_error InkFilePicker::ServerError
|
202
209
|
end
|
@@ -218,12 +225,12 @@ describe InkFilePicker::Client do
|
|
218
225
|
builder.adapter :test, stubs
|
219
226
|
end
|
220
227
|
|
221
|
-
subject.
|
228
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
222
229
|
|
223
230
|
response = subject.remove file_url
|
224
231
|
|
225
232
|
stubs.verify_stubbed_calls
|
226
|
-
expect(response).to
|
233
|
+
expect(response).to be_truthy
|
227
234
|
end
|
228
235
|
|
229
236
|
it "makes delete request with file handle name" do
|
@@ -235,12 +242,12 @@ describe InkFilePicker::Client do
|
|
235
242
|
builder.adapter :test, stubs
|
236
243
|
end
|
237
244
|
|
238
|
-
subject.
|
245
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
239
246
|
|
240
247
|
response = subject.remove 'WmFxB2aSe20SGT2kzSsr'
|
241
248
|
|
242
249
|
stubs.verify_stubbed_calls
|
243
|
-
expect(response).to
|
250
|
+
expect(response).to be_truthy
|
244
251
|
end
|
245
252
|
|
246
253
|
it "handles server errors correctly" do
|
@@ -252,7 +259,7 @@ describe InkFilePicker::Client do
|
|
252
259
|
builder.adapter :test, stubs
|
253
260
|
end
|
254
261
|
|
255
|
-
subject.
|
262
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
256
263
|
|
257
264
|
expect { subject.remove 'WmFxB2aSe20SGT2kzSsr' }.to raise_error InkFilePicker::ServerError
|
258
265
|
end
|
@@ -268,12 +275,12 @@ describe InkFilePicker::Client do
|
|
268
275
|
builder.adapter :test, stubs
|
269
276
|
end
|
270
277
|
|
271
|
-
subject.
|
278
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
272
279
|
|
273
280
|
response = subject.remove file_url, expiry: 1394363896
|
274
281
|
|
275
282
|
stubs.verify_stubbed_calls
|
276
|
-
expect(response).to
|
283
|
+
expect(response).to be_truthy
|
277
284
|
end
|
278
285
|
end
|
279
286
|
end
|
@@ -282,15 +289,15 @@ describe InkFilePicker::Client do
|
|
282
289
|
let(:file_url) { 'https://www.filepicker.io/api/file/WmFxB2aSe20SGT2kzSsr' }
|
283
290
|
|
284
291
|
it "handles server errors correctly" do
|
285
|
-
stubs = Faraday::Adapter::Test::Stubs.new do |
|
286
|
-
|
292
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |receive|
|
293
|
+
receive.get(file_url + '/metadata') { [502, {}, 'Bad Gateway'] }
|
287
294
|
end
|
288
295
|
|
289
296
|
stubbed_connection = Faraday.new do |builder|
|
290
297
|
builder.adapter :test, stubs
|
291
298
|
end
|
292
299
|
|
293
|
-
subject.
|
300
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
294
301
|
|
295
302
|
expect { subject.stat 'WmFxB2aSe20SGT2kzSsr' }.to raise_error InkFilePicker::ServerError
|
296
303
|
end
|
@@ -307,7 +314,7 @@ describe InkFilePicker::Client do
|
|
307
314
|
builder.adapter :test, stubs
|
308
315
|
end
|
309
316
|
|
310
|
-
subject.
|
317
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
311
318
|
|
312
319
|
response = subject.stat file_url, {}, expiry: 1394363896
|
313
320
|
|
@@ -326,7 +333,7 @@ describe InkFilePicker::Client do
|
|
326
333
|
builder.adapter :test, stubs
|
327
334
|
end
|
328
335
|
|
329
|
-
subject.
|
336
|
+
allow(subject).to receive(:http_connection).and_return stubbed_connection
|
330
337
|
|
331
338
|
response = subject.stat file_url, {width: true, heigth: true}, expiry: 1394363896
|
332
339
|
|
@@ -344,17 +351,37 @@ describe InkFilePicker::Client do
|
|
344
351
|
before { subject.configuration.secret = nil }
|
345
352
|
|
346
353
|
it "builds expected convert URL when given a URL" do
|
347
|
-
|
354
|
+
converted_url = subject.convert_url url, w: 300, h: 200
|
355
|
+
|
356
|
+
expect(converted_url).to start_with 'https://www.filepicker.io/api/file/PHqJHHWpRAGUsIfyx0og/convert?'
|
357
|
+
expect(query_to_hash converted_url).to include({
|
358
|
+
"h" => "200",
|
359
|
+
"w" => "300"
|
360
|
+
})
|
348
361
|
end
|
349
362
|
|
350
363
|
it "builds expected convert URL when given a handle" do
|
351
|
-
|
364
|
+
converted_url = subject.convert_url handle, w: 300, h: 200
|
365
|
+
|
366
|
+
expect(converted_url).to start_with 'https://www.filepicker.io/api/file/PHqJHHWpRAGUsIfyx0og/convert?'
|
367
|
+
expect(query_to_hash converted_url).to include({
|
368
|
+
"h" => "200",
|
369
|
+
"w" => "300"
|
370
|
+
})
|
352
371
|
end
|
353
372
|
end
|
354
373
|
|
355
374
|
context "with secret" do
|
356
375
|
it "builds expected convert URL when given a URL" do
|
357
|
-
|
376
|
+
converted_url = subject.convert_url url, {w: 300, h: 200}, expiry: 1394363896
|
377
|
+
|
378
|
+
expect(converted_url).to start_with 'https://www.filepicker.io/api/file/PHqJHHWpRAGUsIfyx0og/convert?'
|
379
|
+
expect(query_to_hash converted_url).to include({
|
380
|
+
"h" => "200",
|
381
|
+
"w" => "300",
|
382
|
+
"policy" => "eyJleHBpcnkiOjEzOTQzNjM4OTYsImNhbGwiOiJjb252ZXJ0IiwiaGFuZGxlIjoiUEhxSkhIV3BSQUdVc0lmeXgwb2cifQ%3D%3D",
|
383
|
+
"signature" => "b370d4ae604c7917c169fe5b10a6274683bb82056c7b80993a7601d486b89d22"
|
384
|
+
})
|
358
385
|
end
|
359
386
|
end
|
360
387
|
end
|
@@ -405,19 +432,20 @@ describe InkFilePicker::Client do
|
|
405
432
|
describe "expiry" do
|
406
433
|
context "is given" do
|
407
434
|
it "uses given value" do
|
408
|
-
InkFilePicker::Policy.
|
435
|
+
expect(InkFilePicker::Policy).to receive(:new).with(hash_including(call: 'read', expiry: 60)).and_return policy
|
409
436
|
|
410
437
|
expect(subject.policy policy_attributes.merge(expiry: 60)).to eq policy
|
411
438
|
end
|
412
439
|
end
|
413
440
|
|
414
441
|
context "not given" do
|
415
|
-
|
442
|
+
let(:the_time) { double :time, to_i: 1 }
|
443
|
+
before { allow(Time).to receive(:now).and_return the_time }
|
416
444
|
|
417
445
|
it "uses default_expiry from config" do
|
418
|
-
subject.configuration.
|
446
|
+
allow(subject.configuration).to receive(:default_expiry).and_return 600
|
419
447
|
|
420
|
-
InkFilePicker::Policy.
|
448
|
+
expect(InkFilePicker::Policy).to receive(:new).with(hash_including(call: 'read', expiry: 601)).and_return policy
|
421
449
|
|
422
450
|
expect(subject.policy policy_attributes).to eq policy
|
423
451
|
end
|
@@ -10,10 +10,10 @@ describe InkFilePicker::Configuration do
|
|
10
10
|
|
11
11
|
subject { described_class.new attributes }
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it { expect(subject.key).to eq 'key' }
|
14
|
+
it { expect(subject.secret).to eq 'secret' }
|
15
|
+
it { expect(subject.default_expiry).to eq 600 }
|
16
|
+
it { expect(subject.cdn_url).to eq 'https://www.filepicker.io/api/file/' }
|
17
17
|
|
18
18
|
describe "#initialize" do
|
19
19
|
it "fails when no key is given" do
|
@@ -11,8 +11,25 @@ describe InkFilePicker::Policy do
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
it { expect(subject.policy).to eq 'eyJleHBpcnkiOjEzOTQzNjM4OTYsImNhbGwiOiJyZWFkIn0=' }
|
15
|
+
it { expect(subject.signature).to eq '4c50ca71d9e123274a01eb00a7facd52069e07c2e9312517f55bf1b94447792e' }
|
16
|
+
|
17
|
+
describe "the policy" do
|
18
|
+
let(:decoded) do
|
19
|
+
JSON.parse Base64.urlsafe_decode64 subject.policy
|
20
|
+
end
|
21
|
+
|
22
|
+
it { expect(decoded['call']).to eq 'read' }
|
23
|
+
it { expect(decoded['expiry']).to eq 1394363896 }
|
24
|
+
|
25
|
+
it "ensures expiry is a number" do
|
26
|
+
time = Time.parse('2016-01-01 00:00:00 +0100')
|
27
|
+
subject.expiry = time
|
28
|
+
|
29
|
+
decoded = JSON.parse Base64.urlsafe_decode64 subject.policy
|
30
|
+
expect(decoded['expiry']).to eq 1451602800
|
31
|
+
end
|
32
|
+
end
|
16
33
|
|
17
34
|
describe "#to_hash" do
|
18
35
|
it "contains policy and signature when secret is given" do
|
@@ -6,7 +6,7 @@ describe InkFilePicker do
|
|
6
6
|
client = double
|
7
7
|
attributes = {some: 'attributes'}
|
8
8
|
|
9
|
-
InkFilePicker::Client.
|
9
|
+
expect(InkFilePicker::Client).to receive(:new).with(attributes).and_return client
|
10
10
|
|
11
11
|
expect(described_class.client(attributes)).to eq client
|
12
12
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ink_file_picker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorbjørn Hermansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2.14
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '5'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 3.2.14
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '5'
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: faraday
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,47 +25,47 @@ dependencies:
|
|
45
25
|
- !ruby/object:Gem::Version
|
46
26
|
version: 0.9.0
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
28
|
+
name: rake
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
50
30
|
requirements:
|
51
|
-
- - "
|
31
|
+
- - ">="
|
52
32
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
33
|
+
version: '0'
|
54
34
|
type: :development
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
37
|
requirements:
|
58
|
-
- - "
|
38
|
+
- - ">="
|
59
39
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
40
|
+
version: '0'
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
42
|
+
name: bundler
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
64
44
|
requirements:
|
65
|
-
- - "
|
45
|
+
- - "~>"
|
66
46
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
47
|
+
version: 1.12.5
|
68
48
|
type: :development
|
69
49
|
prerelease: false
|
70
50
|
version_requirements: !ruby/object:Gem::Requirement
|
71
51
|
requirements:
|
72
|
-
- - "
|
52
|
+
- - "~>"
|
73
53
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
54
|
+
version: 1.12.5
|
75
55
|
- !ruby/object:Gem::Dependency
|
76
56
|
name: rspec
|
77
57
|
requirement: !ruby/object:Gem::Requirement
|
78
58
|
requirements:
|
79
59
|
- - "~>"
|
80
60
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
61
|
+
version: 3.5.0
|
82
62
|
type: :development
|
83
63
|
prerelease: false
|
84
64
|
version_requirements: !ruby/object:Gem::Requirement
|
85
65
|
requirements:
|
86
66
|
- - "~>"
|
87
67
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
68
|
+
version: 3.5.0
|
89
69
|
description:
|
90
70
|
email:
|
91
71
|
- thhermansen@gmail.com
|
@@ -94,6 +74,7 @@ extensions: []
|
|
94
74
|
extra_rdoc_files: []
|
95
75
|
files:
|
96
76
|
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
97
78
|
- ".travis.yml"
|
98
79
|
- CHANGELOG.md
|
99
80
|
- Gemfile
|
@@ -110,6 +91,7 @@ files:
|
|
110
91
|
- lib/ink_file_picker/policy.rb
|
111
92
|
- lib/ink_file_picker/response.rb
|
112
93
|
- lib/ink_file_picker/url_builder.rb
|
94
|
+
- lib/ink_file_picker/utils.rb
|
113
95
|
- lib/ink_file_picker/version.rb
|
114
96
|
- spec/fixtures/skalar.png
|
115
97
|
- spec/ink_file_picker/client_spec.rb
|