ucloud_storage 0.0.4

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.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg/
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ spec/fixtures/vcr_cassettes/*
20
+ spec/support/auth_info.yml
data/CHANGELOG ADDED
@@ -0,0 +1,11 @@
1
+ ## v0.0.2
2
+
3
+ * Add runtime_dependency
4
+
5
+ ## v0.0.2
6
+
7
+ * Add Module
8
+
9
+ ## v0.0.1
10
+
11
+ * Initial Release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.3.4)
5
+ crack (0.3.2)
6
+ diff-lcs (1.2.4)
7
+ httparty (0.11.0)
8
+ multi_json (~> 1.0)
9
+ multi_xml (>= 0.5.2)
10
+ multi_json (1.7.2)
11
+ multi_xml (0.5.3)
12
+ rspec (2.13.0)
13
+ rspec-core (~> 2.13.0)
14
+ rspec-expectations (~> 2.13.0)
15
+ rspec-mocks (~> 2.13.0)
16
+ rspec-core (2.13.1)
17
+ rspec-expectations (2.13.0)
18
+ diff-lcs (>= 1.1.3, < 2.0)
19
+ rspec-mocks (2.13.1)
20
+ vcr (2.4.0)
21
+ webmock (1.11.0)
22
+ addressable (>= 2.2.7)
23
+ crack (>= 0.3.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ httparty
30
+ rspec
31
+ vcr
32
+ webmock
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sooyong Wang & KunHa Park
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # UcloudStorage
2
+
3
+ Simple API for ucloud storage
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ucloud_storage'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ucloud_storage
18
+
19
+ ## Usage
20
+
21
+ ucloud = UcloudStorage.new
22
+ ucloud.user = "email"
23
+ ucloud.pass = "API KEY"
24
+ ucloud.authoize
25
+ ucloud.upload(filepath, boxname, destination)
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ require_relative 'ucloud_storage/ucloud_storage'
2
+ require_relative 'ucloud_storage/version'
3
+
4
+ module UcloudStorage
5
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ module UcloudStorage
4
+ class TotalyWrongException < StandardError; end
5
+ class NotAuthorized < StandardError; end
6
+
7
+ class UcloudStorage
8
+ attr_accessor :user, :pass, :storage_url, :auth_token
9
+
10
+ def authorize
11
+ response = HTTParty.get("https://api.ucloudbiz.olleh.com/storage/v1/auth/",
12
+ headers: { "X-Storage-User" => user, "X-Storage-Pass" => pass})
13
+ case response.code
14
+ when 200 then
15
+ self.storage_url = response.headers["X-Storage-Url"]
16
+ self.auth_token = response.headers["X-Auth-Token"]
17
+ true
18
+ when 401 then
19
+ false
20
+ else
21
+ raise TotalyWrongException
22
+ end
23
+ end
24
+
25
+ def upload(file_path, box_name, destination)
26
+ raise NotAuthorized if storage_url.nil?
27
+ file = File.new(file_path)
28
+ contenttype = `file --mime-type #{file_path}`.split(": ").last
29
+ response = HTTParty.put(storage_url+ "/#{box_name}/#{destination}",
30
+ headers: {
31
+ "X-Auth-Token" => auth_token,
32
+ "Content-Type" => contenttype,
33
+ "Content-Length" => file.size.to_s },
34
+ body: file.read)
35
+ case response.code
36
+ when 201 then
37
+ true
38
+ else
39
+ false
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module UcloudStorage
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,4 @@
1
+ VCR.configure do |c|
2
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), "../fixtures/vcr_cassettes")
3
+ c.hook_into :webmock
4
+ end
@@ -0,0 +1,3 @@
1
+ valid_user:
2
+ user: valid_user@mintshop.com
3
+ pass: <API Key HERE>
@@ -0,0 +1,4 @@
1
+ VCR.configure do |c|
2
+ c.cassette_library_dir = File.join(File.dirname(__FILE__), "../fixtures/vcr_cassettes")
3
+ c.hook_into :webmock
4
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require_relative '../lib/ucloud_storage'
3
+ require 'httparty'
4
+ require 'vcr'
5
+ require 'support/vcr'
6
+ require 'yaml'
7
+
8
+ describe UcloudStorage do
9
+ let(:valid_ucloud) do
10
+ ucloud = UcloudStorage::UcloudStorage.new
11
+ file = File.open(File.join(File.dirname(__FILE__), "/support/auth_info.yml"))
12
+ auth_info = YAML.load(file)
13
+ ucloud.user = auth_info["valid_user"]["user"]
14
+ ucloud.pass = auth_info["valid_user"]["pass"]
15
+ ucloud
16
+ end
17
+
18
+ let(:invalid_ucloud) do
19
+ invlaid_ucloud = UcloudStorage::UcloudStorage.new
20
+ invlaid_ucloud.user = "invalid_user@mintshop.com"
21
+ invlaid_ucloud.pass = "please download mintshop"
22
+ invlaid_ucloud
23
+ end
24
+
25
+ it "can authorize with valid user/pass" do
26
+ VCR.use_cassette("storage/v1/auth") do
27
+ valid_ucloud.authorize.should == true
28
+ valid_ucloud.storage_url.should_not be_nil
29
+ valid_ucloud.auth_token.should_not be_nil
30
+ end
31
+ end
32
+
33
+ it "cannot authorize with invalid user/pass" do
34
+ VCR.use_cassette("storage/v1/auth_fail") do
35
+ invalid_ucloud.authorize.should == false
36
+ invalid_ucloud.storage_url.should be_nil
37
+ invalid_ucloud.auth_token.should be_nil
38
+ end
39
+ end
40
+
41
+ it "can upload a file" do
42
+ VCR.use_cassette('storage/v1/auth') do
43
+ valid_ucloud.authorize
44
+ end
45
+
46
+ file_path = File.join(File.dirname(__FILE__), "/fixtures/sample_file.txt")
47
+ box = 'dev'
48
+ destination = 'cropped_images/'+Pathname(file_path).basename.to_s
49
+
50
+ VCR.use_cassette("v1/put_storage_object") do
51
+ valid_ucloud.upload(file_path, box, destination).should be_true
52
+ end
53
+ end
54
+
55
+ it "should fail to upload with invalid file path" do
56
+ VCR.use_cassette('storage/v1/auth') do
57
+ valid_ucloud.authorize
58
+ end
59
+
60
+ file_path = File.join(File.dirname(__FILE__), "/fixtures/no_sample_file.txt")
61
+ box = 'dev'
62
+ destination = 'cropped_images/'+Pathname(file_path).basename.to_s
63
+
64
+ expect {
65
+ valid_ucloud.upload(file_path, box, destination)
66
+ }.to raise_error(Errno::ENOENT)
67
+ end
68
+
69
+ it "should fail to upload without authorization" do
70
+ file_path = File.join(File.dirname(__FILE__), "/fixtures/sample_file.txt")
71
+ box = 'dev'
72
+ destination = 'cropped_images/'+Pathname(file_path).basename.to_s
73
+
74
+ expect {
75
+ valid_ucloud.upload(file_path, box, destination).should be_true
76
+ }.to raise_error(UcloudStorage::NotAuthorized)
77
+ end
78
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ucloud_storage/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sooyong Wang", "Kunha Park"]
6
+ gem.email = ["wangsy@wangsy.com", "potato9@gmail.com"]
7
+ gem.description = %q{ucloud storage API}
8
+ gem.summary = %q{simple API for authorize, upload files}
9
+ gem.homepage = "https://github.com/wangsy/ucloud-storage"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ucloud_storage"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = UcloudStorage::VERSION
17
+
18
+ gem.add_development_dependency "rspec"
19
+ gem.add_development_dependency "vcr"
20
+ gem.add_development_dependency "webmock"
21
+
22
+ gem.add_dependency "httparty"
23
+
24
+ gem.rubyforge_project = "ucloudstorage"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ucloud_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sooyong Wang
9
+ - Kunha Park
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &70224015659260 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *70224015659260
26
+ - !ruby/object:Gem::Dependency
27
+ name: vcr
28
+ requirement: &70224015684140 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70224015684140
37
+ - !ruby/object:Gem::Dependency
38
+ name: webmock
39
+ requirement: &70224015683660 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70224015683660
48
+ - !ruby/object:Gem::Dependency
49
+ name: httparty
50
+ requirement: &70224015683180 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: *70224015683180
59
+ description: ucloud storage API
60
+ email:
61
+ - wangsy@wangsy.com
62
+ - potato9@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - CHANGELOG
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - lib/ucloud_storage.rb
75
+ - lib/ucloud_storage/ucloud_storage.rb
76
+ - lib/ucloud_storage/version.rb
77
+ - spec/fixtures/sample_file.txt
78
+ - spec/support/auth_info.sample.yml
79
+ - spec/support/vcr.rb
80
+ - spec/ucloud_storage_spec.rb
81
+ - ucloud_storage.gemspec
82
+ homepage: https://github.com/wangsy/ucloud-storage
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project: ucloudstorage
102
+ rubygems_version: 1.8.5
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: simple API for authorize, upload files
106
+ test_files:
107
+ - spec/fixtures/sample_file.txt
108
+ - spec/support/auth_info.sample.yml
109
+ - spec/support/vcr.rb
110
+ - spec/ucloud_storage_spec.rb