uploadcare-ruby 1.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+ require 'socket'
4
+
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
10
+ end
11
+
12
+ it "freshly uploaded file should have empty operations list" do
13
+ @file.should respond_to :operations
14
+ @file.operations.should be_kind_of(Array)
15
+ @file.operations.should be_empty
16
+ end
17
+
18
+ it "file created from uuid should be not loaded and without operations" do
19
+ file = @api.file @file.uuid
20
+ file.is_loaded?.should be_false
21
+ file.operations.should be_empty
22
+ end
23
+
24
+ it "file created from url without operations should be not be loaded and have no operations" do
25
+ file = @api.file @file.cdn_url
26
+ file.is_loaded?.should be_false
27
+ file.operations.should be_empty
28
+ end
29
+
30
+ it "file created from url with operations should be not be loaded and have operations" do
31
+ file = @api.file @file.cdn_url + "-/crop/150x150/center/-/format/png/"
32
+ file.is_loaded?.should be_false
33
+ file.operations.should_not be_empty
34
+ end
35
+
36
+ it "file should have methods for construct cdn urls with or without cdn operations" do
37
+ @file.should respond_to(:cdn_url_with_operations)
38
+ @file.should respond_to(:cdn_url_without_operations)
39
+ end
40
+
41
+ it "file should construct cdn_url with and without opreations" do
42
+ url_without_operations = @file.cdn_url
43
+ url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
44
+
45
+ file = @api.file url_with_operations
46
+
47
+ file.cdn_url.should == (url_without_operations)
48
+ file.cdn_url(true).should == (url_with_operations)
49
+ end
50
+
51
+ it 'should works also with exact methods' do
52
+ url_without_operations = @file.cdn_url.to_s
53
+ url_with_operations = @file.cdn_url + "-/crop/150x150/center/-/format/png/"
54
+
55
+ file = @api.file url_with_operations
56
+
57
+ file.cdn_url_with_operations.should == (url_with_operations)
58
+ file.cdn_url_without_operations.should == (url_without_operations)
59
+ end
60
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Uploadcare::Api::File do
4
+ before :each do
5
+ # http://www.ucarecdn.com/be4e24fb-2cad-476f-9417-ba95e3fefbf2~3/-/crop/123/-/fromat/png/
6
+ @uuid = "be4e24fb-2cad-476f-9417-ba95e3fefbf2"
7
+ @count = "12"
8
+ @operations = "-/crop/123/-/fromat/png/"
9
+ end
10
+
11
+ it "should parse file uuid string" do
12
+ string = "#{@uuid}"
13
+
14
+ parsed = Uploadcare::Parser.parse(string)
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
21
+ end
22
+
23
+ it "should parse file cdn string without operations string" do
24
+ string = "http://www.ucarecdn.com/#{@uuid}/"
25
+
26
+ parsed = Uploadcare::Parser.parse(string)
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
33
+ end
34
+
35
+ it "should parse file cdn string with operations string" do
36
+ string = "http://www.ucarecdn.com/#{@uuid}/#{@operations}"
37
+
38
+ parsed = Uploadcare::Parser.parse(string)
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
45
+ end
46
+
47
+ it "should parse group uuid string" do
48
+ string = "#{@uuid}~#{@count}"
49
+
50
+ parsed = Uploadcare::Parser.parse(string)
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
58
+ end
59
+
60
+ it "should parse file cdn string without operations string" do
61
+ string = "http://www.ucarecdn.com/#{@uuid}~#{@count}/"
62
+
63
+ parsed = Uploadcare::Parser.parse(string)
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
71
+ end
72
+
73
+ it "should parse file cdn string with operations string" do
74
+ string = "http://www.ucarecdn.com/#{@uuid}~#{@count}/#{@operations}"
75
+
76
+ parsed = Uploadcare::Parser.parse(string)
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
84
+ end
85
+
86
+
87
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+ require 'socket'
4
+
5
+ describe Uploadcare::Api::Project do
6
+ before :each do
7
+ @api = Uploadcare::Api.new(CONFIG)
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
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+ require 'socket'
4
+
5
+ describe Uploadcare::Api do
6
+ before :each do
7
+ @api = Uploadcare::Api.new(CONFIG)
8
+ end
9
+
10
+ it "should initialize api" do
11
+ @api.should be_an_instance_of(Uploadcare::Api)
12
+ end
13
+
14
+ it 'should respond to request methods' do
15
+ @api.should respond_to :request
16
+ @api.should respond_to :get
17
+ @api.should respond_to :post
18
+ @api.should respond_to :put
19
+ @api.should respond_to :delete
20
+ end
21
+
22
+ it 'should perform custom requests' do
23
+ expect { @api.request }.to_not raise_error
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'pry'
6
+ require 'rspec'
7
+ require 'uploadcare'
8
+ require 'yaml'
9
+
10
+ CONFIG = Uploadcare.default_settings
11
+ UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
12
+
13
+ config_file = File.join(File.dirname(__FILE__), 'config.yml')
14
+ if File.exists?(config_file)
15
+ CONFIG.update Hash[YAML.parse_file(config_file).to_ruby.map{|a, b| [a.to_sym, b]}]
16
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+ require 'socket'
4
+
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]
11
+ end
12
+
13
+ it "it should upload multiple files" do
14
+ expect {files = @api.upload @files_ary}.to_not raise_error
15
+ end
16
+
17
+ it "should retunrn an array of files" do
18
+ files = @api.upload @files_ary
19
+ files.should be_kind_of(Array)
20
+ end
21
+
22
+ it "each in array should be UC file object" do
23
+ files = @api.upload @files_ary
24
+ files.each do |f|
25
+ f.should be_kind_of(Uploadcare::Api::File)
26
+ end
27
+ end
28
+
29
+ it "each in array should have valid UUID" do
30
+ files = @api.upload @files_ary
31
+ files.each do |f|
32
+ f.should respond_to(:uuid)
33
+ f.uuid.should match(UUID_REGEX)
34
+ end
35
+ end
36
+
37
+ it "each in array should load data for uploaded file" do
38
+ files = @api.upload @files_ary
39
+ files.each do |f|
40
+ f.should respond_to(:load_data)
41
+ expect {f.load_data}.to_not raise_error
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'uri'
3
+ require 'socket'
4
+
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"
10
+ end
11
+
12
+ it 'should upload file or url' do
13
+ file = @api.upload @file
14
+ file.should be_an_instance_of Uploadcare::Api::File
15
+ end
16
+
17
+ it 'should raise an error when neither file nor url given' do
18
+ expect { @api.upload 12 }.to raise_error
19
+ end
20
+
21
+ it 'should upload file' do
22
+ file = @api.upload @file
23
+ file.should be_an_instance_of Uploadcare::Api::File
24
+ end
25
+
26
+ it 'should upload from url' do
27
+ file = @api.upload @url
28
+ file.should be_an_instance_of Uploadcare::Api::File
29
+ end
30
+
31
+ it 'should not upload from invalid url' do
32
+ expect { @api.upload 'not.url.' }.to raise_error
33
+ end
34
+
35
+ it 'uploaded file should have valid UUID' do
36
+ file = @api.upload @url
37
+ file.should be_an_instance_of Uploadcare::Api::File
38
+ file.uuid.should match UUID_REGEX
39
+ end
40
+ end
Binary file
Binary file
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/uploadcare/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "uploadcare-ruby"
6
+ gem.authors = ["@rastyagaev (Vadim Rastyagaev)",
7
+ "@dimituri (Dimitry Solovyov)",
8
+ "@romanonthego (Roman Dubinin)"]
9
+ gem.email = ["hello@uploadcare.com"]
10
+ gem.summary = "Ruby gem for Uploadcare"
11
+ gem.description = <<-EOF
12
+ Ruby wrapper for Uploadcare service API.
13
+ Full documentations on api can be found
14
+ at https://uploadcare.com/documentation/rest/
15
+ EOF
16
+ gem.metadata = {
17
+ "github" => "https://github.com/uploadcare/uploadcare-ruby",
18
+ "issue_tracker" => "https://github.com/uploadcare/uploadcare-ruby/issues"
19
+ }
20
+ gem.homepage = "https://uploadcare.com/documentation/libs/"
21
+ gem.license = "MIT"
22
+
23
+ gem.files = `git ls-files`.split($\)
24
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
25
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
26
+ gem.require_paths = ["lib"]
27
+ gem.version = Uploadcare::VERSION
28
+ gem.add_runtime_dependency 'faraday'
29
+ gem.add_runtime_dependency 'faraday_middleware'
30
+ gem.add_runtime_dependency 'multipart-post'
31
+ gem.add_runtime_dependency 'mime-types'
32
+
33
+ gem.add_development_dependency 'rspec'
34
+ gem.add_development_dependency 'pry'
35
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uploadcare-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1.rc1
5
+ platform: ruby
6
+ authors:
7
+ - '@rastyagaev (Vadim Rastyagaev)'
8
+ - '@dimituri (Dimitry Solovyov)'
9
+ - '@romanonthego (Roman Dubinin)'
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-12-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: faraday_middleware
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: multipart-post
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: mime-types
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: pry
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: " Ruby wrapper for Uploadcare service API. \n
100
+ \ Full documentations on api can be found \n at
101
+ https://uploadcare.com/documentation/rest/\n"
102
+ email:
103
+ - hello@uploadcare.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - .DS_Store
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/uploadcare.rb
115
+ - lib/uploadcare/api.rb
116
+ - lib/uploadcare/api/connections.rb
117
+ - lib/uploadcare/api/file_api.rb
118
+ - lib/uploadcare/api/file_list_api.rb
119
+ - lib/uploadcare/api/group_api.rb
120
+ - lib/uploadcare/api/group_list_api.rb
121
+ - lib/uploadcare/api/parser.rb
122
+ - lib/uploadcare/api/project_api.rb
123
+ - lib/uploadcare/api/raw_api.rb
124
+ - lib/uploadcare/api/uploading_api.rb
125
+ - lib/uploadcare/resources/file.rb
126
+ - lib/uploadcare/resources/file_list.rb
127
+ - lib/uploadcare/resources/group.rb
128
+ - lib/uploadcare/resources/group_list.rb
129
+ - lib/uploadcare/resources/project.rb
130
+ - lib/uploadcare/version.rb
131
+ - spec/file_list_spec.rb
132
+ - spec/file_spec.rb
133
+ - spec/group_list_spec.rb
134
+ - spec/group_spec.rb
135
+ - spec/operations_spec.rb
136
+ - spec/parser_spec.rb
137
+ - spec/project_spec.rb
138
+ - spec/raw_api_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/uploading_multiple_spec.rb
141
+ - spec/uploading_spec.rb
142
+ - spec/view.png
143
+ - spec/view2.jpg
144
+ - uploadcare-ruby.gemspec
145
+ homepage: https://uploadcare.com/documentation/libs/
146
+ licenses:
147
+ - MIT
148
+ metadata:
149
+ github: https://github.com/uploadcare/uploadcare-ruby
150
+ issue_tracker: https://github.com/uploadcare/uploadcare-ruby/issues
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>'
163
+ - !ruby/object:Gem::Version
164
+ version: 1.3.1
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.0.6
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Ruby gem for Uploadcare
171
+ test_files:
172
+ - spec/file_list_spec.rb
173
+ - spec/file_spec.rb
174
+ - spec/group_list_spec.rb
175
+ - spec/group_spec.rb
176
+ - spec/operations_spec.rb
177
+ - spec/parser_spec.rb
178
+ - spec/project_spec.rb
179
+ - spec/raw_api_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/uploading_multiple_spec.rb
182
+ - spec/uploading_spec.rb
183
+ - spec/view.png
184
+ - spec/view2.jpg