Sha256: 6bbc2efc20a75ce24adcf03b1ff794d6001f4cd62fe3f43a267e58ea7e2d7ddb
Contents?: true
Size: 1.29 KB
Versions: 2
Compression:
Stored size: 1.29 KB
Contents
require 'rubygems' require 'uri' require 'net/http' require 'net/https' require 'time' module Kooaba class UploadRequest attr_accessor :message attr_accessor :bucket_id def initialize(item, bucket_id) @bucket_id = bucket_id @message = MultipartMessage.new item.image_files.each do |image_path| content_type = `file --mime-type -b #{image_path}` @message.add_file_part('images', image_path, content_type) end @message.add_text_part('referenceId', item.reference_id) if item.reference_id @message.add_text_part('title', item.title) if item.title @message.add_text_part('enabled', item.enabled) @message.add_text_part('metadata', item.metadata) if item.metadata end # # Returns the http response from the Kooaba servers. # def start url = URI.parse(Kooaba::UPLOAD_URL + "buckets/" + bucket_id + "/items") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(url.path) req.body = @message.body req['date'] = Time.new.httpdate req['content-type'] = @message.content_type req['authorization'] = "Token #{Kooaba.data_key}" http.start { |h| h.request(req) } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
kooaba-0.0.3 | lib/kooaba/upload_request.rb |
kooaba-0.0.2 | lib/kooaba/upload_request.rb |