class OHDrives
Attributes
conn[RW]
options[RW]
Public Class Methods
new(conn=OHConnection.connect, options={})
click to toggle source
# File lib/drives.rb, line 5 def initialize(conn=OHConnection.connect, options={}) @conn = conn @options = options end
Public Instance Methods
create(drive,options={})
click to toggle source
# File lib/drives.rb, line 34 def create(drive,options={}) if ( drive.is_a? OHDrive ) # a data structure of optional user metadata and tags ctags = options[:ctags] user_data = options[:user] # we're going to have to serialize the object to JSON # http://www.skorks.com/2010/04/serializing-and-deserializing-objects-with-ruby/ body = drive.to_json resp = @conn.post "#{@@subject}/#{__method__}", body return JSON.parse(resp.body) else raise TypeError, "First argument must be an instance of OHDrive with a unique name" end end
destroy(drive)
click to toggle source
# File lib/drives.rb, line 49 def destroy(drive) loc = @@subject if ( drive.length == 36 ) loc += "/#{drive}" else raise TypeError, "The Drive UUID passed is invalid. It is #{drive}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc return resp.status end
image(drive, source, *conversion)
click to toggle source
# File lib/drives.rb, line 76 def image(drive, source, *conversion) # drive and source should be Drive objects loc = @@subject if ( drive.length == 36) loc += "/#{drive}" else raise TypeError, "The Drive UUID passed is invalid. It is #{drive}. It must be 36 characters" end loc += "/#{__method__}" if ( source.length == 36) loc += "/#{source}" else raise TypeError, "The Source UUID passed is invalid. It is #{source}. It must be 36 characters" end if ( conversion.size > 0 ) loc += "/#{conversion.first.to_s}" end resp = @conn.post loc return resp.status end
info(*uuid)
click to toggle source
# File lib/drives.rb, line 17 def info(*uuid) # add our subject, in this case "drives" loc = @@subject if ( uuid.size > 0 ) if ( uuid.first.length == 36 ) loc += "/#{uuid.first}" else raise TypeError, "The Drive UUID passed is invalid. It is #{uuid.first}. It must be 36 characters" end end # add the verb, which is the method name loc += "/#{__method__}" resp = @conn.get loc return JSON.parse(resp.body) end
list()
click to toggle source
# File lib/drives.rb, line 10 def list # the __method__ instance var is the name of the method resp = @conn.get "#{@@subject}/#{__method__}" # returns an array of Hashes, convert to an array of OHDriveUUID objects return JSON.parse(resp.body) end
read(drive, offset=0, size="4M")
click to toggle source
this will take some weird options for Faraday www.rubydoc.info/gems/faraday/
# File lib/drives.rb, line 99 def read(drive, offset=0, size="4M") content_type = "application/octet-stream" loc = @@subject if ( drive.length == 36 ) loc += "/#{drive}" else raise TypeError, "The Drive UUID passed is invalid. It is #{drive}. It must be 36 characters" end loc += "/#{__method__}/#{offset.to_s}/#{size.to_s}" return loc #resp = @conn.get loc #return JSON.parse(resp.body) # this'll have to take a file as an argument, since we are streaming binary data to disk. end
set(drive, options={})
click to toggle source
# File lib/drives.rb, line 61 def set(drive, options={}) # This should accept a drive object, not a UUID # drive.drive should return the UUID options = options.to_json loc = @@subject if ( drive.length == 36 ) loc += "/#{drive}" else raise TypeError, "The Drive UUID passed is invalid. It is #{drive}. It must be 36 characters" end loc += "/#{__method__}" resp = @conn.post loc, options return JSON.parse(resp.body) end
write(drive, offset=0)
click to toggle source
# File lib/drives.rb, line 114 def write(drive, offset=0) content_type = "application/octet-stream" content_encoding = "gzip" loc = @@subject if ( drive.length == 36 ) loc += "/#{drive}" else raise TypeError, "The Drive UUID passed is invalid. It is #{drive}. It must be 36 characters" end loc += "/#{__method__}/#{offset.to_s}" return loc # this'll have to take a file as an argument, since we are streaming binary data to a URL. #resp = @conn.post loc, body #return resp.status end