uploadcare-ruby 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/uploadcare/resources/file.rb +12 -0
- data/lib/uploadcare/resources/project.rb +0 -8
- data/lib/uploadcare/rest/middlewares/parse_json_middleware.rb +3 -1
- data/lib/uploadcare/version.rb +1 -1
- data/spec/{raw_api_spec.rb → api/raw_api_spec.rb} +0 -0
- data/spec/{file_list_spec.rb → resources/file_list_spec.rb} +2 -3
- data/spec/{file_spec.rb → resources/file_spec.rb} +8 -3
- data/spec/{group_list_spec.rb → resources/group_list_spec.rb} +2 -3
- data/spec/{group_spec.rb → resources/group_spec.rb} +3 -6
- data/spec/{operations_spec.rb → resources/operations_spec.rb} +3 -4
- data/spec/{project_spec.rb → resources/project_spec.rb} +2 -2
- data/spec/spec_helper.rb +8 -0
- data/spec/{uploading_multiple_spec.rb → uploading/uploading_multiple_spec.rb} +3 -5
- data/spec/{uploading_spec.rb → uploading/uploading_spec.rb} +4 -4
- data/spec/{parser_spec.rb → utils/parser_spec.rb} +0 -0
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c1df4ed27dd413da0a8aa2bf116fc41a5f59347
|
4
|
+
data.tar.gz: d947913ea623ceeffc06c583b3406e751f59f7c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b84d77ef7cf3b2f8aa0463fc824bbb71ed94c78f75817d5756c108d4296df555e58684eaaf202475792e5d953228729a7606f42697e116dceb2fa619b2037fe0
|
7
|
+
data.tar.gz: 85c71b37914fc456cb2e6b9ef0b4f5d691c68ddaa88c44f00edd42504ed9601362bbbce4b4f2ae34a8e9ed1d1115f543e5e3576b750d2bd2c0a2d81cf605b9fa
|
data/.gitignore
CHANGED
@@ -92,6 +92,18 @@ module Uploadcare
|
|
92
92
|
alias_method :is_removed?, :is_deleted?
|
93
93
|
|
94
94
|
|
95
|
+
# copy file to target location
|
96
|
+
# note what file copied with operations
|
97
|
+
def copy with_operations=true, target=nil
|
98
|
+
data = Hash.new
|
99
|
+
data[:target] = target if target
|
100
|
+
data[:source] = self.cdn_url_with_operations if with_operations
|
101
|
+
data[:source] = self.cdn_url_without_operations unless with_operations
|
102
|
+
|
103
|
+
@api.post "/files/", data
|
104
|
+
end
|
105
|
+
|
106
|
+
|
95
107
|
# Datetime methods
|
96
108
|
# practicly try and parse the string to date objects
|
97
109
|
["original", "uploaded", "stored", "removed"].each do |dt|
|
@@ -7,6 +7,8 @@ module Uploadcare
|
|
7
7
|
class ParseJson < Faraday::Response::Middleware
|
8
8
|
WHITESPACE_REGEX = /\A^\s*$\z/
|
9
9
|
|
10
|
+
ERROR_CODES = [400, 401, 403, 404, 406, 408, 422, 429, 500, 502, 503, 504]
|
11
|
+
|
10
12
|
def parse(body)
|
11
13
|
case body
|
12
14
|
when WHITESPACE_REGEX, nil
|
@@ -17,7 +19,7 @@ module Uploadcare
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def on_complete(response)
|
20
|
-
response[:body] = parse(response[:body]) if respond_to?(:parse) && !(response[:status]
|
22
|
+
response[:body] = parse(response[:body]) if respond_to?(:parse) && !ERROR_CODES.include?(response[:status])
|
21
23
|
end
|
22
24
|
|
23
25
|
def unparsable_status_codes
|
data/lib/uploadcare/version.rb
CHANGED
File without changes
|
@@ -4,9 +4,8 @@ require 'socket'
|
|
4
4
|
|
5
5
|
describe Uploadcare::Api::File do
|
6
6
|
before :each do
|
7
|
-
@api =
|
8
|
-
@
|
9
|
-
@file = @api.upload @url
|
7
|
+
@api = API
|
8
|
+
@file = @api.upload IMAGE_URL
|
10
9
|
end
|
11
10
|
|
12
11
|
it 'file should be an instance of File' do
|
@@ -102,4 +101,10 @@ describe Uploadcare::Api::File do
|
|
102
101
|
@file.datetime_removed.should == @file.datetime_deleted
|
103
102
|
end
|
104
103
|
|
104
|
+
|
105
|
+
it 'should copy itself' do
|
106
|
+
result = @file.copy
|
107
|
+
result.should be_kind_of(Hash)
|
108
|
+
result["type"].should == "file"
|
109
|
+
end
|
105
110
|
end
|
@@ -3,12 +3,9 @@ require 'uri'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
describe Uploadcare::Api::Group do
|
6
|
-
before :
|
7
|
-
@api =
|
8
|
-
@
|
9
|
-
@file2 = File.open(File.join(File.dirname(__FILE__), 'view2.jpg'))
|
10
|
-
@files_ary = [@file, @file2]
|
11
|
-
@files = @api.upload @files_ary
|
6
|
+
before :all do
|
7
|
+
@api = API
|
8
|
+
@files = @api.upload FILES_ARY
|
12
9
|
end
|
13
10
|
|
14
11
|
it "should return group object" do
|
@@ -3,10 +3,9 @@ require 'uri'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
describe Uploadcare::Api::File do
|
6
|
-
before :
|
7
|
-
@api =
|
8
|
-
@
|
9
|
-
@file = @api.upload @url
|
6
|
+
before :all do
|
7
|
+
@api = API
|
8
|
+
@file = @api.upload IMAGE_URL
|
10
9
|
end
|
11
10
|
|
12
11
|
it "freshly uploaded file should have empty operations list" do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,6 +10,14 @@ require 'yaml'
|
|
10
10
|
CONFIG = Uploadcare.default_settings
|
11
11
|
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
|
12
12
|
|
13
|
+
API = Uploadcare::Api.new(CONFIG)
|
14
|
+
IMAGE_URL = "http://macaw.co/images/macaw-logo.png"
|
15
|
+
|
16
|
+
FILE1 = File.open(File.join(File.dirname(__FILE__), 'view.png'))
|
17
|
+
FILE2 = File.open(File.join(File.dirname(__FILE__), 'view2.jpg'))
|
18
|
+
FILES_ARY = [FILE1, FILE2]
|
19
|
+
|
20
|
+
|
13
21
|
config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
14
22
|
if File.exists?(config_file)
|
15
23
|
CONFIG.update Hash[YAML.parse_file(config_file).to_ruby.map{|a, b| [a.to_sym, b]}]
|
@@ -3,11 +3,9 @@ require 'uri'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
describe Uploadcare::Api do
|
6
|
-
before :
|
7
|
-
@api =
|
8
|
-
@
|
9
|
-
@file2 = File.open(File.join(File.dirname(__FILE__), 'view2.jpg'))
|
10
|
-
@files_ary = [@file, @file2]
|
6
|
+
before :all do
|
7
|
+
@api = API
|
8
|
+
@files_ary = FILES_ARY
|
11
9
|
end
|
12
10
|
|
13
11
|
it "it should upload multiple files" do
|
@@ -3,10 +3,10 @@ require 'uri'
|
|
3
3
|
require 'socket'
|
4
4
|
|
5
5
|
describe Uploadcare::Api do
|
6
|
-
before :
|
7
|
-
@api =
|
8
|
-
@file =
|
9
|
-
@url =
|
6
|
+
before :all do
|
7
|
+
@api = API
|
8
|
+
@file = FILE1
|
9
|
+
@url = IMAGE_URL
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should upload file or url' do
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploadcare-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '@rastyagaev (Vadim Rastyagaev)'
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-04-
|
13
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|
@@ -132,20 +132,20 @@ files:
|
|
132
132
|
- lib/uploadcare/rest/middlewares/raise_error_middleware.rb
|
133
133
|
- lib/uploadcare/utils/parser.rb
|
134
134
|
- lib/uploadcare/version.rb
|
135
|
-
- spec/
|
136
|
-
- spec/
|
137
|
-
- spec/
|
138
|
-
- spec/
|
139
|
-
- spec/
|
140
|
-
- spec/
|
141
|
-
- spec/project_spec.rb
|
142
|
-
- spec/raw_api_spec.rb
|
135
|
+
- spec/api/raw_api_spec.rb
|
136
|
+
- spec/resources/file_list_spec.rb
|
137
|
+
- spec/resources/file_spec.rb
|
138
|
+
- spec/resources/group_list_spec.rb
|
139
|
+
- spec/resources/group_spec.rb
|
140
|
+
- spec/resources/operations_spec.rb
|
141
|
+
- spec/resources/project_spec.rb
|
143
142
|
- spec/rest/api_connection_spec.rb
|
144
143
|
- spec/rest/errors_spec.rb
|
145
144
|
- spec/rest/upload_connection_spec.rb
|
146
145
|
- spec/spec_helper.rb
|
147
|
-
- spec/uploading_multiple_spec.rb
|
148
|
-
- spec/uploading_spec.rb
|
146
|
+
- spec/uploading/uploading_multiple_spec.rb
|
147
|
+
- spec/uploading/uploading_spec.rb
|
148
|
+
- spec/utils/parser_spec.rb
|
149
149
|
- spec/view.png
|
150
150
|
- spec/view2.jpg
|
151
151
|
- uploadcare-ruby.gemspec
|
@@ -176,19 +176,19 @@ signing_key:
|
|
176
176
|
specification_version: 4
|
177
177
|
summary: Ruby gem for Uploadcare
|
178
178
|
test_files:
|
179
|
-
- spec/
|
180
|
-
- spec/
|
181
|
-
- spec/
|
182
|
-
- spec/
|
183
|
-
- spec/
|
184
|
-
- spec/
|
185
|
-
- spec/project_spec.rb
|
186
|
-
- spec/raw_api_spec.rb
|
179
|
+
- spec/api/raw_api_spec.rb
|
180
|
+
- spec/resources/file_list_spec.rb
|
181
|
+
- spec/resources/file_spec.rb
|
182
|
+
- spec/resources/group_list_spec.rb
|
183
|
+
- spec/resources/group_spec.rb
|
184
|
+
- spec/resources/operations_spec.rb
|
185
|
+
- spec/resources/project_spec.rb
|
187
186
|
- spec/rest/api_connection_spec.rb
|
188
187
|
- spec/rest/errors_spec.rb
|
189
188
|
- spec/rest/upload_connection_spec.rb
|
190
189
|
- spec/spec_helper.rb
|
191
|
-
- spec/uploading_multiple_spec.rb
|
192
|
-
- spec/uploading_spec.rb
|
190
|
+
- spec/uploading/uploading_multiple_spec.rb
|
191
|
+
- spec/uploading/uploading_spec.rb
|
192
|
+
- spec/utils/parser_spec.rb
|
193
193
|
- spec/view.png
|
194
194
|
- spec/view2.jpg
|