netstorageapi 0.7.0 → 0.8.0
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 +4 -4
- data/lib/akamai/netstorage.rb +40 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98536983f38afcef837d9ecdab5e5728420e700f
|
4
|
+
data.tar.gz: fb7cb2e986b5ef90f9b275932eeb7903438a6341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d4b6568b60b88f5477cb76d826e3ab2c6dea3b021042bf449883f3ea3bf7732b90bf1a82d9ae7268ee6667de4e1d4f135bd49bfcc436fd36213ac04f9f74db
|
7
|
+
data.tar.gz: b1b19da5b75668dfc3ee39b553c65eb71b136d02cd6966932933b8ba165a1cb609bf67c32ac59e4ac014ce14d21f52bc4b211ec62782f369402e82308e61b75f
|
data/lib/akamai/netstorage.rb
CHANGED
@@ -25,11 +25,20 @@ require "uri"
|
|
25
25
|
|
26
26
|
|
27
27
|
module Akamai
|
28
|
+
class NetstorageError < Exception
|
29
|
+
"""Base-class for all exceptions raised by Netstorage Class"""
|
30
|
+
end
|
31
|
+
|
32
|
+
|
28
33
|
class Netstorage
|
29
34
|
attr_accessor :hostname, :keyname, :key, :ssl
|
30
35
|
attr_reader :request
|
31
36
|
|
32
37
|
def initialize(hostname, keyname, key, ssl=false)
|
38
|
+
if hostname == '' || keyname == '' || key == ''
|
39
|
+
raise NetstorageError, '[NetstorageError] You should input netstorage hostname, keyname and key all'
|
40
|
+
end
|
41
|
+
|
33
42
|
@hostname = hostname
|
34
43
|
@keyname = keyname
|
35
44
|
@key = key
|
@@ -43,21 +52,24 @@ module Akamai
|
|
43
52
|
def _response(uri, kwargs)
|
44
53
|
if kwargs[:action] == "download"
|
45
54
|
local_destination = kwargs[:destination]
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
local_destination = File.join(local_destination, ns_filename)
|
52
|
-
end
|
55
|
+
ns_filename = kwargs[:path][-1] != '/' ? File.basename(kwargs[:path]) : nil
|
56
|
+
if local_destination == ''
|
57
|
+
local_destination = ns_filename
|
58
|
+
elsif File.directory?(local_destination)
|
59
|
+
local_destination = File.join(local_destination, ns_filename)
|
53
60
|
end
|
61
|
+
|
54
62
|
response = Net::HTTP.start(uri.hostname, uri.port,
|
55
63
|
:use_ssl => uri.scheme == 'https') { |http|
|
56
64
|
http.request @request do |res|
|
57
|
-
|
58
|
-
|
59
|
-
|
65
|
+
begin
|
66
|
+
open(local_destination, "wb") do |io|
|
67
|
+
res.read_body do |chunk|
|
68
|
+
io.write chunk
|
69
|
+
end
|
60
70
|
end
|
71
|
+
rescue Exception => e
|
72
|
+
raise NetstorageError, e
|
61
73
|
end
|
62
74
|
end
|
63
75
|
}
|
@@ -65,7 +77,11 @@ module Akamai
|
|
65
77
|
end
|
66
78
|
|
67
79
|
if kwargs[:action] == "upload"
|
68
|
-
|
80
|
+
begin
|
81
|
+
@request.body = File.read(kwargs[:source])
|
82
|
+
rescue Exception => e
|
83
|
+
raise NetstorageError, e
|
84
|
+
end
|
69
85
|
end
|
70
86
|
|
71
87
|
response = Net::HTTP.start(uri.hostname, uri.port,
|
@@ -77,6 +93,11 @@ module Akamai
|
|
77
93
|
end
|
78
94
|
|
79
95
|
def _request(kwargs={})
|
96
|
+
path = kwargs[:path].to_s
|
97
|
+
if !path.start_with?('/')
|
98
|
+
raise NetstorageError, '[NetstorageError] Invalid netstorage path'
|
99
|
+
end
|
100
|
+
|
80
101
|
path = URI::escape(kwargs[:path])
|
81
102
|
acs_action = "version=1&action=#{kwargs[:action]}"
|
82
103
|
acs_auth_data = "5, 0.0.0.0, 0.0.0.0, #{Time.now.to_i}, #{Random.rand(100000)}, #{@keyname}"
|
@@ -91,7 +112,8 @@ module Akamai
|
|
91
112
|
'X-Akamai-ACS-Action' => acs_action,
|
92
113
|
'X-Akamai-ACS-Auth-Data' => acs_auth_data,
|
93
114
|
'X-Akamai-ACS-Auth-Sign' => acs_auth_sign,
|
94
|
-
'Accept-Encoding' =>
|
115
|
+
'Accept-Encoding' => 'identity',
|
116
|
+
'User-Agent' => 'NetStorageKit-Ruby'
|
95
117
|
}
|
96
118
|
|
97
119
|
if kwargs[:method] == "GET"
|
@@ -177,8 +199,12 @@ module Akamai
|
|
177
199
|
end
|
178
200
|
|
179
201
|
def upload(local_source, ns_destination)
|
180
|
-
if File.file?(local_source)
|
181
|
-
ns_destination
|
202
|
+
if File.file?(local_source)
|
203
|
+
if ns_destination[-1] == "/"
|
204
|
+
ns_destination = "#{ns_destination}#{File.basename(local_source)}"
|
205
|
+
end
|
206
|
+
else
|
207
|
+
raise NetstorageError, "[NetstorageError] #{ns_destination} doesn't exist or is directory"
|
182
208
|
end
|
183
209
|
return _request(action: "upload",
|
184
210
|
method: "PUT",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netstorageapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: NetstorageAPI is Akamai Netstorage (File/Object Store) API for Ruby 2.0+
|
14
14
|
email: achoi@akamai.com
|