Class: TaboolaApi::Resources::Operations

Inherits:
Base
  • Object
show all
Defined in:
lib/taboola_api/resources/operations.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from TaboolaApi::Resources::Base

Instance Method Details

#upload_image(file) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/taboola_api/resources/operations.rb', line 6

def upload_image(file)
  raise ArgumentError, "File must be provided" unless file.is_a?(File) || file.is_a?(Tempfile)

  mime_type = MIME::Types.type_for(file.path).first.to_s
  payload = {
    file: Faraday::Multipart::FilePart.new(file, mime_type)
  }
  response = client.request(:post, "operations/upload-image", payload, "Content-Type" => "multipart/form-data")
  response.body
end