netstorageapi 0.0.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/akamai/netstorage.rb +133 -131
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c8c3c41f92b0ddb4cb562929eb3692fd7628c2d
4
- data.tar.gz: ac5be83acb9c78c59d2c8e4a369d51aab730992d
3
+ metadata.gz: a99cc7c30421fc23825086161e0e31f8503a6c28
4
+ data.tar.gz: aa3f2f79bbec4a6edd06f66626b36de0d544d8b6
5
5
  SHA512:
6
- metadata.gz: 1802526fdbfee477083cf3773e85c3eb01ff71f1761e9a522e82d860f00992ea622ee626fb5b50463d4dfa8f4e9653a14b1589e1a412701c73ed3e16b8ae4a39
7
- data.tar.gz: fc6a863f02e1e0e7ac96003d73db8fbc33f5957c355a4b20f0adf3675e1ec22f5bfcddfdd1e3b496e43539a0b2126dd0041f76e5dce67c4cc3dcbcacb0b3cc7d
6
+ metadata.gz: ae957130bf15715e95c5e45bb9c7fb7bcc558400a6e786f394c4b5de3e9e0ed20c4447b3bc0c8cbb4e7821f934d2f9a99e0e2e9a8f7279f59f9dd84dc685dc88
7
+ data.tar.gz: ccb4b1288d200974adcce701a7c5e9a679de3a5a8fcc62c893e123b6aea08acfe0fbdd3c1fad205e8aa07bf43686ed1469c7b557eca5c878be616bf7ac6d8d11
@@ -24,158 +24,160 @@ require "openssl"
24
24
  require "uri"
25
25
 
26
26
 
27
- class Netstorage
27
+ module Akamai
28
+ class Netstorage
28
29
 
29
- attr_accessor :hostname, :keyname, :key
30
+ attr_accessor :hostname, :keyname, :key
30
31
 
31
- def initialize(hostname, keyname, key)
32
- @hostname = hostname
33
- @keyname = keyname
34
- @key = key
35
- end
32
+ def initialize(hostname, keyname, key)
33
+ @hostname = hostname
34
+ @keyname = keyname
35
+ @key = key
36
+ end
36
37
 
37
- private
38
-
39
- def _response(request, uri, kwargs)
40
- if kwargs[:action] == "download"
41
- local_destination = kwargs[:destination]
42
- if kwargs[:path]
43
- ns_filename = kwargs[:path][-1] != '/' ? File.basename(kwargs[:path]) : nil
44
- if local_destination == ''
45
- local_destination = ns_filename
46
- elsif File.directory?(local_destination)
47
- local_destination = File.join(local_destination, ns_filename)
38
+ private
39
+
40
+ def _response(request, uri, kwargs)
41
+ if kwargs[:action] == "download"
42
+ local_destination = kwargs[:destination]
43
+ if kwargs[:path]
44
+ ns_filename = kwargs[:path][-1] != '/' ? File.basename(kwargs[:path]) : nil
45
+ if local_destination == ''
46
+ local_destination = ns_filename
47
+ elsif File.directory?(local_destination)
48
+ local_destination = File.join(local_destination, ns_filename)
49
+ end
48
50
  end
49
- end
50
- response = Net::HTTP.start(uri.hostname, uri.port) { |http|
51
- http.request request do |res|
52
- open(local_destination, "wb") do |io|
53
- res.read_body do |chunk|
54
- io.write chunk
51
+ response = Net::HTTP.start(uri.hostname, uri.port) { |http|
52
+ http.request request do |res|
53
+ open(local_destination, "wb") do |io|
54
+ res.read_body do |chunk|
55
+ io.write chunk
56
+ end
55
57
  end
56
58
  end
57
- end
58
- }
59
- elsif kwargs[:action] == "upload"
60
- request.body = File.read(kwargs[:source])
61
- response = Net::HTTP.start(uri.hostname, uri.port) { |http|
62
- http.request(request)
63
- }
64
- else
65
- response = Net::HTTP.start(uri.hostname, uri.port) { |http|
66
- http.request(request)
67
- }
68
- end
69
- return response
70
- end
71
-
72
- def _request(kwargs={})
73
- path = URI::escape(kwargs[:path])
74
- acs_action = "version=1&action=#{kwargs[:action]}"
75
- acs_auth_data = "5, 0.0.0.0, 0.0.0.0, #{Time.now.to_i}, #{Random.rand(100000)}, #{@keyname}"
76
- sign_string = "#{path}\nx-akamai-acs-action:#{acs_action}\n"
77
- message = acs_auth_data + sign_string
78
-
79
- hash_ = OpenSSL::HMAC.digest("sha256", @key, message)
80
- acs_auth_sign = Base64.encode64(hash_).rstrip
81
-
82
- uri = URI("http://#{@hostname}#{path}")
83
- headers = {
84
- 'X-Akamai-ACS-Action' => acs_action,
85
- 'X-Akamai-ACS-Auth-Data' => acs_auth_data,
86
- 'X-Akamai-ACS-Auth-Sign' => acs_auth_sign,
87
- 'Accept-Encoding' => "identity"
88
- }
89
-
90
- if kwargs[:method] == "GET"
91
- request = Net::HTTP::Get.new(uri, initheader=headers)
92
- elsif kwargs[:method] == "POST"
93
- request = Net::HTTP::Post.new(uri, initheader=headers)
94
- elsif kwargs[:method] == "PUT" # Use only upload
95
- request = Net::HTTP::Put.new(uri, initheader=headers)
59
+ }
60
+ elsif kwargs[:action] == "upload"
61
+ request.body = File.read(kwargs[:source])
62
+ response = Net::HTTP.start(uri.hostname, uri.port) { |http|
63
+ http.request(request)
64
+ }
65
+ else
66
+ response = Net::HTTP.start(uri.hostname, uri.port) { |http|
67
+ http.request(request)
68
+ }
69
+ end
70
+ return response
96
71
  end
97
-
98
- response = _response(request, uri, kwargs)
99
72
 
100
- return response.code == "200", response
101
- end
73
+ def _request(kwargs={})
74
+ path = URI::escape(kwargs[:path])
75
+ acs_action = "version=1&action=#{kwargs[:action]}"
76
+ acs_auth_data = "5, 0.0.0.0, 0.0.0.0, #{Time.now.to_i}, #{Random.rand(100000)}, #{@keyname}"
77
+ sign_string = "#{path}\nx-akamai-acs-action:#{acs_action}\n"
78
+ message = acs_auth_data + sign_string
79
+
80
+ hash_ = OpenSSL::HMAC.digest("sha256", @key, message)
81
+ acs_auth_sign = Base64.encode64(hash_).rstrip
82
+
83
+ uri = URI("http://#{@hostname}#{path}")
84
+ headers = {
85
+ 'X-Akamai-ACS-Action' => acs_action,
86
+ 'X-Akamai-ACS-Auth-Data' => acs_auth_data,
87
+ 'X-Akamai-ACS-Auth-Sign' => acs_auth_sign,
88
+ 'Accept-Encoding' => "identity"
89
+ }
102
90
 
103
- public
91
+ if kwargs[:method] == "GET"
92
+ request = Net::HTTP::Get.new(uri, initheader=headers)
93
+ elsif kwargs[:method] == "POST"
94
+ request = Net::HTTP::Post.new(uri, initheader=headers)
95
+ elsif kwargs[:method] == "PUT" # Use only upload
96
+ request = Net::HTTP::Put.new(uri, initheader=headers)
97
+ end
104
98
 
105
- def dir(ns_path)
106
- return _request(action: "dir&format=xml",
107
- method: "GET",
108
- path: ns_path)
109
- end
99
+ response = _response(request, uri, kwargs)
100
+
101
+ return response.code == "200", response
102
+ end
110
103
 
111
- def download(ns_source, local_destination='')
112
- return _request(action: "download",
113
- method: "GET",
114
- path: ns_source,
115
- destination: local_destination)
116
- end
104
+ public
117
105
 
118
- def du(ns_path)
119
- return _request(action: "du&format=xml",
120
- method: "GET",
121
- path: ns_path)
122
- end
106
+ def dir(ns_path)
107
+ return _request(action: "dir&format=xml",
108
+ method: "GET",
109
+ path: ns_path)
110
+ end
123
111
 
124
- def stat(ns_path)
125
- return _request(action: "stat&format=xml",
126
- method: "GET",
127
- path: ns_path)
128
- end
112
+ def download(ns_source, local_destination='')
113
+ return _request(action: "download",
114
+ method: "GET",
115
+ path: ns_source,
116
+ destination: local_destination)
117
+ end
129
118
 
130
- def mkdir(ns_path)
131
- return _request(action: "mkdir",
132
- method: "POST",
133
- path: ns_path)
134
- end
119
+ def du(ns_path)
120
+ return _request(action: "du&format=xml",
121
+ method: "GET",
122
+ path: ns_path)
123
+ end
135
124
 
136
- def rmdir(ns_path)
137
- return _request(action: "rmdir",
138
- method: "POST",
139
- path: ns_path)
140
- end
125
+ def stat(ns_path)
126
+ return _request(action: "stat&format=xml",
127
+ method: "GET",
128
+ path: ns_path)
129
+ end
141
130
 
142
- def mtime(ns_path, mtime)
143
- return _request(action: "mtime&format=xml&mtime=#{mtime}",
144
- method: "POST",
145
- path: ns_path)
146
- end
131
+ def mkdir(ns_path)
132
+ return _request(action: "mkdir",
133
+ method: "POST",
134
+ path: ns_path)
135
+ end
147
136
 
148
- def delete(ns_path)
149
- return _request(action: "delete",
150
- method: "POST",
151
- path: ns_path)
152
- end
137
+ def rmdir(ns_path)
138
+ return _request(action: "rmdir",
139
+ method: "POST",
140
+ path: ns_path)
141
+ end
153
142
 
154
- def quick_delete(ns_path)
155
- return _request(action: "quick-delete&quick-delete=imreallyreallysure",
156
- method: "POST",
157
- path: ns_path)
158
- end
143
+ def mtime(ns_path, mtime)
144
+ return _request(action: "mtime&format=xml&mtime=#{mtime}",
145
+ method: "POST",
146
+ path: ns_path)
147
+ end
159
148
 
160
- def rename(ns_target, ns_destination)
161
- return _request(action: "rename&destination=#{CGI::escape(ns_destination)}",
162
- method: "POST",
163
- path: ns_target)
164
- end
149
+ def delete(ns_path)
150
+ return _request(action: "delete",
151
+ method: "POST",
152
+ path: ns_path)
153
+ end
165
154
 
166
- def symlink(ns_target, ns_destination)
167
- return _request(action: "symlink&target=#{CGI::escape(ns_target)}",
168
- method: "POST",
169
- path: ns_destination)
170
- end
155
+ def quick_delete(ns_path)
156
+ return _request(action: "quick-delete&quick-delete=imreallyreallysure",
157
+ method: "POST",
158
+ path: ns_path)
159
+ end
171
160
 
172
- def upload(local_source, ns_destination)
173
- if File.file?(local_source) && ns_destination[-1] == "/"
174
- ns_destination = "#{ns_destination}#{File.basename(local_source)}"
161
+ def rename(ns_target, ns_destination)
162
+ return _request(action: "rename&destination=#{CGI::escape(ns_destination)}",
163
+ method: "POST",
164
+ path: ns_target)
165
+ end
166
+
167
+ def symlink(ns_target, ns_destination)
168
+ return _request(action: "symlink&target=#{CGI::escape(ns_target)}",
169
+ method: "POST",
170
+ path: ns_destination)
171
+ end
172
+
173
+ def upload(local_source, ns_destination)
174
+ if File.file?(local_source) && ns_destination[-1] == "/"
175
+ ns_destination = "#{ns_destination}#{File.basename(local_source)}"
176
+ end
177
+ return _request(action: "upload",
178
+ method: "PUT",
179
+ source: local_source,
180
+ path: ns_destination)
175
181
  end
176
- return _request(action: "upload",
177
- method: "PUT",
178
- source: local_source,
179
- path: ns_destination)
180
182
  end
181
183
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netstorageapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Astin Choi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-07-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: NetstorageAPI is Akamai Netstorage (File/Object Store) API for Ruby 1.9+
13
+ description: NetstorageAPI is Akamai Netstorage (File/Object Store) API for Ruby 2.0+
14
14
  email: achoi@akamai.com
15
15
  executables: []
16
16
  extensions: []
@@ -29,7 +29,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.9.3
32
+ version: '2.0'
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ">="