uploadcare-ruby 1.2.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/gem-push.yml +20 -0
- data/.github/workflows/ruby.yml +52 -0
- data/.gitignore +13 -5
- data/.rspec +3 -0
- data/.rubocop.yml +20 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +25 -24
- data/DEVELOPMENT.md +18 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +191 -519
- data/Rakefile +6 -4
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/uploadcare.rb +36 -26
- data/lib/uploadcare/api/api.rb +25 -0
- data/lib/uploadcare/client/file_client.rb +44 -0
- data/lib/uploadcare/client/file_list_client.rb +46 -0
- data/lib/uploadcare/client/group_client.rb +45 -0
- data/lib/uploadcare/client/multipart_upload/chunks_client.rb +46 -0
- data/lib/uploadcare/client/multipart_upload_client.rb +62 -0
- data/lib/uploadcare/client/project_client.rb +18 -0
- data/lib/uploadcare/client/rest_client.rb +73 -0
- data/lib/uploadcare/client/rest_group_client.rb +23 -0
- data/lib/uploadcare/client/upload_client.rb +35 -0
- data/lib/uploadcare/client/uploader_client.rb +93 -0
- data/lib/uploadcare/client/webhook_client.rb +43 -0
- data/lib/uploadcare/concern/error_handler.rb +54 -0
- data/lib/uploadcare/concern/throttle_handler.rb +25 -0
- data/lib/uploadcare/concern/upload_error_handler.rb +32 -0
- data/lib/uploadcare/entity/decorator/paginator.rb +81 -0
- data/lib/uploadcare/entity/entity.rb +18 -0
- data/lib/uploadcare/entity/file.rb +81 -0
- data/lib/uploadcare/entity/file_list.rb +30 -0
- data/lib/uploadcare/entity/group.rb +41 -0
- data/lib/uploadcare/entity/group_list.rb +24 -0
- data/lib/uploadcare/entity/project.rb +13 -0
- data/lib/uploadcare/entity/uploader.rb +73 -0
- data/lib/uploadcare/entity/webhook.rb +14 -0
- data/lib/uploadcare/exception/request_error.rb +9 -0
- data/lib/uploadcare/exception/throttle_error.rb +14 -0
- data/lib/uploadcare/param/authentication_header.rb +25 -0
- data/lib/uploadcare/param/param.rb +10 -0
- data/lib/uploadcare/param/secure_auth_header.rb +37 -0
- data/lib/uploadcare/param/simple_auth_header.rb +14 -0
- data/lib/uploadcare/param/upload/signature_generator.rb +24 -0
- data/lib/uploadcare/param/upload/upload_params_generator.rb +23 -0
- data/lib/uploadcare/param/user_agent.rb +21 -0
- data/lib/uploadcare/ruby/version.rb +5 -0
- data/uploadcare-ruby.gemspec +50 -36
- metadata +112 -96
- data/.travis.yml +0 -12
- data/lib/uploadcare/api.rb +0 -24
- data/lib/uploadcare/api/file_api.rb +0 -7
- data/lib/uploadcare/api/file_list_api.rb +0 -8
- data/lib/uploadcare/api/group_api.rb +0 -38
- data/lib/uploadcare/api/group_list_api.rb +0 -8
- data/lib/uploadcare/api/project_api.rb +0 -9
- data/lib/uploadcare/api/raw_api.rb +0 -44
- data/lib/uploadcare/api/uploading_api.rb +0 -110
- data/lib/uploadcare/errors/errors.rb +0 -64
- data/lib/uploadcare/resources/file.rb +0 -164
- data/lib/uploadcare/resources/file_list.rb +0 -41
- data/lib/uploadcare/resources/group.rb +0 -115
- data/lib/uploadcare/resources/group_list.rb +0 -31
- data/lib/uploadcare/resources/project.rb +0 -13
- data/lib/uploadcare/rest/auth/auth.rb +0 -31
- data/lib/uploadcare/rest/auth/secure.rb +0 -43
- data/lib/uploadcare/rest/auth/simple.rb +0 -16
- data/lib/uploadcare/rest/connections/api_connection.rb +0 -32
- data/lib/uploadcare/rest/connections/upload_connection.rb +0 -21
- data/lib/uploadcare/rest/middlewares/auth_middleware.rb +0 -24
- data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +0 -33
- data/lib/uploadcare/rest/middlewares/raise_error_middleware.rb +0 -21
- data/lib/uploadcare/utils/parser.rb +0 -71
- data/lib/uploadcare/utils/user_agent.rb +0 -44
- data/lib/uploadcare/version.rb +0 -3
- data/spec/api/raw_api_spec.rb +0 -25
- data/spec/resources/file_list_spec.rb +0 -64
- data/spec/resources/file_spec.rb +0 -222
- data/spec/resources/group_list_spec.rb +0 -30
- data/spec/resources/group_spec.rb +0 -101
- data/spec/resources/operations_spec.rb +0 -59
- data/spec/resources/project_spec.rb +0 -21
- data/spec/rest/api_connection_spec.rb +0 -68
- data/spec/rest/auth/secure_spec.rb +0 -66
- data/spec/rest/auth/simple_spec.rb +0 -31
- data/spec/rest/errors_spec.rb +0 -75
- data/spec/rest/upload_connection_spec.rb +0 -19
- data/spec/spec_helper.rb +0 -41
- data/spec/uploadcare_spec.rb +0 -16
- data/spec/uploading/uploading_multiple_spec.rb +0 -43
- data/spec/uploading/uploading_spec.rb +0 -40
- data/spec/utils/parser_spec.rb +0 -87
- data/spec/utils/user_agent_spec.rb +0 -46
- data/spec/view.png +0 -0
- data/spec/view2.jpg +0 -0
data/spec/resources/file_spec.rb
DELETED
@@ -1,222 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
require 'securerandom'
|
5
|
-
|
6
|
-
describe Uploadcare::Api::File do
|
7
|
-
before :each do
|
8
|
-
@api = API
|
9
|
-
@file = @api.upload IMAGE_URL
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'file should be an instance of File' do
|
13
|
-
@file.should be_an_instance_of Uploadcare::Api::File
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should not be initialized without correct UUID given' do
|
17
|
-
expect {Uploadcare::Api::File.new(@api, "not-uuid")}.to raise_error
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should have valid url' do
|
21
|
-
@file.uuid.should match UUID_REGEX
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should return public url' do
|
25
|
-
@file.should respond_to :cdn_url
|
26
|
-
@file.should respond_to :public_url
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'public url should be valid url' do
|
30
|
-
url = @file.cdn_url
|
31
|
-
uri = URI.parse(url)
|
32
|
-
uri.should be_kind_of(URI::HTTP)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should be able to load image data' do
|
36
|
-
expect {@file.load_data}.to_not raise_error
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should store itself' do
|
40
|
-
expect { @file.store }.to_not raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'file should respond with nil for :stored? and :deleted? methods unless loaded' do
|
44
|
-
@file.is_loaded?.should == false
|
45
|
-
@file.is_stored?.should == nil
|
46
|
-
@file.is_deleted?.should == nil
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should be able to tell thenever file was stored' do
|
50
|
-
@file.load
|
51
|
-
@file.is_stored?.should == false
|
52
|
-
@file.store
|
53
|
-
@file.is_stored?.should == true
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should delete itself' do
|
57
|
-
expect { @file.delete }.to_not raise_error
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'should be able to tell thenever file was deleted' do
|
61
|
-
@file.load
|
62
|
-
@file.is_deleted?.should == false
|
63
|
-
@file.delete
|
64
|
-
@file.is_deleted?.should == true
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should construct file from uuid' do
|
68
|
-
file = @api.file @file.uuid
|
69
|
-
file.should be_kind_of(Uploadcare::Api::File)
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should construct file from cdn url' do
|
73
|
-
url = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
74
|
-
file = @api.file url
|
75
|
-
file.should be_kind_of(Uploadcare::Api::File)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'shoul respond to datetime_ methods' do
|
79
|
-
@file.load
|
80
|
-
@file.should respond_to(:datetime_original)
|
81
|
-
@file.should respond_to(:datetime_uploaded)
|
82
|
-
@file.should respond_to(:datetime_stored)
|
83
|
-
@file.should respond_to(:datetime_removed)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should respond to datetime_uploaded' do
|
87
|
-
@file.load
|
88
|
-
@file.datetime_uploaded.should be_kind_of(DateTime)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should respond to datetime_stored' do
|
92
|
-
@file.load
|
93
|
-
@file.store
|
94
|
-
@file.datetime_stored.should be_kind_of(DateTime)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should respond to datetime_removed' do
|
98
|
-
@file.load
|
99
|
-
@file.delete
|
100
|
-
@file.datetime_removed.should be_kind_of(DateTime)
|
101
|
-
@file.datetime_deleted.should be_kind_of(DateTime)
|
102
|
-
@file.datetime_removed.should == @file.datetime_deleted
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
it 'should copy itself' do
|
107
|
-
# This can cause "File is not ready yet" error if ran too early
|
108
|
-
# In this case we retry it 3 times before giving up
|
109
|
-
result = retry_if(Uploadcare::Error::RequestError::BadRequest){@file.copy}
|
110
|
-
result.should be_kind_of(Hash)
|
111
|
-
result["type"].should == "file"
|
112
|
-
end
|
113
|
-
|
114
|
-
|
115
|
-
describe '#internal_copy' do
|
116
|
-
describe 'integration' do
|
117
|
-
it 'creates an internal copy of the file' do
|
118
|
-
response = retry_if(Uploadcare::Error::RequestError::BadRequest){@file.internal_copy}
|
119
|
-
|
120
|
-
expect( response['type'] ).to eq 'file'
|
121
|
-
expect( response['result']['uuid'] ).not_to eq @file.uuid
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'params' do
|
126
|
-
let(:url_without_ops){ @api.file(SecureRandom.uuid).cdn_url }
|
127
|
-
let(:url_with_ops){ url_without_ops + "-/crop/5x5/center/" }
|
128
|
-
let(:file){ @api.file(url_with_ops) }
|
129
|
-
|
130
|
-
context 'if no params given' do
|
131
|
-
it 'requests server to create an unstored copy with operataions applied' do
|
132
|
-
expect(@api).to receive(:post)
|
133
|
-
.with('/files/', source: url_with_ops)
|
134
|
-
|
135
|
-
file.internal_copy
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'if strip_operations: true given' do
|
140
|
-
it 'passes url without operations as a source for a copy' do
|
141
|
-
expect(@api).to receive(:post)
|
142
|
-
.with('/files/', source: url_without_ops)
|
143
|
-
|
144
|
-
file.internal_copy(strip_operations: true)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context 'if store: true given' do
|
149
|
-
it 'requests server to create a stored copy' do
|
150
|
-
expect(@api).to receive(:post)
|
151
|
-
.with('/files/', source: url_with_ops, store: true)
|
152
|
-
|
153
|
-
file.internal_copy(store: true)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
|
160
|
-
describe '#external_copy' do
|
161
|
-
let(:target){ 'with-prefix' }
|
162
|
-
|
163
|
-
describe 'integration', :payed_feature do
|
164
|
-
it 'creates an external copy of the file' do
|
165
|
-
response = retry_if(Uploadcare::Error::RequestError::BadRequest) do
|
166
|
-
@file.external_copy(target)
|
167
|
-
end
|
168
|
-
|
169
|
-
expect( response['type'] ).to eq 'url'
|
170
|
-
expect( response['result'] ).to match(URI.regexp)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe 'params' do
|
175
|
-
let(:url_without_ops){ @api.file(SecureRandom.uuid).cdn_url }
|
176
|
-
let(:url_with_ops){ url_without_ops + "-/resize/50x50/" }
|
177
|
-
let(:file){ @api.file(url_with_ops) }
|
178
|
-
|
179
|
-
context 'if only target is given' do
|
180
|
-
it 'requests server to create a private copy with default name and with operataions applied' do
|
181
|
-
expect(@api).to receive(:post)
|
182
|
-
.with('/files/', source: url_with_ops, target: target)
|
183
|
-
|
184
|
-
file.external_copy(target)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context 'if target is not given' do
|
189
|
-
it 'raises ArgumentError' do
|
190
|
-
expect{ file.external_copy }.to raise_error(ArgumentError)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
context 'if strip_operations: true given' do
|
195
|
-
it 'passes url without operations as a source for a copy' do
|
196
|
-
expect(@api).to receive(:post)
|
197
|
-
.with('/files/', source: url_without_ops, target: target)
|
198
|
-
|
199
|
-
file.external_copy(target, strip_operations: true)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'if :make_public given' do
|
204
|
-
it 'requests server to create a copy with correspondent permissions' do
|
205
|
-
expect(@api).to receive(:post)
|
206
|
-
.with('/files/', source: url_with_ops, target: target, make_public: false)
|
207
|
-
|
208
|
-
file.external_copy(target, make_public: false)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context 'if :pattern given' do
|
213
|
-
it 'requests server to apply given pattern to name of a copy' do
|
214
|
-
expect(@api).to receive(:post)
|
215
|
-
.with('/files/', source: url_with_ops, target: target, pattern: 'test')
|
216
|
-
|
217
|
-
file.external_copy(target, pattern: 'test')
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::File do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@list = @api.group_list
|
9
|
-
end
|
10
|
-
|
11
|
-
it "basic group list" do
|
12
|
-
@list.should be_kind_of Uploadcare::Api::GroupList
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should contain groups and results" do
|
16
|
-
@list.should respond_to(:results)
|
17
|
-
@list.should respond_to(:groups)
|
18
|
-
@list.groups.should be_kind_of(Array)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "results should contain groups" do
|
22
|
-
group = @list.groups.sample
|
23
|
-
group.should be_kind_of(Uploadcare::Api::Group)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "group should no be loaded" do
|
27
|
-
group = @list.groups.sample
|
28
|
-
group.is_loaded?.should == false
|
29
|
-
end
|
30
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::Group do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@files = @api.upload FILES_ARY
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should return group object" do
|
12
|
-
group = @api.create_group @files
|
13
|
-
group.should be_kind_of(Uploadcare::Api::Group)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should have valid UUID and count of files" do
|
17
|
-
group = @api.create_group @files
|
18
|
-
group.should respond_to(:uuid)
|
19
|
-
group.should respond_to(:files_count)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should may have files" do
|
23
|
-
group = @api.create_group @files
|
24
|
-
group.should respond_to(:files)
|
25
|
-
group.files.should be_kind_of(Array)
|
26
|
-
group.files.each do |file|
|
27
|
-
file.should be_kind_of(Uploadcare::Api::File)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should create group by id" do
|
32
|
-
group = @api.create_group @files
|
33
|
-
|
34
|
-
expect {group_uloaded = @api.group group.uuid}.to_not raise_error
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should create loaded and unloaded groups" do
|
38
|
-
group = @api.create_group @files
|
39
|
-
group_uloaded = @api.group group.uuid
|
40
|
-
group.is_loaded?.should be true
|
41
|
-
group_uloaded.is_loaded?.should be false
|
42
|
-
end
|
43
|
-
|
44
|
-
it "group should load data" do
|
45
|
-
group = @api.create_group @files
|
46
|
-
group_uloaded = @api.group group.uuid
|
47
|
-
group_uloaded.should respond_to(:load_data)
|
48
|
-
expect {group_uloaded.load_data}.to_not raise_error
|
49
|
-
group_uloaded.is_loaded?.should be true
|
50
|
-
end
|
51
|
-
|
52
|
-
it "group should store itself" do
|
53
|
-
group = @api.create_group @files
|
54
|
-
expect {group.store}.to_not raise_error
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should be able to tell when group is stored" do
|
58
|
-
group = @api.create_group @files
|
59
|
-
group_unloaded = @api.group group.uuid
|
60
|
-
|
61
|
-
group_unloaded.is_loaded?.should == false
|
62
|
-
group_unloaded.is_stored?.should == nil
|
63
|
-
|
64
|
-
group_unloaded.load
|
65
|
-
group_unloaded.is_stored?.should == false
|
66
|
-
|
67
|
-
group_unloaded.store
|
68
|
-
group_unloaded.is_stored?.should == true
|
69
|
-
end
|
70
|
-
|
71
|
-
it "group should have datetime attributes" do
|
72
|
-
group = @api.create_group @files
|
73
|
-
group.should respond_to(:datetime_created)
|
74
|
-
group.should respond_to(:datetime_stored)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "group should have datetime_created as DateTime object" do
|
78
|
-
group = @api.create_group @files
|
79
|
-
group.datetime_created.should be_kind_of(DateTime)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "group should have datetime_created as DateTime object" do
|
83
|
-
group = @api.create_group @files
|
84
|
-
group.store
|
85
|
-
group.datetime_stored.should be_kind_of(DateTime)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should return cdn string for file in group by it index" do
|
89
|
-
group = @api.create_group @files
|
90
|
-
|
91
|
-
file_cdn_url = group.file_cdn_url(0)
|
92
|
-
|
93
|
-
file_cdn_url.should be_kind_of(String)
|
94
|
-
file_cdn_url.should == group.cdn_url + "nth/0/"
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should raise an error if index is greater than files count in group' do
|
98
|
-
group = @api.create_group @files
|
99
|
-
expect {group.file_cdn_url(5)}.to raise_error
|
100
|
-
end
|
101
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::File do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@file = @api.upload IMAGE_URL
|
9
|
-
end
|
10
|
-
|
11
|
-
it "freshly uploaded file should have empty operations list" do
|
12
|
-
@file.should respond_to :operations
|
13
|
-
@file.operations.should be_kind_of(Array)
|
14
|
-
@file.operations.should be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
it "file created from uuid should be not loaded and without operations" do
|
18
|
-
file = @api.file @file.uuid
|
19
|
-
file.is_loaded?.should be false
|
20
|
-
file.operations.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it "file created from url without operations should be not be loaded and have no operations" do
|
24
|
-
file = @api.file @file.cdn_url
|
25
|
-
file.is_loaded?.should be false
|
26
|
-
file.operations.should be_empty
|
27
|
-
end
|
28
|
-
|
29
|
-
it "file created from url with operations should be not be loaded and have operations" do
|
30
|
-
file = @api.file @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
31
|
-
file.is_loaded?.should be false
|
32
|
-
file.operations.should_not be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
it "file should have methods for construct cdn urls with or without cdn operations" do
|
36
|
-
@file.should respond_to(:cdn_url_with_operations)
|
37
|
-
@file.should respond_to(:cdn_url_without_operations)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "file should construct cdn_url with and without opreations" do
|
41
|
-
url_without_operations = @file.cdn_url
|
42
|
-
url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
43
|
-
|
44
|
-
file = @api.file url_with_operations
|
45
|
-
|
46
|
-
file.cdn_url.should == (url_without_operations)
|
47
|
-
file.cdn_url(true).should == (url_with_operations)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should works also with exact methods' do
|
51
|
-
url_without_operations = @file.cdn_url.to_s
|
52
|
-
url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
|
53
|
-
|
54
|
-
file = @api.file url_with_operations
|
55
|
-
|
56
|
-
file.cdn_url_with_operations.should == (url_with_operations)
|
57
|
-
file.cdn_url_without_operations.should == (url_without_operations)
|
58
|
-
end
|
59
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Api::Project do
|
6
|
-
before :all do
|
7
|
-
@api = API
|
8
|
-
@project = @api.project
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should instantiated project" do
|
12
|
-
@project.should be_kind_of Uploadcare::Api::Project
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should respond to project api methods" do
|
16
|
-
@project.should respond_to :collaborators
|
17
|
-
@project.should respond_to :name
|
18
|
-
@project.should respond_to :pub_key
|
19
|
-
@project.should respond_to :autostore_enabled
|
20
|
-
end
|
21
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'uri'
|
3
|
-
require 'socket'
|
4
|
-
|
5
|
-
describe Uploadcare::Connections::ApiConnection do
|
6
|
-
let(:settings){ Uploadcare.default_settings }
|
7
|
-
|
8
|
-
it 'is initializable with default settings' do
|
9
|
-
expect {described_class.new(settings)}.to_not raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
describe 'default request headers' do
|
14
|
-
subject{ described_class.new(settings).headers }
|
15
|
-
|
16
|
-
it 'includes correct Accept header' do
|
17
|
-
expected = "application/vnd.uploadcare-v#{settings[:api_version]}+json"
|
18
|
-
expect(subject['Accept']).to eq expected
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'includes correct User-Agent header' do
|
22
|
-
expected = Uploadcare::UserAgent.new.call(settings)
|
23
|
-
expect(subject['User-Agent']).to eq expected
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
describe 'middleware' do
|
29
|
-
subject{ described_class.new(settings).builder.handlers }
|
30
|
-
|
31
|
-
it 'uses Request::Auth middleware' do
|
32
|
-
expect(subject).to include(Uploadcare::Connections::Request::Auth)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'uses Response::ParseJson middleware' do
|
36
|
-
expect(subject).to include(Uploadcare::Connections::Response::ParseJson)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses Response::RaiseError middleware' do
|
40
|
-
expect(subject).to include(Uploadcare::Connections::Response::RaiseError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
describe 'auth scheme' do
|
46
|
-
it 'uses simple auth when auth_scheme: :simple setting is provided' do
|
47
|
-
expect(Uploadcare::Connections::Auth::Simple).to receive(:new)
|
48
|
-
described_class.new(settings.merge(auth_scheme: :simple))
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'uses secure auth when auth_scheme: :secure setting is provided' do
|
52
|
-
expect(Uploadcare::Connections::Auth::Secure).to receive(:new)
|
53
|
-
described_class.new(settings.merge(auth_scheme: :secure))
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'raises KeyError when :auth_scheme options is not provided' do
|
57
|
-
expect{
|
58
|
-
described_class.new(settings.reject{|k,_| k == :auth_scheme})
|
59
|
-
}.to raise_error(KeyError)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'raises ArgumentError when provided :auth_scheme is unknown' do
|
63
|
-
expect{
|
64
|
-
described_class.new(settings.merge(auth_scheme: :unknown))
|
65
|
-
}.to raise_error(ArgumentError)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|