class RightScriptAttachmentInternal
API 0.1
Public Class Methods
get_s3_upload_params(right_script_href)
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 54 def self.get_s3_upload_params(right_script_href) url = self.resource_plural_name + "/get_s3_upload_params" params = {"right_script_href" => right_script_href} params = {self.resource_singular_name => params} connection.get(url, params) end
resource_plural_name()
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 46 def self.resource_plural_name "right_script_attachments" end
resource_singular_name()
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 50 def self.resource_singular_name "right_script_attachment" end
Public Instance Methods
download()
click to toggle source
def self.upload(filepath, right_script_href)
hsh = get_s3_upload_params(right_script_href) params = {} hsh.keys.each { |k| params[k.gsub(/-/,"_").to_sym] = hsh[k] } params[:file] = File.new(filepath, 'rb') req = RestClient::Request.new({ :method => :post, :url => hsh["url"], :payload => params, :multipart => true, }) s = req.payload.to_s splitter = s.split("\r\n").first a = s.split(/#{splitter}-?-?\r\n/) a.push(a.delete(a.detect { |n| n =~ %r{name="file";} })) new_payload = a.join(splitter + "\r\n") + splitter + "--\r\n" uri = URI.parse(hsh["url"]) net_http = Net::HTTP::Post.new(uri.request_uri) req.transmit(uri, net_http, new_payload) # TODO: Precondition Failing callback_uri = URI.parse(hsh["success_action_redirect"]) connection.get(callback_uri.request_uri)
end
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 89 def download self.reload unless @params["authenticated_s3_url"] RestClient.get(@params["authenticated_s3_url"]) end
download_to_file(path=Dir.pwd)
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 94 def download_to_file(path=Dir.pwd) data = self.download File.open(File.join(path, @params["filename"]), 'w') { |f| f.write(data) } end
reload()
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 99 def reload uri = URI.parse(self.href || "#{resource_plural_name}/#{@params["id"]}") @params ? @params.merge!(connection.get(uri.path)) : @params = connection.get(uri.path) end
resource_plural_name()
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 38 def resource_plural_name "right_script_attachments" end
resource_singular_name()
click to toggle source
# File lib/rest_connection/rightscale/right_script_attachment_internal.rb, line 42 def resource_singular_name "right_script_attachment" end