Class: Akamai::Netstorage

Inherits:
Object
  • Object
show all
Defined in:
lib/akamai/netstorage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname, keyname, key, ssl = false) ⇒ Netstorage

Returns a new instance of Netstorage.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/akamai/netstorage.rb', line 37

def initialize(hostname, keyname, key, ssl=false)
    if hostname == '' || keyname == '' || key == ''
        raise NetstorageError, '[NetstorageError] You should input netstorage hostname, keyname and key all'
    end

    @hostname = hostname
    @keyname = keyname
    @key = key
    @ssl = ssl ? 's' : ''

    @request = nil
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



34
35
36
# File 'lib/akamai/netstorage.rb', line 34

def hostname
  @hostname
end

#keyObject

Returns the value of attribute key.



34
35
36
# File 'lib/akamai/netstorage.rb', line 34

def key
  @key
end

#keynameObject

Returns the value of attribute keyname.



34
35
36
# File 'lib/akamai/netstorage.rb', line 34

def keyname
  @keyname
end

#requestObject (readonly)

Returns the value of attribute request.



35
36
37
# File 'lib/akamai/netstorage.rb', line 35

def request
  @request
end

#sslObject

Returns the value of attribute ssl.



34
35
36
# File 'lib/akamai/netstorage.rb', line 34

def ssl
  @ssl
end

Instance Method Details

#delete(ns_path) ⇒ Object



187
188
189
190
191
# File 'lib/akamai/netstorage.rb', line 187

def delete(ns_path)
    return _request(action: "delete",
                    method: "POST",
                    path: ns_path)
end

#dir(ns_path, option = {}) ⇒ Object



134
135
136
137
138
# File 'lib/akamai/netstorage.rb', line 134

def dir(ns_path, option={})
    return _request(action: "dir&format=xml&#{URI.encode_www_form(option)}",
                    method: "GET",
                    path: ns_path)
end

#download(ns_source, local_destination = '') ⇒ Object



146
147
148
149
150
151
152
153
154
155
# File 'lib/akamai/netstorage.rb', line 146

def download(ns_source, local_destination='')
    if ns_source.end_with?('/')
        raise NetstorageError, "[NetstorageError] Nestorage download path shouldn't be a directory: #{ns_source}"
    end

    return _request(action: "download",
                    method: "GET",
                    path: ns_source,
                    destination: local_destination)
end

#du(ns_path) ⇒ Object



157
158
159
160
161
# File 'lib/akamai/netstorage.rb', line 157

def du(ns_path)
    return _request(action: "du&format=xml",
                    method: "GET",
                    path: ns_path)
end

#list(ns_path, option = {}) ⇒ Object



140
141
142
143
144
# File 'lib/akamai/netstorage.rb', line 140

def list(ns_path, option={})
    return _request(action: "list&format=xml&#{URI.encode_www_form(option)}",
                    method: "GET",
                    path: ns_path)
end

#mkdir(ns_path) ⇒ Object



169
170
171
172
173
# File 'lib/akamai/netstorage.rb', line 169

def mkdir(ns_path)
    return _request(action: "mkdir",
                    method: "POST",
                    path: ns_path)
end

#mtime(ns_path, mtime) ⇒ Object



181
182
183
184
185
# File 'lib/akamai/netstorage.rb', line 181

def mtime(ns_path, mtime)
    return _request(action: "mtime&format=xml&mtime=#{mtime}",
                    method: "POST",
                    path: ns_path)
end

#quick_delete(ns_path) ⇒ Object



193
194
195
196
197
# File 'lib/akamai/netstorage.rb', line 193

def quick_delete(ns_path)
    return _request(action: "quick-delete&quick-delete=imreallyreallysure",
                    method: "POST",
                    path: ns_path)
end

#rename(ns_target, ns_destination) ⇒ Object



199
200
201
202
203
# File 'lib/akamai/netstorage.rb', line 199

def rename(ns_target, ns_destination)
    return _request(action: "rename&destination=#{CGI::escape(ns_destination)}",
                    method: "POST",
                    path: ns_target)
end

#rmdir(ns_path) ⇒ Object



175
176
177
178
179
# File 'lib/akamai/netstorage.rb', line 175

def rmdir(ns_path)
    return _request(action: "rmdir",
                    method: "POST",
                    path: ns_path)
end

#stat(ns_path) ⇒ Object



163
164
165
166
167
# File 'lib/akamai/netstorage.rb', line 163

def stat(ns_path)
    return _request(action: "stat&format=xml",
                    method: "GET",
                    path: ns_path)
end


205
206
207
208
209
# File 'lib/akamai/netstorage.rb', line 205

def symlink(ns_target, ns_destination)
    return _request(action: "symlink&target=#{CGI::escape(ns_target)}",
                    method: "POST",
                    path: ns_destination)
end

#upload(local_source, ns_destination, index_zip = false) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/akamai/netstorage.rb', line 211

def upload(local_source, ns_destination, index_zip=false)
    if File.file?(local_source) 
        if ns_destination.end_with?('/')
            ns_destination = "#{ns_destination}#{File.basename(local_source)}"
        end
    else
        raise NetstorageError, "[NetstorageError] #{ns_destination} doesn't exist or is directory"
    end
    action = "upload"
    if index_zip == true or index_zip.to_s.downcase == "true"
        action += "&index-zip=2"
    end

    return _request(action: action,
                    method: "PUT",
                    source: local_source,
                    path: ns_destination) 
end