ucloud_api 0.0.4 → 0.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: 5c16ec3171741a707d8c90935f23adb7d6247980
4
- data.tar.gz: 99ac80bd9fb69a049da70ece285d2df390e804b0
3
+ metadata.gz: b8c8c290d068269a4029f53ce70c32346a9f8f44
4
+ data.tar.gz: e53fb65a84f32b8754efd8bbd7e0d9cc871195fb
5
5
  SHA512:
6
- metadata.gz: bc09d2598799c3c1a71ac137071c85ba1cb88ab57c71f5e3562bea21aa001c0cbca653686fe4a676cb101aa0498acc350af2d51cad56b8ce1db10db063682f9c
7
- data.tar.gz: 2f25423569c1630cb6c8b4403fa8a9b3e1e0304adc098d02e09b393aa3ce6b721f773120acd1daf00ed507afc4fc57f43ddf7ffe9354615594f97ac6b4eaad1d
6
+ metadata.gz: e2641498f3d0e6a34a3c33c7d62f047c99bf3337a1b16ecbf16bed5bae9b42bc1547106d983558d55d5746d7d07cbba4b107cbb9b93f8c911f988991fd536c1f
7
+ data.tar.gz: 9f654b32ea14bba2c245df358d04d6341faabcdd8d52d7a42b8efb8c102a1430ecb18f05f4f53f044cc6c690623a8baa7a6274a261b870596fd52b989ce4b8e1
data/lib/ucloud_api.rb CHANGED
@@ -1,62 +1,4 @@
1
-
1
+ $:.unshift(File.dirname(__FILE__))
2
2
  require "ucloud_api/version"
3
- require 'base64'
4
- require 'openssl'
5
- require 'addressable/uri'
6
- require 'httparty'
7
-
8
- module UcloudApi
9
-
10
- class Client
11
- include HTTParty
12
- base_uri 'https://api.ucloudbiz.olleh.com/server/v1/client'
13
- format :json # spechify resonse format
14
-
15
- # debug_output $stderr
16
-
17
- def initialize(apikey=nil, secretkey=nil)
18
- @apikey = apikey || ENV["UCLOUDAPIKEY"]
19
- @secretkey = secretkey || ENV["UCLOUDSECRET"]
20
- end
21
-
22
- def raw_cmd options={}
23
- uri = Addressable::URI.new
24
- hashable_opt = options.merge( {:apiKey => @apikey, :response=>"json"} )
25
- uri.query_values = hashable_opt.sort
26
- hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), uri.query.downcase, @secretkey)
27
- signature = Base64.encode64("#{OpenSSL::HMAC.digest('sha1', @secretkey, uri.query.downcase)}")[0..-2]
28
- query = options.merge( {:response=>"json", :apiKey=>@apikey, :signature => signature } )
29
- self.class.get "/api" , :query => query
30
- end
31
-
32
- def self.list_styled command, listname
33
- class_eval <<"EOD"
34
- def #{command}(*args, &block)
35
- h = Hash[*args]
36
- h[:command] = "#{command}"
37
- response = raw_cmd(h)
38
- list = response.parsed_response["#{command.to_s.downcase}response"]["#{listname}"]
39
- yield(list) if block_given?
40
- list
41
- end
42
- EOD
43
- end
44
-
45
- list_styled "listAvailableProductTypes", "producttypes"
46
- list_styled "listVirtualMachines", "virtualmachine"
47
- list_styled "listTemplates", "template"
48
- list_styled "listZones", "zone"
49
- list_styled "listNetworks", "network"
50
-
51
- # def method_missing m, *args, &block
52
- # h = Hash[*args]
53
- # h[:command] = m.to_s
54
- # response = raw_cmd(h)
55
- # r = response.parsed_response["#{m.to_s.downcase}response"]
56
- # yield(r) if block_given?
57
- # r
58
- # end
59
-
60
- end
61
-
62
- end
3
+ require "ucloud_api/client"
4
+ require "ucloud_api/storage"
@@ -0,0 +1,63 @@
1
+
2
+ require 'base64'
3
+ require 'openssl'
4
+ require 'addressable/uri'
5
+ require 'httparty'
6
+
7
+ module UcloudApi
8
+
9
+ class Client
10
+ include HTTParty
11
+ base_uri 'https://api.ucloudbiz.olleh.com/server/v1/client'
12
+ format :json # specify resonse format
13
+
14
+ # debug_output $stderr
15
+
16
+ def initialize(apikey=nil, secretkey=nil)
17
+ @apikey = apikey || ENV["UCLOUDAPIKEY"]
18
+ @secretkey = secretkey || ENV["UCLOUDSECRET"]
19
+ end
20
+
21
+ def raw_cmd options={}
22
+ uri = Addressable::URI.new
23
+ hashable_opt = options.merge( {:apiKey => @apikey, :response=>"json"} )
24
+ uri.query_values = hashable_opt.sort
25
+ hmac = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), uri.query.downcase, @secretkey)
26
+ signature = Base64.encode64("#{OpenSSL::HMAC.digest('sha1', @secretkey, uri.query.downcase)}")[0..-2]
27
+ query = options.merge( {:response=>"json", :apiKey=>@apikey, :signature => signature } )
28
+ self.class.get "/api" , :query => query
29
+ end
30
+
31
+ def self.list_styled command, listname
32
+ class_eval <<"EOD"
33
+ def #{command}(*args, &block)
34
+ h = Hash[*args]
35
+ h[:command] = "#{command}"
36
+ response = raw_cmd(h)
37
+ list = response.parsed_response["#{command.to_s.downcase}response"]["#{listname}"]
38
+ yield(list) if block_given?
39
+ list
40
+ end
41
+ EOD
42
+ end
43
+
44
+ list_styled "listAvailableProductTypes", "producttypes"
45
+ list_styled "listVirtualMachines", "virtualmachine"
46
+ list_styled "listVolumes", "volume"
47
+ list_styled "listSnapshots", "snapshot"
48
+ list_styled "listTemplates", "template"
49
+ list_styled "listZones", "zone"
50
+ list_styled "listNetworks", "network"
51
+
52
+ # def method_missing m, *args, &block
53
+ # h = Hash[*args]
54
+ # h[:command] = m.to_s
55
+ # response = raw_cmd(h)
56
+ # r = response.parsed_response["#{m.to_s.downcase}response"]
57
+ # yield(r) if block_given?
58
+ # r
59
+ # end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,82 @@
1
+ require 'uri'
2
+ require 'httparty'
3
+
4
+ module UcloudApi
5
+
6
+ class Storage
7
+ include HTTParty
8
+
9
+ format :json # specify resonse format
10
+
11
+ # debug_output $stderr
12
+
13
+ def initialize(user=nil, pass=nil)
14
+ @user = user || ENV["UCLOUD_STORAGE_USER"]
15
+ @pass = pass || ENV["UCLOUD_STORAGE_PASS"]
16
+ end
17
+
18
+ def auth
19
+ auth_url = 'https://api.ucloudbiz.olleh.com/storage/v1/auth'
20
+ response = self.class.get auth_url , :headers => { "X-Storage-User" => @user, "X-Storage-Pass"=> @pass }
21
+ headers = response.headers
22
+ @storage_url = headers["X-Storage-Url"]
23
+ @auth_token = headers["X-Auth-Token"]
24
+ response
25
+ end
26
+
27
+ # http://developer.ucloudbiz.olleh.com/doc/swift/Account/GET-Storage-account/
28
+ def get path, options = {}
29
+ url = File.join @storage_url,path
30
+ params = { format: "json" }.merge options
31
+ response = self.class.get url, :query => params, :headers=> {"X-Auth-Token"=> @auth_token}
32
+ response.parsed_response
33
+ end
34
+
35
+ def head path, options = {}
36
+ url = File.join @storage_url,path
37
+ params = { format: "json" }.merge options
38
+ self.class.head url, :query => params, :headers=> {"X-Auth-Token"=> @auth_token}
39
+ end
40
+
41
+
42
+ end
43
+
44
+
45
+ class StorageReseller
46
+ include HTTParty
47
+
48
+ format :json # specify resonse format
49
+
50
+ # debug_output $stderr
51
+
52
+ def initialize(reseller_admin_user=nil, reseller_admin_pass=nil, reseller_user = nil)
53
+ @reseller_admin = reseller_admin_user || ENV["UCLOUD_STORAGE_RESELLER_ADMIN"]
54
+ @reseller_admin_pass = reseller_admin_pass || ENV["UCLOUD_STORAGE_RESELLER_ADMIN_PASS"]
55
+ @reseller_user = reseller_user || ENV["UCLOUD_STORAGE_RESELLER_USER"]
56
+ end
57
+
58
+ def auth
59
+ auth_url = 'https://api.ucloudbiz.olleh.com/storage/v1/auth'
60
+ headers = {
61
+ "X-Storage-User" => "#@reseller_user:#@reseller_admin",
62
+ "X-Storage-Pass"=> @reseller_admin_pass }
63
+ response = self.class.get auth_url , :headers => headers
64
+ headers = response.headers
65
+ @storage_url = headers["X-Storage-Url"]
66
+ @auth_token = headers["X-Auth-Token"]
67
+ response
68
+ end
69
+
70
+ def add_user user, pass
71
+ auth_url = File.join "https://ssproxy.ucloudbiz.olleh.com", "/auth/v2/#@reseller_user/#{user}"
72
+ #auth_url = "https://api.ucloudbiz.olleh.com/v2/#@reseller_user/#{user}"
73
+ headers = {
74
+ "X-Auth-Admin-User" => @reseller_admin,
75
+ "X-Auth-Admin-Key" => @reseller_admin_pass,
76
+ "X-Auth-User-Key" => pass }
77
+ self.class.put auth_url, :headers => headers
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -1,3 +1,3 @@
1
1
  module UcloudApi
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ucloud_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - BJ Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-20 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -51,6 +51,8 @@ files:
51
51
  - README.md
52
52
  - Rakefile
53
53
  - lib/ucloud_api.rb
54
+ - lib/ucloud_api/client.rb
55
+ - lib/ucloud_api/storage.rb
54
56
  - lib/ucloud_api/version.rb
55
57
  - ucloud_api.gemspec
56
58
  homepage: https://github.com/burnsssun/ucloud_api