uploadcare-ruby 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13befd5dd6e5faed651bdb5735db6273577ce2da
4
- data.tar.gz: f93c39068ff590a2b0fcd5bb1388b225c477e00f
3
+ metadata.gz: 7c1df4ed27dd413da0a8aa2bf116fc41a5f59347
4
+ data.tar.gz: d947913ea623ceeffc06c583b3406e751f59f7c8
5
5
  SHA512:
6
- metadata.gz: 4138493da1575faba21ed1136845693c540ef97a04f22bde1f1ea27b2f0cbb02d613cdd207afaa09bec01866984451c14aed15e5b3838b6dcd45a49547102588
7
- data.tar.gz: c00dca425022a489b824add52361f82454e79aa8aa51e7afe8e8750ec9ead0145558187b22cb894ddaca46ce93c406a345ab37a9d2c1c9d8fd93babd2c95e7d1
6
+ metadata.gz: b84d77ef7cf3b2f8aa0463fc824bbb71ed94c78f75817d5756c108d4296df555e58684eaaf202475792e5d953228729a7606f42697e116dceb2fa619b2037fe0
7
+ data.tar.gz: 85c71b37914fc456cb2e6b9ef0b4f5d691c68ddaa88c44f00edd42504ed9601362bbbce4b4f2ae34a8e9ed1d1115f543e5e3576b750d2bd2c0a2d81cf605b9fa
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ Gemfile.lock
2
2
  .ruby-gemset
3
3
  .ruby-version
4
4
 
5
+ *.DS_Store
5
6
  *.gem
@@ -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|
@@ -8,14 +8,6 @@ module Uploadcare
8
8
  data = @api.get "/project/"
9
9
  super data
10
10
  end
11
-
12
- # def load data
13
- # if data.respond_to? :each
14
- # data.each do |key, value|
15
- # self.send "#{key}=", value
16
- # end
17
- # end
18
- # end
19
11
  end
20
12
  end
21
13
  end
@@ -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] > 200) #!unparsable_status_codes.include?(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
@@ -1,3 +1,3 @@
1
1
  module Uploadcare
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
File without changes
@@ -3,9 +3,8 @@ require 'uri'
3
3
  require 'socket'
4
4
 
5
5
  describe Uploadcare::Api::File do
6
- before :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @url = "http://macaw.co/images/macaw-logo.png"
6
+ before :all do
7
+ @api = API
9
8
  @list = @api.file_list 1
10
9
  end
11
10
 
@@ -4,9 +4,8 @@ require 'socket'
4
4
 
5
5
  describe Uploadcare::Api::File do
6
6
  before :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @url = "http://macaw.co/images/macaw-logo.png"
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,9 +3,8 @@ require 'uri'
3
3
  require 'socket'
4
4
 
5
5
  describe Uploadcare::Api::File do
6
- before :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @url = "http://macaw.co/images/macaw-logo.png"
6
+ before :all do
7
+ @api = API
9
8
  @list = @api.group_list
10
9
  end
11
10
 
@@ -3,12 +3,9 @@ require 'uri'
3
3
  require 'socket'
4
4
 
5
5
  describe Uploadcare::Api::Group do
6
- before :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @file = File.open(File.join(File.dirname(__FILE__), 'view.png'))
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 :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @url = "http://macaw.co/images/macaw-logo.png"
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
@@ -3,8 +3,8 @@ require 'uri'
3
3
  require 'socket'
4
4
 
5
5
  describe Uploadcare::Api::Project do
6
- before :each do
7
- @api = Uploadcare::Api.new(CONFIG)
6
+ before :all do
7
+ @api = API
8
8
  @project = @api.project
9
9
  end
10
10
 
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 :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @file = File.open(File.join(File.dirname(__FILE__), 'view.png'))
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 :each do
7
- @api = Uploadcare::Api.new(CONFIG)
8
- @file = File.open(File.join(File.dirname(__FILE__), 'view.png'))
9
- @url = "http://macaw.co/images/macaw-logo.png"
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
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-23 00:00:00.000000000 Z
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/file_list_spec.rb
136
- - spec/file_spec.rb
137
- - spec/group_list_spec.rb
138
- - spec/group_spec.rb
139
- - spec/operations_spec.rb
140
- - spec/parser_spec.rb
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/file_list_spec.rb
180
- - spec/file_spec.rb
181
- - spec/group_list_spec.rb
182
- - spec/group_spec.rb
183
- - spec/operations_spec.rb
184
- - spec/parser_spec.rb
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