Class: Kooaba::UploadRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/kooaba/upload_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, bucket_id) ⇒ UploadRequest

Returns a new instance of UploadRequest.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kooaba/upload_request.rb', line 14

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.) if item.
end

Instance Attribute Details

#bucket_idObject

Returns the value of attribute bucket_id.



12
13
14
# File 'lib/kooaba/upload_request.rb', line 12

def bucket_id
  @bucket_id
end

#messageObject

Returns the value of attribute message.



11
12
13
# File 'lib/kooaba/upload_request.rb', line 11

def message
  @message
end

Instance Method Details

#startObject

Returns the http response from the Kooaba servers.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kooaba/upload_request.rb', line 30

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