uploadcare-ruby 1.2.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.rspec +1 -0
  4. data/.travis.yml +19 -5
  5. data/CHANGELOG.md +12 -30
  6. data/README.md +149 -72
  7. data/Rakefile +1 -1
  8. data/UPGRADE_NOTES.md +36 -0
  9. data/lib/uploadcare.rb +16 -22
  10. data/lib/uploadcare/api.rb +3 -1
  11. data/lib/uploadcare/api/file_list_api.rb +15 -4
  12. data/lib/uploadcare/api/file_storage_api.rb +34 -0
  13. data/lib/uploadcare/api/group_list_api.rb +13 -4
  14. data/lib/uploadcare/api/raw_api.rb +10 -16
  15. data/lib/uploadcare/api/uploading_api.rb +45 -84
  16. data/lib/uploadcare/api/uploading_api/upload_params.rb +72 -0
  17. data/lib/uploadcare/api/validators/file_list_options_validator.rb +73 -0
  18. data/lib/uploadcare/api/validators/group_list_options_validator.rb +49 -0
  19. data/lib/uploadcare/resources/file_list.rb +6 -33
  20. data/lib/uploadcare/resources/group_list.rb +6 -23
  21. data/lib/uploadcare/resources/resource_list.rb +83 -0
  22. data/lib/uploadcare/rest/connections/api_connection.rb +25 -3
  23. data/lib/uploadcare/rest/connections/upload_connection.rb +3 -2
  24. data/lib/uploadcare/version.rb +1 -1
  25. data/spec/api/file_list_api_spec.rb +95 -0
  26. data/spec/api/file_storage_api_spec.rb +88 -0
  27. data/spec/api/group_list_api_spec.rb +59 -0
  28. data/spec/api/raw_api_spec.rb +12 -12
  29. data/spec/api/uploading_api/upload_params_spec.rb +99 -0
  30. data/spec/api/uploading_api_spec.rb +59 -0
  31. data/spec/resources/file_list_spec.rb +13 -52
  32. data/spec/resources/file_spec.rb +6 -3
  33. data/spec/resources/group_list_spec.rb +15 -20
  34. data/spec/rest/api_connection_spec.rb +1 -1
  35. data/spec/shared/resource_list.rb +188 -0
  36. data/spec/spec_helper.rb +11 -1
  37. data/spec/uploadcare_spec.rb +9 -32
  38. data/spec/utils/parser_spec.rb +34 -36
  39. data/uploadcare-ruby.gemspec +7 -6
  40. metadata +52 -37
  41. data/lib/uploadcare/utils/user_agent.rb +0 -44
  42. data/spec/uploading/uploading_multiple_spec.rb +0 -43
  43. data/spec/uploading/uploading_spec.rb +0 -40
  44. data/spec/utils/user_agent_spec.rb +0 -46
@@ -32,10 +32,20 @@ if CONFIG[:public_key] == 'demopublickey'
32
32
  end
33
33
  end
34
34
 
35
- def retry_if(error, retries=5, &block)
35
+ Dir[File.join(File.dirname(__FILE__), 'shared/*.rb')].each{|path| require path}
36
+
37
+ def retry_if(error, retries=10, &block)
36
38
  block.call
37
39
  rescue error
38
40
  raise if retries <= 0
39
41
  sleep 0.2
40
42
  retry_if(error, retries-1, &block)
41
43
  end
44
+
45
+ def wait_until_ready(file)
46
+ unless file.is_ready
47
+ sleep 0.2
48
+ file.load_data!
49
+ wait_until_ready(file)
50
+ end
51
+ end
@@ -1,43 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Uploadcare do
4
- around do |example|
5
- orig_stderr = $stderr
6
- $stderr = StringIO.new
7
-
8
- example.call
9
-
10
- $stderr = orig_stderr
11
- end
12
4
 
13
5
  describe '::user_agent' do
14
- subject(:user_agent) { described_class.user_agent(options) }
15
- let(:options) { {user_agent: 'user/agent'} }
16
- let(:user_agent_builder) { instance_double('Uploadcare::UserAgent') }
17
-
18
- it 'returns user agent string' do
19
- allow(Uploadcare::UserAgent).to receive(:new) { user_agent_builder }
20
- expect(user_agent_builder).to receive(:call).with(options) { 'user/agent' }
21
-
22
- expect(user_agent).to eq('user/agent')
6
+ context "if :user_agent is specified in method's options" do
7
+ it "returns it's stringified version" do
8
+ expect( Uploadcare.user_agent(user_agent: 123) ).to eq '123'
9
+ end
23
10
  end
24
11
 
25
- it 'is deprecated' do
26
- user_agent
27
-
28
- $stderr.rewind
29
- expect($stderr.string).to start_with('[DEPRECATION] `Uploadcare::user_agent`')
12
+ context "if user_agent is not specified in method's options" do
13
+ it 'builds user-agent from ruby version, gem version and public key' do
14
+ expected = /#{Gem.ruby_version}\/#{described_class::VERSION}\/test/
15
+ expect( Uploadcare.user_agent(public_key: 'test') ).to match(expected)
16
+ end
30
17
  end
31
18
  end
32
19
 
33
- describe '::USER_AGENT' do
34
- it { expect(described_class::USER_AGENT).not_to be_nil }
35
-
36
- it 'is deprecated' do
37
- described_class::USER_AGENT
38
-
39
- $stderr.rewind
40
- expect($stderr.string).to start_with('[DEPRECATION] `Uploadcare::USER_AGENT`')
41
- end
42
- end
43
20
  end
@@ -13,11 +13,11 @@ describe Uploadcare::Parser do
13
13
 
14
14
  parsed = Uploadcare::Parser.parse(string)
15
15
 
16
- parsed.should be_kind_of(Uploadcare::Parser::File)
17
- parsed.uuid.should == @uuid
18
- parsed.count.should be_nil
19
- parsed.operations.should be_kind_of(Array)
20
- parsed.operations.should be_empty
16
+ expect(parsed).to be_kind_of(Uploadcare::Parser::File)
17
+ expect(parsed.uuid).to eq @uuid
18
+ expect(parsed.count).to be_nil
19
+ expect(parsed.operations).to be_kind_of(Array)
20
+ expect(parsed.operations).to be_empty
21
21
  end
22
22
 
23
23
  it "should parse file cdn string without operations string" do
@@ -25,11 +25,11 @@ describe Uploadcare::Parser do
25
25
 
26
26
  parsed = Uploadcare::Parser.parse(string)
27
27
 
28
- parsed.should be_kind_of(Uploadcare::Parser::File)
29
- parsed.uuid.should == @uuid
30
- parsed.count.should be_nil
31
- parsed.operations.should be_kind_of(Array)
32
- parsed.operations.should be_empty
28
+ expect(parsed).to be_kind_of(Uploadcare::Parser::File)
29
+ expect(parsed.uuid).to eq @uuid
30
+ expect(parsed.count).to be_nil
31
+ expect(parsed.operations).to be_kind_of(Array)
32
+ expect(parsed.operations).to be_empty
33
33
  end
34
34
 
35
35
  it "should parse file cdn string with operations string" do
@@ -37,11 +37,11 @@ describe Uploadcare::Parser do
37
37
 
38
38
  parsed = Uploadcare::Parser.parse(string)
39
39
 
40
- parsed.should be_kind_of(Uploadcare::Parser::File)
41
- parsed.uuid.should == @uuid
42
- parsed.count.should be_nil
43
- parsed.operations.should be_kind_of(Array)
44
- parsed.operations.should_not be_empty
40
+ expect(parsed).to be_kind_of(Uploadcare::Parser::File)
41
+ expect(parsed.uuid).to eq @uuid
42
+ expect(parsed.count).to be_nil
43
+ expect(parsed.operations).to be_kind_of(Array)
44
+ expect(parsed.operations).not_to be_empty
45
45
  end
46
46
 
47
47
  it "should parse group uuid string" do
@@ -49,12 +49,12 @@ describe Uploadcare::Parser do
49
49
 
50
50
  parsed = Uploadcare::Parser.parse(string)
51
51
 
52
- parsed.should be_kind_of(Uploadcare::Parser::Group)
53
- parsed.uuid.should == "#{@uuid}~#{@count}"
54
- parsed.count.should_not be_nil
55
- parsed.count.should == @count
56
- parsed.operations.should be_kind_of(Array)
57
- parsed.operations.should be_empty
52
+ expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
53
+ expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
54
+ expect(parsed.count).not_to be_nil
55
+ expect(parsed.count).to eq @count
56
+ expect(parsed.operations).to be_kind_of(Array)
57
+ expect(parsed.operations).to be_empty
58
58
  end
59
59
 
60
60
  it "should parse file cdn string without operations string" do
@@ -62,12 +62,12 @@ describe Uploadcare::Parser do
62
62
 
63
63
  parsed = Uploadcare::Parser.parse(string)
64
64
 
65
- parsed.should be_kind_of(Uploadcare::Parser::Group)
66
- parsed.uuid.should == "#{@uuid}~#{@count}"
67
- parsed.count.should_not be_nil
68
- parsed.count.should == @count
69
- parsed.operations.should be_kind_of(Array)
70
- parsed.operations.should be_empty
65
+ expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
66
+ expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
67
+ expect(parsed.count).not_to be_nil
68
+ expect(parsed.count).to eq @count
69
+ expect(parsed.operations).to be_kind_of(Array)
70
+ expect(parsed.operations).to be_empty
71
71
  end
72
72
 
73
73
  it "should parse file cdn string with operations string" do
@@ -75,13 +75,11 @@ describe Uploadcare::Parser do
75
75
 
76
76
  parsed = Uploadcare::Parser.parse(string)
77
77
 
78
- parsed.should be_kind_of(Uploadcare::Parser::Group)
79
- parsed.uuid.should == "#{@uuid}~#{@count}"
80
- parsed.count.should_not be_nil
81
- parsed.count.should == @count
82
- parsed.operations.should be_kind_of(Array)
83
- parsed.operations.should_not be_empty
78
+ expect(parsed).to be_kind_of(Uploadcare::Parser::Group)
79
+ expect(parsed.uuid).to eq "#{@uuid}~#{@count}"
80
+ expect(parsed.count).not_to be_nil
81
+ expect(parsed.count).to eq @count
82
+ expect(parsed.operations).to be_kind_of(Array)
83
+ expect(parsed.operations).not_to be_empty
84
84
  end
85
-
86
-
87
- end
85
+ end
@@ -5,18 +5,19 @@ Gem::Specification.new do |gem|
5
5
  gem.name = "uploadcare-ruby"
6
6
  gem.authors = ["@rastyagaev (Vadim Rastyagaev)",
7
7
  "@dimituri (Dimitry Solovyov)",
8
- "@romanonthego (Roman Dubinin)"]
8
+ "@romanonthego (Roman Dubinin)",
9
+ "@vizvamitra (Dmitrii Krasnov)"]
9
10
  gem.email = ["hello@uploadcare.com"]
10
11
  gem.summary = "Ruby gem for Uploadcare"
11
12
  gem.description = <<-EOF
12
- Ruby wrapper for Uploadcare service API.
13
+ Ruby wrapper for Uploadcare service API.
13
14
  Full documentations on APIs can be found
14
15
  at https://uploadcare.com/documentation/rest/
15
16
  and https://uploadcare.com/documentation/upload/
16
17
  EOF
17
- gem.metadata = {
18
- "github" => "https://github.com/uploadcare/uploadcare-ruby",
19
- "issue_tracker" => "https://github.com/uploadcare/uploadcare-ruby/issues"
18
+ gem.metadata = {
19
+ "github" => "https://github.com/uploadcare/uploadcare-ruby",
20
+ "issue_tracker" => "https://github.com/uploadcare/uploadcare-ruby/issues"
20
21
  }
21
22
  gem.homepage = "https://uploadcare.com/documentation/libs/"
22
23
  gem.license = "MIT"
@@ -31,7 +32,7 @@ Gem::Specification.new do |gem|
31
32
  gem.add_runtime_dependency 'multipart-post'
32
33
  gem.add_runtime_dependency 'mime-types'
33
34
 
34
- gem.add_development_dependency 'rspec', "~> 3"
35
+ gem.add_development_dependency 'rspec', "~> 3.6"
35
36
  gem.add_development_dependency 'rake'
36
37
  gem.add_development_dependency 'pry'
37
38
  end
metadata CHANGED
@@ -1,147 +1,157 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - "@rastyagaev (Vadim Rastyagaev)"
8
- - "@dimituri (Dimitry Solovyov)"
9
- - "@romanonthego (Roman Dubinin)"
7
+ - '@rastyagaev (Vadim Rastyagaev)'
8
+ - '@dimituri (Dimitry Solovyov)'
9
+ - '@romanonthego (Roman Dubinin)'
10
+ - '@vizvamitra (Dmitrii Krasnov)'
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
- date: 2018-06-11 00:00:00.000000000 Z
14
+ date: 2017-09-26 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: faraday
17
18
  requirement: !ruby/object:Gem::Requirement
18
19
  requirements:
19
- - - "~>"
20
+ - - ~>
20
21
  - !ruby/object:Gem::Version
21
22
  version: '0.8'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
- - - "~>"
27
+ - - ~>
27
28
  - !ruby/object:Gem::Version
28
29
  version: '0.8'
29
30
  - !ruby/object:Gem::Dependency
30
31
  name: faraday_middleware
31
32
  requirement: !ruby/object:Gem::Requirement
32
33
  requirements:
33
- - - "~>"
34
+ - - ~>
34
35
  - !ruby/object:Gem::Version
35
36
  version: '0.9'
36
37
  type: :runtime
37
38
  prerelease: false
38
39
  version_requirements: !ruby/object:Gem::Requirement
39
40
  requirements:
40
- - - "~>"
41
+ - - ~>
41
42
  - !ruby/object:Gem::Version
42
43
  version: '0.9'
43
44
  - !ruby/object:Gem::Dependency
44
45
  name: multipart-post
45
46
  requirement: !ruby/object:Gem::Requirement
46
47
  requirements:
47
- - - ">="
48
+ - - '>='
48
49
  - !ruby/object:Gem::Version
49
50
  version: '0'
50
51
  type: :runtime
51
52
  prerelease: false
52
53
  version_requirements: !ruby/object:Gem::Requirement
53
54
  requirements:
54
- - - ">="
55
+ - - '>='
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0'
57
58
  - !ruby/object:Gem::Dependency
58
59
  name: mime-types
59
60
  requirement: !ruby/object:Gem::Requirement
60
61
  requirements:
61
- - - ">="
62
+ - - '>='
62
63
  - !ruby/object:Gem::Version
63
64
  version: '0'
64
65
  type: :runtime
65
66
  prerelease: false
66
67
  version_requirements: !ruby/object:Gem::Requirement
67
68
  requirements:
68
- - - ">="
69
+ - - '>='
69
70
  - !ruby/object:Gem::Version
70
71
  version: '0'
71
72
  - !ruby/object:Gem::Dependency
72
73
  name: rspec
73
74
  requirement: !ruby/object:Gem::Requirement
74
75
  requirements:
75
- - - "~>"
76
+ - - ~>
76
77
  - !ruby/object:Gem::Version
77
- version: '3'
78
+ version: '3.6'
78
79
  type: :development
79
80
  prerelease: false
80
81
  version_requirements: !ruby/object:Gem::Requirement
81
82
  requirements:
82
- - - "~>"
83
+ - - ~>
83
84
  - !ruby/object:Gem::Version
84
- version: '3'
85
+ version: '3.6'
85
86
  - !ruby/object:Gem::Dependency
86
87
  name: rake
87
88
  requirement: !ruby/object:Gem::Requirement
88
89
  requirements:
89
- - - ">="
90
+ - - '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  type: :development
93
94
  prerelease: false
94
95
  version_requirements: !ruby/object:Gem::Requirement
95
96
  requirements:
96
- - - ">="
97
+ - - '>='
97
98
  - !ruby/object:Gem::Version
98
99
  version: '0'
99
100
  - !ruby/object:Gem::Dependency
100
101
  name: pry
101
102
  requirement: !ruby/object:Gem::Requirement
102
103
  requirements:
103
- - - ">="
104
+ - - '>='
104
105
  - !ruby/object:Gem::Version
105
106
  version: '0'
106
107
  type: :development
107
108
  prerelease: false
108
109
  version_requirements: !ruby/object:Gem::Requirement
109
110
  requirements:
110
- - - ">="
111
+ - - '>='
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
113
- description: " Ruby wrapper for Uploadcare service API. \n
114
- \ Full documentations on APIs can be found\n at
115
- https://uploadcare.com/documentation/rest/\n and https://uploadcare.com/documentation/upload/\n"
114
+ description: |2
115
+ Ruby wrapper for Uploadcare service API.
116
+ Full documentations on APIs can be found
117
+ at https://uploadcare.com/documentation/rest/
118
+ and https://uploadcare.com/documentation/upload/
116
119
  email:
117
120
  - hello@uploadcare.com
118
121
  executables: []
119
122
  extensions: []
120
123
  extra_rdoc_files: []
121
124
  files:
122
- - ".DS_Store"
123
- - ".gitignore"
124
- - ".travis.yml"
125
+ - .DS_Store
126
+ - .gitignore
127
+ - .rspec
128
+ - .travis.yml
125
129
  - CHANGELOG.md
126
130
  - Gemfile
127
131
  - LICENSE
128
132
  - README.md
129
133
  - Rakefile
134
+ - UPGRADE_NOTES.md
130
135
  - lib/uploadcare.rb
131
136
  - lib/uploadcare/api.rb
132
137
  - lib/uploadcare/api/file_api.rb
133
138
  - lib/uploadcare/api/file_list_api.rb
139
+ - lib/uploadcare/api/file_storage_api.rb
134
140
  - lib/uploadcare/api/group_api.rb
135
141
  - lib/uploadcare/api/group_list_api.rb
136
142
  - lib/uploadcare/api/project_api.rb
137
143
  - lib/uploadcare/api/raw_api.rb
138
144
  - lib/uploadcare/api/uploading_api.rb
145
+ - lib/uploadcare/api/uploading_api/upload_params.rb
146
+ - lib/uploadcare/api/validators/file_list_options_validator.rb
147
+ - lib/uploadcare/api/validators/group_list_options_validator.rb
139
148
  - lib/uploadcare/errors/errors.rb
140
149
  - lib/uploadcare/resources/file.rb
141
150
  - lib/uploadcare/resources/file_list.rb
142
151
  - lib/uploadcare/resources/group.rb
143
152
  - lib/uploadcare/resources/group_list.rb
144
153
  - lib/uploadcare/resources/project.rb
154
+ - lib/uploadcare/resources/resource_list.rb
145
155
  - lib/uploadcare/rest/auth/auth.rb
146
156
  - lib/uploadcare/rest/auth/secure.rb
147
157
  - lib/uploadcare/rest/auth/simple.rb
@@ -151,9 +161,13 @@ files:
151
161
  - lib/uploadcare/rest/middlewares/parse_json_middleware.rb
152
162
  - lib/uploadcare/rest/middlewares/raise_error_middleware.rb
153
163
  - lib/uploadcare/utils/parser.rb
154
- - lib/uploadcare/utils/user_agent.rb
155
164
  - lib/uploadcare/version.rb
165
+ - spec/api/file_list_api_spec.rb
166
+ - spec/api/file_storage_api_spec.rb
167
+ - spec/api/group_list_api_spec.rb
156
168
  - spec/api/raw_api_spec.rb
169
+ - spec/api/uploading_api/upload_params_spec.rb
170
+ - spec/api/uploading_api_spec.rb
157
171
  - spec/resources/file_list_spec.rb
158
172
  - spec/resources/file_spec.rb
159
173
  - spec/resources/group_list_spec.rb
@@ -165,12 +179,10 @@ files:
165
179
  - spec/rest/auth/simple_spec.rb
166
180
  - spec/rest/errors_spec.rb
167
181
  - spec/rest/upload_connection_spec.rb
182
+ - spec/shared/resource_list.rb
168
183
  - spec/spec_helper.rb
169
184
  - spec/uploadcare_spec.rb
170
- - spec/uploading/uploading_multiple_spec.rb
171
- - spec/uploading/uploading_spec.rb
172
185
  - spec/utils/parser_spec.rb
173
- - spec/utils/user_agent_spec.rb
174
186
  - spec/view.png
175
187
  - spec/view2.jpg
176
188
  - uploadcare-ruby.gemspec
@@ -186,22 +198,27 @@ require_paths:
186
198
  - lib
187
199
  required_ruby_version: !ruby/object:Gem::Requirement
188
200
  requirements:
189
- - - ">="
201
+ - - '>='
190
202
  - !ruby/object:Gem::Version
191
203
  version: '0'
192
204
  required_rubygems_version: !ruby/object:Gem::Requirement
193
205
  requirements:
194
- - - ">="
206
+ - - '>='
195
207
  - !ruby/object:Gem::Version
196
208
  version: '0'
197
209
  requirements: []
198
210
  rubyforge_project:
199
- rubygems_version: 2.7.7
211
+ rubygems_version: 2.0.14.1
200
212
  signing_key:
201
213
  specification_version: 4
202
214
  summary: Ruby gem for Uploadcare
203
215
  test_files:
216
+ - spec/api/file_list_api_spec.rb
217
+ - spec/api/file_storage_api_spec.rb
218
+ - spec/api/group_list_api_spec.rb
204
219
  - spec/api/raw_api_spec.rb
220
+ - spec/api/uploading_api/upload_params_spec.rb
221
+ - spec/api/uploading_api_spec.rb
205
222
  - spec/resources/file_list_spec.rb
206
223
  - spec/resources/file_spec.rb
207
224
  - spec/resources/group_list_spec.rb
@@ -213,11 +230,9 @@ test_files:
213
230
  - spec/rest/auth/simple_spec.rb
214
231
  - spec/rest/errors_spec.rb
215
232
  - spec/rest/upload_connection_spec.rb
233
+ - spec/shared/resource_list.rb
216
234
  - spec/spec_helper.rb
217
235
  - spec/uploadcare_spec.rb
218
- - spec/uploading/uploading_multiple_spec.rb
219
- - spec/uploading/uploading_spec.rb
220
236
  - spec/utils/parser_spec.rb
221
- - spec/utils/user_agent_spec.rb
222
237
  - spec/view.png
223
238
  - spec/view2.jpg