rabbit_swift 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f29d05a174b2ea4d31afcf8552715836e6fc5c39
4
+ data.tar.gz: 1131b4980efa6dbc9e3e64af150b7136016ebda6
5
+ SHA512:
6
+ metadata.gz: e1a3cb2e388d621e28225786e5e9453dc2cd6620fb14e4031873d35dd17189048ada63eaa4137b46b5fd855a77fa34c63e56ae0930f4bb6282fc99a7727b0654
7
+ data.tar.gz: 13cf613cf9583e9b1dac6948ced65e006b2d0a9f97be82ad397e6d6721550b87245e7bfa911e3463f1596e8b307ab82d4cfc801e677878f7d02ac2a26b92b17c
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rabbit_swift.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 AKB428
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,56 @@
1
+ # RabbitSwift
2
+
3
+ OpenStack Swift Simple Client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rabbit_swift'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rabbit_swift
20
+
21
+ ## Usage
22
+
23
+ ### Set server information
24
+
25
+ ```ruby
26
+ swift_conf = {
27
+ auth_url: "https://ident-r1nd9999.cnode.jp/v2.0/tokens",
28
+ tenantName: "1234567",
29
+ username: "chino",
30
+ password: "password"
31
+ }
32
+ ```
33
+
34
+ ### Get token
35
+
36
+ rabbit_swift_client = RabbitSwift::Client.new(swift_conf);
37
+ token = rabbit_swift_client.get_token
38
+
39
+ ### Upload File or Folder
40
+
41
+ //dest_url = ex) https://objectstore-r1nd1111.cnode.jp/v1/XXXXXXXXXXX/container_name
42
+ status = rabbit_swift_client.upload(token, dest_url, src_file_path)
43
+
44
+ ### Check Result
45
+ if (status == RabbitSwift::Client::UPLOAD_SUCCESS_HTTP_STATUS_CODE)
46
+ puts "upload success!"
47
+ end
48
+
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/AKB428/rabbit_swift/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require "rabbit_swift/version"
2
+ require "rabbit_swift/client"
3
+
4
+ module RabbitSwift
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,108 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'httpclient'
5
+ require 'pathname'
6
+
7
+ module RabbitSwift
8
+
9
+ class Client
10
+
11
+ UPLOAD_SUCCESS_HTTP_STATUS_CODE = 201
12
+
13
+ def initialize(opt)
14
+ @auth_url = opt['auth_url']
15
+ @tenantName = opt['tenantName']
16
+ @username = opt['username']
17
+ @password = opt['password']
18
+ end
19
+
20
+ #curl -i 'https://********.jp/v2.0/tokens' -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"auth": {"tenantName": "1234567", "passwordCredentials": {"username": "1234567", "password": "************"}}}'
21
+ def get_token
22
+ body = build_auth_json
23
+
24
+ http_client = HTTPClient.new
25
+ response = http_client.post_content(@auth_url, body, 'Content-Type' => 'application/json')
26
+ response_json_body = JSON.load(response)
27
+
28
+ response_json_body['access']['token']['id']
29
+ end
30
+
31
+ # curl -i -X PUT -H "X-Auth-Token: トークン" オブジェクトストレージエンドポイント/コンテナ名/ -T オブジェクトへのパス
32
+ def upload(token, end_point, input_file_path)
33
+ auth_header = {
34
+ 'X-Auth-Token' => token
35
+ }
36
+
37
+ #相対パスがきた時のために絶対パスに変換
38
+ path_name_obj = Pathname.new(input_file_path);
39
+ file_path = path_name_obj.expand_path.to_s
40
+
41
+ http_client = HTTPClient.new
42
+
43
+ target_url = add_filename_to_url(end_point, file_path)
44
+
45
+ puts 'upload_url -> ' + target_url
46
+
47
+ if File::ftype(file_path) == 'directory'
48
+ auth_header = {
49
+ 'X-Auth-Token' => token,
50
+ 'Content-Type' => 'application/directory',
51
+ 'Content-Length' => 0
52
+ }
53
+ @res = http_client.put(URI.parse(URI.encode(target_url)), file_path, auth_header)
54
+ if @res.status == UPLOAD_SUCCESS_HTTP_STATUS_CODE
55
+ Dir::foreach(file_path) {|f|
56
+ next if (f == '.' || f == '..')
57
+ begin
58
+ child_path = path_name_obj.join(f)
59
+ # 再帰
60
+ upload(token, end_point + '/' +File::basename(file_path), child_path)
61
+ rescue => e
62
+ puts e
63
+ end
64
+ }
65
+ end
66
+ else
67
+ File.open(file_path) do |file|
68
+ @res = http_client.put(URI.parse(URI.encode(target_url)), file, auth_header)
69
+ end
70
+ end
71
+
72
+ #p @res
73
+ @res.status
74
+ end
75
+
76
+ private
77
+
78
+ def build_auth_json
79
+ auth_json = {
80
+ auth: {
81
+ tenantName: @tenantName,
82
+ passwordCredentials: {
83
+ username: @username,
84
+ password: @password
85
+ }
86
+ }
87
+ }
88
+ JSON.dump(auth_json)
89
+ end
90
+
91
+ #URLにファイル名を付与
92
+ def add_filename_to_url(url, file_path)
93
+ filename = File::basename(file_path)
94
+
95
+ decorate_url = nil
96
+
97
+ if /\/$/ =~ url
98
+ decorate_url = url + filename
99
+ else
100
+ decorate_url = url + '/' + filename
101
+ end
102
+
103
+ return decorate_url
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,3 @@
1
+ module RabbitSwift
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rabbit_swift/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rabbit_swift"
8
+ spec.version = RabbitSwift::VERSION
9
+ spec.authors = ["AKB428"]
10
+ spec.email = ["otoraru@gmail.com"]
11
+ spec.summary = %q{OpenStack Swift Simple Client}
12
+ spec.description = %q{OpenStack Swift Simple Client. main target for "ConoHa VPS"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency 'httpclient'
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit_swift
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - AKB428
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httpclient
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: OpenStack Swift Simple Client. main target for "ConoHa VPS"
56
+ email:
57
+ - otoraru@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rabbit_swift.rb
68
+ - lib/rabbit_swift/client.rb
69
+ - lib/rabbit_swift/version.rb
70
+ - rabbit_swift.gemspec
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: OpenStack Swift Simple Client
95
+ test_files: []