uploadcare-ruby 2.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +2 -2
- data/CHANGELOG.md +41 -10
- data/LICENSE +1 -1
- data/README.md +10 -1
- data/Rakefile +2 -0
- data/lib/uploadcare.rb +3 -2
- data/lib/uploadcare/rest/connections/api_connection.rb +1 -2
- data/lib/uploadcare/rest/connections/upload_connection.rb +1 -1
- data/lib/uploadcare/utils/user_agent.rb +44 -0
- data/lib/uploadcare/version.rb +1 -1
- data/spec/resources/file_spec.rb +81 -83
- data/spec/resources/group_spec.rb +2 -2
- data/spec/rest/api_connection_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/uploadcare_spec.rb +8 -12
- data/spec/utils/user_agent_spec.rb +46 -0
- data/uploadcare-ruby.gemspec +15 -15
- metadata +43 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a91d6bc58cb4485cc93ff080fa5f66040b6ab0f0
|
4
|
+
data.tar.gz: ae95eb7e6d60828a91883c1c481e7a469d49702a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3b503ac19459939ec38af251f322c3804dec77546deeeba3d192757927a2cf4eef04d4f2b2ac2265efc42e42233f54d0f2fe66d2dcd29ced6ab18c65f6432c8
|
7
|
+
data.tar.gz: c08f3fb47d507b520c0859ee268ce8926b014fa7895b3a288f881586e857724a825f075899827f07a02c33228c790a26848728294cd5b8add0e323c14c49502f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,23 +1,54 @@
|
|
1
1
|
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
2
3
|
|
3
|
-
|
4
|
+
The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
## [Unreleased] - FIXME
|
8
|
+
|
9
|
+
|
10
|
+
## [2.1.1] - 2018-05-24
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- Allow user to override User-Agent header
|
14
|
+
- User-Agent format reports gem name, version and environment
|
15
|
+
|
16
|
+
## 2.1.0 - 2018-04-23 [YANKED]
|
17
|
+
|
18
|
+
## 2.0.0 - 2017-09-26
|
19
|
+
|
20
|
+
There are **breaking** changes in this release, please read [upgrade notes](UPGRADE_NOTES.md#v1---v2)
|
21
|
+
|
22
|
+
### Added
|
23
|
+
- Support for `store` flag in [Upload API](https://uploadcare.com/documentation/upload/) methods
|
24
|
+
- Methods to store/delete multiple files at once: `Uploadcare::Api#store_files` & `Uploadcare::Api#delete_files`
|
25
|
+
|
26
|
+
### Changed
|
7
27
|
- Upgraded to REST API v0.5
|
8
28
|
- All POST/PUT/DELETE params are now being sent as JSON instead of being form-encoded
|
9
|
-
-
|
10
|
-
- Changed pagination implementation for files and groups
|
29
|
+
- Pagination implementation for files and groups
|
11
30
|
|
12
|
-
|
31
|
+
## 1.1.0 - 2017-03-21
|
13
32
|
|
14
|
-
|
33
|
+
### Added
|
15
34
|
- Added to new methods to `Uploadcare::Api::File`, `#internal_copy` and `#external_copy`.
|
16
35
|
- Added support of [secure authorization](https://uploadcare.com/documentation/rest/#request) for REST API. It is now used by default (can be overriden in config)
|
36
|
+
|
37
|
+
### Fixed
|
17
38
|
- Fixed middleware names that could break other gems ([#13](https://github.com/uploadcare/uploadcare-ruby/issues/13)).
|
18
39
|
|
40
|
+
### Deprecated
|
41
|
+
- `Uploadcare::Api::File#copy` in favor of `#internal_copy` and `#external_copy`.
|
42
|
+
|
43
|
+
|
44
|
+
## 1.0.6, 2017-01-30
|
45
|
+
|
46
|
+
### Added
|
47
|
+
- Ruby version and public API key sent via User-Agent header (can be overriden in config)
|
48
|
+
|
49
|
+
### Fixed
|
50
|
+
- Incorrect dependencies
|
19
51
|
|
20
|
-
### 1.0.6, 30.01.2017
|
21
52
|
|
22
|
-
-
|
23
|
-
-
|
53
|
+
[Unreleased]: https://github.com/uploadcare/uploadcare-ruby/compare/v2.1.1...HEAD
|
54
|
+
[2.1.1]: https://github.com/uploadcare/uploadcare-ruby/compare/v2.0.0...v2.1.1
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
[![Build Status]
|
1
|
+
[![Build Status][travis-img]][travis]
|
2
|
+
[![Coverage Status][coverals-img]][coverals]
|
3
|
+
[![Uploadcare stack on StackShare][stack-img]][stack]
|
4
|
+
|
5
|
+
[travis-img]: https://secure.travis-ci.org/uploadcare/uploadcare-ruby.png?branch=master
|
6
|
+
[travis]: http://travis-ci.org/uploadcare/uploadcare-ruby
|
7
|
+
[coverals-img]: https://coveralls.io/repos/github/uploadcare/uploadcare-ruby/badge.svg?branch=master
|
8
|
+
[coverals]: https://coveralls.io/github/uploadcare/uploadcare-ruby?branch=master
|
9
|
+
[stack-img]: https://img.shields.io/badge/tech-stack-0690fa.svg?style=flat
|
10
|
+
[stack]: https://stackshare.io/uploadcare/stacks/
|
2
11
|
|
3
12
|
A [Ruby](https://www.ruby-lang.org/en/) wrapper for [Uploadcare](https://uploadcare.com).
|
4
13
|
|
data/Rakefile
CHANGED
data/lib/uploadcare.rb
CHANGED
@@ -18,6 +18,7 @@ module Uploadcare
|
|
18
18
|
auth_scheme: :secure,
|
19
19
|
}
|
20
20
|
|
21
|
+
warn '[DEPRECATION] `Uploadcare::USER_AGENT` constant is deprecated and will be removed in version 3.0'
|
21
22
|
USER_AGENT = "uploadcare-ruby/#{Gem.ruby_version}/#{Uploadcare::VERSION}"
|
22
23
|
|
23
24
|
def self.default_settings
|
@@ -25,7 +26,7 @@ module Uploadcare
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.user_agent(options={})
|
28
|
-
|
29
|
-
|
29
|
+
warn '[DEPRECATION] `Uploadcare::user_agent` method is deprecated and will be removed in version 3.0'
|
30
|
+
UserAgent.new.call(options)
|
30
31
|
end
|
31
32
|
end
|
@@ -10,7 +10,7 @@ module Uploadcare
|
|
10
10
|
auth_strategy = Auth.strategy(options)
|
11
11
|
|
12
12
|
frd.headers['Accept'] = "application/vnd.uploadcare-v#{options[:api_version]}+json"
|
13
|
-
frd.headers['User-Agent'] =
|
13
|
+
frd.headers['User-Agent'] = UserAgent.new.call(options)
|
14
14
|
|
15
15
|
# order of middleware matters!
|
16
16
|
|
@@ -48,7 +48,6 @@ module Uploadcare
|
|
48
48
|
yield(request) if block_given?
|
49
49
|
}
|
50
50
|
end
|
51
|
-
|
52
51
|
end
|
53
52
|
end
|
54
53
|
end
|
@@ -9,7 +9,7 @@ module Uploadcare
|
|
9
9
|
super ssl: { ca_path: ca_path }, url: options[:upload_url_base] do |frd|
|
10
10
|
frd.request :multipart
|
11
11
|
frd.request :url_encoded
|
12
|
-
frd.headers['User-Agent'] =
|
12
|
+
frd.headers['User-Agent'] = UserAgent.new.call(options)
|
13
13
|
|
14
14
|
frd.response :uploadcare_raise_error
|
15
15
|
frd.response :uploadcare_parse_json
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Uploadcare
|
2
|
+
# Determines User-Agent string either taking it from settings or building
|
3
|
+
# in accordance with common Uploadcare format
|
4
|
+
#
|
5
|
+
class UserAgent
|
6
|
+
# @param options [Hash]
|
7
|
+
# @option options [String] :user_agent (nil)
|
8
|
+
# @option options [String] :public_key (nil)
|
9
|
+
# @option options [String] :user_agent_environment (nil)
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
def call(options)
|
13
|
+
return options[:user_agent].to_s if options[:user_agent]
|
14
|
+
|
15
|
+
user_agent_string(
|
16
|
+
options.fetch(:public_key, nil),
|
17
|
+
options.fetch(:user_agent_environment, {})
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def user_agent_string(public_key, extensions)
|
24
|
+
format(
|
25
|
+
'%<library>s/%<pubkey>s (%<environment>s)',
|
26
|
+
library: versioned('UploadcareRuby', Uploadcare::VERSION),
|
27
|
+
pubkey: public_key,
|
28
|
+
environment: environment_string(extensions)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def environment_string(extensions)
|
33
|
+
[
|
34
|
+
versioned('Ruby', Gem.ruby_version),
|
35
|
+
versioned(extensions[:framework_name], extensions[:framework_version]),
|
36
|
+
versioned(extensions[:extension_name], extensions[:extension_version])
|
37
|
+
].compact.join('; ')
|
38
|
+
end
|
39
|
+
|
40
|
+
def versioned(name, version = nil)
|
41
|
+
name ? [name, version].compact.join('/') : nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/uploadcare/version.rb
CHANGED
data/spec/resources/file_spec.rb
CHANGED
@@ -4,135 +4,133 @@ require 'socket'
|
|
4
4
|
require 'securerandom'
|
5
5
|
|
6
6
|
describe Uploadcare::Api::File do
|
7
|
-
|
8
|
-
|
9
|
-
@file = @api.upload IMAGE_URL
|
10
|
-
end
|
7
|
+
let(:api) { API }
|
8
|
+
let(:file) { api.upload IMAGE_URL }
|
11
9
|
|
12
|
-
it '
|
13
|
-
|
10
|
+
it 'is an instance of File' do
|
11
|
+
expect(file).to be_an_instance_of Uploadcare::Api::File
|
14
12
|
end
|
15
13
|
|
16
|
-
it '
|
17
|
-
expect {Uploadcare::Api::File.new(
|
14
|
+
it 'is not initialized without correct UUID given' do
|
15
|
+
expect {Uploadcare::Api::File.new(api, "not-uuid")}.to raise_error NoMethodError
|
18
16
|
end
|
19
17
|
|
20
|
-
it '
|
21
|
-
|
18
|
+
it 'has a valid url' do
|
19
|
+
expect(file.uuid).to match UUID_REGEX
|
22
20
|
end
|
23
21
|
|
24
|
-
it '
|
25
|
-
|
26
|
-
|
22
|
+
it 'returns a public url' do
|
23
|
+
expect(file).to respond_to :cdn_url
|
24
|
+
expect(file).to respond_to :public_url
|
27
25
|
end
|
28
26
|
|
29
|
-
it 'public url
|
30
|
-
url =
|
27
|
+
it 'has a public url that is valid' do
|
28
|
+
url = file.cdn_url
|
31
29
|
uri = URI.parse(url)
|
32
|
-
uri.
|
30
|
+
expect(uri).to be_kind_of(URI::HTTP)
|
33
31
|
end
|
34
32
|
|
35
|
-
it '
|
36
|
-
expect {
|
33
|
+
it 'is able to load image data' do
|
34
|
+
expect {file.load_data}.to_not raise_error
|
37
35
|
end
|
38
36
|
|
39
|
-
it '
|
40
|
-
expect {
|
37
|
+
it 'stores itself' do
|
38
|
+
expect { file.store }.to_not raise_error
|
41
39
|
end
|
42
40
|
|
43
|
-
it '
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
it 'responds with nil for :stored? and :deleted? methods unless loaded' do
|
42
|
+
expect(file.is_loaded?).to be false
|
43
|
+
expect(file.is_stored?).to be_nil
|
44
|
+
expect(file.is_deleted?).to be_nil
|
47
45
|
end
|
48
46
|
|
49
|
-
it '
|
50
|
-
|
51
|
-
expect(
|
52
|
-
wait_until_ready(
|
53
|
-
|
54
|
-
expect(
|
47
|
+
it 'is able to tell thenever file was stored' do
|
48
|
+
file.load
|
49
|
+
expect(file.stored?).to be(true)
|
50
|
+
wait_until_ready(file)
|
51
|
+
file.delete
|
52
|
+
expect(file.stored?).to be(false)
|
55
53
|
end
|
56
54
|
|
57
|
-
it '
|
58
|
-
expect {
|
55
|
+
it 'deletes itself' do
|
56
|
+
expect { file.delete }.to_not raise_error
|
59
57
|
end
|
60
58
|
|
61
|
-
it '
|
62
|
-
|
63
|
-
|
64
|
-
wait_until_ready(
|
65
|
-
|
66
|
-
|
59
|
+
it 'is able to tell thenever file was deleted' do
|
60
|
+
file.load
|
61
|
+
file.is_deleted?.should == false
|
62
|
+
wait_until_ready(file)
|
63
|
+
file.delete
|
64
|
+
expect(file.is_deleted?).to be true
|
67
65
|
end
|
68
66
|
|
69
|
-
it '
|
70
|
-
|
71
|
-
|
67
|
+
it 'constructs file from uuid' do
|
68
|
+
uuid_file = api.file file.uuid
|
69
|
+
expect(uuid_file).to be_kind_of(Uploadcare::Api::File)
|
72
70
|
end
|
73
71
|
|
74
|
-
it '
|
75
|
-
url =
|
76
|
-
file =
|
77
|
-
file.
|
72
|
+
it 'constructs file from cdn url' do
|
73
|
+
url = file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
74
|
+
file = api.file url
|
75
|
+
expect(file).to be_kind_of(Uploadcare::Api::File)
|
78
76
|
end
|
79
77
|
|
80
|
-
it '
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
78
|
+
it 'responds to datetime_ methods' do
|
79
|
+
file.load
|
80
|
+
expect(file).to respond_to(:datetime_original)
|
81
|
+
expect(file).to respond_to(:datetime_uploaded)
|
82
|
+
expect(file).to respond_to(:datetime_stored)
|
83
|
+
expect(file).to respond_to(:datetime_removed)
|
86
84
|
end
|
87
85
|
|
88
|
-
it '
|
89
|
-
|
90
|
-
|
86
|
+
it 'responds to datetime_uploaded' do
|
87
|
+
file.load
|
88
|
+
expect(file.datetime_uploaded).to be_kind_of(DateTime)
|
91
89
|
end
|
92
90
|
|
93
|
-
it '
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
it 'responds to datetime_stored' do
|
92
|
+
file.load
|
93
|
+
file.store
|
94
|
+
expect(file.datetime_stored).to be_kind_of(DateTime)
|
97
95
|
end
|
98
96
|
|
99
|
-
it '
|
100
|
-
|
101
|
-
wait_until_ready(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
97
|
+
it 'responds to datetime_removed' do
|
98
|
+
file.load
|
99
|
+
wait_until_ready(file)
|
100
|
+
file.delete
|
101
|
+
expect(file.datetime_removed).to be_kind_of(DateTime)
|
102
|
+
expect(file.datetime_deleted).to be_kind_of(DateTime)
|
103
|
+
expect(file.datetime_removed).to eq file.datetime_deleted
|
106
104
|
end
|
107
105
|
|
108
106
|
|
109
|
-
it '
|
107
|
+
it 'copies itself' do
|
110
108
|
# This can cause "File is not ready yet" error if ran too early
|
111
109
|
# In this case we retry it 3 times before giving up
|
112
|
-
result = retry_if(Uploadcare::Error::RequestError::BadRequest){
|
113
|
-
result.
|
114
|
-
result["type"].
|
110
|
+
result = retry_if(Uploadcare::Error::RequestError::BadRequest){file.copy}
|
111
|
+
expect(result).to be_kind_of(Hash)
|
112
|
+
expect(result["type"]).to eq "file"
|
115
113
|
end
|
116
114
|
|
117
115
|
|
118
116
|
describe '#internal_copy' do
|
119
117
|
describe 'integration' do
|
120
118
|
it 'creates an internal copy of the file' do
|
121
|
-
response = retry_if(Uploadcare::Error::RequestError::BadRequest){
|
119
|
+
response = retry_if(Uploadcare::Error::RequestError::BadRequest){file.internal_copy}
|
122
120
|
|
123
121
|
expect( response['type'] ).to eq 'file'
|
124
|
-
expect( response['result']['uuid'] ).not_to eq
|
122
|
+
expect( response['result']['uuid'] ).not_to eq file.uuid
|
125
123
|
end
|
126
124
|
end
|
127
125
|
|
128
126
|
describe 'params' do
|
129
|
-
let(:url_without_ops){
|
127
|
+
let(:url_without_ops){ api.file(SecureRandom.uuid).cdn_url }
|
130
128
|
let(:url_with_ops){ url_without_ops + "-/crop/5x5/center/" }
|
131
|
-
let(:file){
|
129
|
+
let(:file){ api.file(url_with_ops) }
|
132
130
|
|
133
131
|
context 'if no params given' do
|
134
132
|
it 'requests server to create an unstored copy with operataions applied' do
|
135
|
-
expect(
|
133
|
+
expect(api).to receive(:post)
|
136
134
|
.with('/files/', source: url_with_ops)
|
137
135
|
|
138
136
|
file.internal_copy
|
@@ -141,7 +139,7 @@ describe Uploadcare::Api::File do
|
|
141
139
|
|
142
140
|
context 'if strip_operations: true given' do
|
143
141
|
it 'passes url without operations as a source for a copy' do
|
144
|
-
expect(
|
142
|
+
expect(api).to receive(:post)
|
145
143
|
.with('/files/', source: url_without_ops)
|
146
144
|
|
147
145
|
file.internal_copy(strip_operations: true)
|
@@ -150,7 +148,7 @@ describe Uploadcare::Api::File do
|
|
150
148
|
|
151
149
|
context 'if store: true given' do
|
152
150
|
it 'requests server to create a stored copy' do
|
153
|
-
expect(
|
151
|
+
expect(api).to receive(:post)
|
154
152
|
.with('/files/', source: url_with_ops, store: true)
|
155
153
|
|
156
154
|
file.internal_copy(store: true)
|
@@ -166,7 +164,7 @@ describe Uploadcare::Api::File do
|
|
166
164
|
describe 'integration', :payed_feature do
|
167
165
|
it 'creates an external copy of the file' do
|
168
166
|
response = retry_if(Uploadcare::Error::RequestError::BadRequest) do
|
169
|
-
|
167
|
+
file.external_copy(target)
|
170
168
|
end
|
171
169
|
|
172
170
|
expect( response['type'] ).to eq 'url'
|
@@ -175,13 +173,13 @@ describe Uploadcare::Api::File do
|
|
175
173
|
end
|
176
174
|
|
177
175
|
describe 'params' do
|
178
|
-
let(:url_without_ops){
|
176
|
+
let(:url_without_ops){ api.file(SecureRandom.uuid).cdn_url }
|
179
177
|
let(:url_with_ops){ url_without_ops + "-/resize/50x50/" }
|
180
|
-
let(:file){
|
178
|
+
let(:file){ api.file(url_with_ops) }
|
181
179
|
|
182
180
|
context 'if only target is given' do
|
183
181
|
it 'requests server to create a private copy with default name and with operataions applied' do
|
184
|
-
expect(
|
182
|
+
expect(api).to receive(:post)
|
185
183
|
.with('/files/', source: url_with_ops, target: target)
|
186
184
|
|
187
185
|
file.external_copy(target)
|
@@ -196,7 +194,7 @@ describe Uploadcare::Api::File do
|
|
196
194
|
|
197
195
|
context 'if strip_operations: true given' do
|
198
196
|
it 'passes url without operations as a source for a copy' do
|
199
|
-
expect(
|
197
|
+
expect(api).to receive(:post)
|
200
198
|
.with('/files/', source: url_without_ops, target: target)
|
201
199
|
|
202
200
|
file.external_copy(target, strip_operations: true)
|
@@ -205,7 +203,7 @@ describe Uploadcare::Api::File do
|
|
205
203
|
|
206
204
|
context 'if :make_public given' do
|
207
205
|
it 'requests server to create a copy with correspondent permissions' do
|
208
|
-
expect(
|
206
|
+
expect(api).to receive(:post)
|
209
207
|
.with('/files/', source: url_with_ops, target: target, make_public: false)
|
210
208
|
|
211
209
|
file.external_copy(target, make_public: false)
|
@@ -214,7 +212,7 @@ describe Uploadcare::Api::File do
|
|
214
212
|
|
215
213
|
context 'if :pattern given' do
|
216
214
|
it 'requests server to apply given pattern to name of a copy' do
|
217
|
-
expect(
|
215
|
+
expect(api).to receive(:post)
|
218
216
|
.with('/files/', source: url_with_ops, target: target, pattern: 'test')
|
219
217
|
|
220
218
|
file.external_copy(target, pattern: 'test')
|
@@ -96,6 +96,6 @@ describe Uploadcare::Api::Group do
|
|
96
96
|
|
97
97
|
it 'should raise an error if index is greater than files count in group' do
|
98
98
|
group = @api.create_group @files
|
99
|
-
expect {group.file_cdn_url(5)}.to raise_error
|
99
|
+
expect {group.file_cdn_url(5)}.to raise_error ArgumentError
|
100
100
|
end
|
101
|
-
end
|
101
|
+
end
|
@@ -19,7 +19,7 @@ describe Uploadcare::Connections::ApiConnection do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'includes correct User-Agent header' do
|
22
|
-
expected = Uploadcare::
|
22
|
+
expected = Uploadcare::UserAgent.new.call(settings)
|
23
23
|
expect(subject['User-Agent']).to eq expected
|
24
24
|
end
|
25
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,9 @@ require 'rspec'
|
|
7
7
|
require 'uploadcare'
|
8
8
|
require 'yaml'
|
9
9
|
|
10
|
+
require 'coveralls'
|
11
|
+
Coveralls.wear!
|
12
|
+
|
10
13
|
CONFIG = Uploadcare.default_settings.merge!(
|
11
14
|
public_key: ENV['UPLOADCARE_PUBLIC_KEY'] || 'demopublickey',
|
12
15
|
private_key: ENV['UPLOADCARE_SECRET_KEY'] || 'demoprivatekey',
|
data/spec/uploadcare_spec.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Uploadcare do
|
4
|
-
|
5
4
|
describe '::user_agent' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
5
|
+
subject(:user_agent) { described_class.user_agent(options) }
|
6
|
+
let(:options) { {user_agent: 'user/agent'} }
|
7
|
+
let(:user_agent_builder) { instance_double('Uploadcare::UserAgent') }
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
it 'returns user agent string' do
|
10
|
+
allow(Uploadcare::UserAgent).to receive(:new) { user_agent_builder }
|
11
|
+
expect(user_agent_builder).to receive(:call).with(options) { 'user/agent' }
|
12
|
+
|
13
|
+
expect(user_agent).to eq('user/agent')
|
17
14
|
end
|
18
15
|
end
|
19
|
-
|
20
16
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Uploadcare::UserAgent do
|
4
|
+
subject(:user_agent) { described_class.new.call(options) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
stub_const('Uploadcare::VERSION', '123')
|
8
|
+
allow(Gem).to receive(:ruby_version) { '456' }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when user_agent option is set' do
|
12
|
+
let(:options) do
|
13
|
+
{ user_agent: 'predefined user agent' }
|
14
|
+
end
|
15
|
+
|
16
|
+
it { is_expected.to eq('predefined user agent') }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when user_agent_environment option is set' do
|
20
|
+
let(:options) do
|
21
|
+
{
|
22
|
+
public_key: 'pubkey',
|
23
|
+
user_agent_environment: {
|
24
|
+
framework_name: 'rails',
|
25
|
+
framework_version: '5.1.0',
|
26
|
+
extension_name: 'UploadcareRails',
|
27
|
+
extension_version: '1.1.0'
|
28
|
+
}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
it do
|
33
|
+
is_expected.to eq(
|
34
|
+
'UploadcareRuby/123/pubkey (Ruby/456; rails/5.1.0; UploadcareRails/1.1.0)'
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when user_agent_environment option is not set' do
|
40
|
+
let(:options) do
|
41
|
+
{ public_key: 'pubkey' }
|
42
|
+
end
|
43
|
+
|
44
|
+
it { is_expected.to eq('UploadcareRuby/123/pubkey (Ruby/456)') }
|
45
|
+
end
|
46
|
+
end
|
data/uploadcare-ruby.gemspec
CHANGED
@@ -2,37 +2,37 @@
|
|
2
2
|
require File.expand_path('../lib/uploadcare/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.name =
|
6
|
-
gem.authors = [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem.email = [
|
11
|
-
gem.summary =
|
5
|
+
gem.name = 'uploadcare-ruby'
|
6
|
+
gem.authors = ['@rastyagaev (Vadim Rastyagaev)',
|
7
|
+
'@dimituri (Dimitry Solovyov)',
|
8
|
+
'@romanonthego (Roman Dubinin)',
|
9
|
+
'@vizvamitra (Dmitrii Krasnov)']
|
10
|
+
gem.email = ['hello@uploadcare.com']
|
11
|
+
gem.summary = 'Ruby gem for Uploadcare'
|
12
12
|
gem.description = <<-EOF
|
13
13
|
Ruby wrapper for Uploadcare service API.
|
14
14
|
Full documentations on APIs can be found
|
15
15
|
at https://uploadcare.com/documentation/rest/
|
16
16
|
and https://uploadcare.com/documentation/upload/
|
17
17
|
EOF
|
18
|
-
gem.metadata
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
gem.
|
23
|
-
gem.license = "MIT"
|
18
|
+
gem.metadata = { 'github' => 'https://github.com/uploadcare/uploadcare-ruby',
|
19
|
+
'issue_tracker' => 'https://github.com/uploadcare/uploadcare-ruby/issues',
|
20
|
+
}
|
21
|
+
gem.homepage = 'https://uploadcare.com/documentation/libs/'
|
22
|
+
gem.license = 'MIT'
|
24
23
|
|
25
24
|
gem.files = `git ls-files`.split($\)
|
26
25
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
27
26
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
28
|
-
gem.require_paths = [
|
27
|
+
gem.require_paths = ['lib']
|
29
28
|
gem.version = Uploadcare::VERSION
|
30
29
|
gem.add_runtime_dependency 'faraday', '~> 0.8'
|
31
30
|
gem.add_runtime_dependency 'faraday_middleware', '~> 0.9'
|
32
31
|
gem.add_runtime_dependency 'multipart-post'
|
33
32
|
gem.add_runtime_dependency 'mime-types'
|
34
33
|
|
35
|
-
gem.add_development_dependency 'rspec',
|
34
|
+
gem.add_development_dependency 'rspec', '~> 3.6'
|
36
35
|
gem.add_development_dependency 'rake'
|
37
36
|
gem.add_development_dependency 'pry'
|
37
|
+
gem.add_development_dependency 'coveralls'
|
38
38
|
end
|
metadata
CHANGED
@@ -1,114 +1,128 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
7
|
+
- "@rastyagaev (Vadim Rastyagaev)"
|
8
|
+
- "@dimituri (Dimitry Solovyov)"
|
9
|
+
- "@romanonthego (Roman Dubinin)"
|
10
|
+
- "@vizvamitra (Dmitrii Krasnov)"
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - ~>
|
20
|
+
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '0.8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0.8'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: faraday_middleware
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '0.9'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0.9'
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: multipart-post
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- -
|
48
|
+
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mime-types
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- -
|
62
|
+
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: rspec
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- - ~>
|
76
|
+
- - "~>"
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '3.6'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- - ~>
|
83
|
+
- - "~>"
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '3.6'
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: rake
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: pry
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- -
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
type: :development
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- -
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: coveralls
|
116
|
+
requirement: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
112
126
|
- !ruby/object:Gem::Version
|
113
127
|
version: '0'
|
114
128
|
description: |2
|
@@ -122,10 +136,9 @@ executables: []
|
|
122
136
|
extensions: []
|
123
137
|
extra_rdoc_files: []
|
124
138
|
files:
|
125
|
-
- .
|
126
|
-
- .
|
127
|
-
- .
|
128
|
-
- .travis.yml
|
139
|
+
- ".gitignore"
|
140
|
+
- ".rspec"
|
141
|
+
- ".travis.yml"
|
129
142
|
- CHANGELOG.md
|
130
143
|
- Gemfile
|
131
144
|
- LICENSE
|
@@ -161,6 +174,7 @@ files:
|
|
161
174
|
- lib/uploadcare/rest/middlewares/parse_json_middleware.rb
|
162
175
|
- lib/uploadcare/rest/middlewares/raise_error_middleware.rb
|
163
176
|
- lib/uploadcare/utils/parser.rb
|
177
|
+
- lib/uploadcare/utils/user_agent.rb
|
164
178
|
- lib/uploadcare/version.rb
|
165
179
|
- spec/api/file_list_api_spec.rb
|
166
180
|
- spec/api/file_storage_api_spec.rb
|
@@ -183,6 +197,7 @@ files:
|
|
183
197
|
- spec/spec_helper.rb
|
184
198
|
- spec/uploadcare_spec.rb
|
185
199
|
- spec/utils/parser_spec.rb
|
200
|
+
- spec/utils/user_agent_spec.rb
|
186
201
|
- spec/view.png
|
187
202
|
- spec/view2.jpg
|
188
203
|
- uploadcare-ruby.gemspec
|
@@ -198,17 +213,17 @@ require_paths:
|
|
198
213
|
- lib
|
199
214
|
required_ruby_version: !ruby/object:Gem::Requirement
|
200
215
|
requirements:
|
201
|
-
- -
|
216
|
+
- - ">="
|
202
217
|
- !ruby/object:Gem::Version
|
203
218
|
version: '0'
|
204
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
220
|
requirements:
|
206
|
-
- -
|
221
|
+
- - ">="
|
207
222
|
- !ruby/object:Gem::Version
|
208
223
|
version: '0'
|
209
224
|
requirements: []
|
210
225
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
226
|
+
rubygems_version: 2.5.2
|
212
227
|
signing_key:
|
213
228
|
specification_version: 4
|
214
229
|
summary: Ruby gem for Uploadcare
|
@@ -234,5 +249,6 @@ test_files:
|
|
234
249
|
- spec/spec_helper.rb
|
235
250
|
- spec/uploadcare_spec.rb
|
236
251
|
- spec/utils/parser_spec.rb
|
252
|
+
- spec/utils/user_agent_spec.rb
|
237
253
|
- spec/view.png
|
238
254
|
- spec/view2.jpg
|