Class: TrailerVote::Api::Product::Image::Create

Inherits:
Object
  • Object
show all
Includes:
Composable::Common
Defined in:
lib/trailer_vote/api/product/image/create.rb

Constant Summary collapse

CONTENT =
MediaTypes::ProductImage.to_constructable.version(1).view('create')
SUCCESS =
MediaTypes::ProductImage.to_constructable.version(1)
FAILURE =
MediaTypes::Errors.to_constructable.version(1)
ACCEPT =
[SUCCESS.to_s, FAILURE.to_s(0.1)].join(', ').freeze

Instance Method Summary collapse

Methods included from Composable::Common

included

Constructor Details

#initialize(configuration:, product:) ⇒ Create

Returns a new instance of Create.



27
28
29
30
# File 'lib/trailer_vote/api/product/image/create.rb', line 27

def initialize(configuration:, product:)
  self.configuration = configuration
  self.product = product
end

Instance Method Details

#backTrailerVote::Api::Product::Image

Returns the api to deal with the current product images.

Returns:



33
34
35
# File 'lib/trailer_vote/api/product/image/create.rb', line 33

def back
  product.image
end

#call(data:, url: resolve_url) ⇒ TrailerVote::Api::Product::Image::Find

Create the image

Parameters:

  • url (String) (defaults to: resolve_url)

    (#resolve_url result) the url to post to

  • data (Hash)

    the image data

Returns:

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/trailer_vote/api/product/image/create.rb', line 45

def call(data:, url: resolve_url)
  body = encode(data)
  guard_network_errors do
    branch(
      resolve_client.headers(
        Headers::ACCEPT => ACCEPT,
        Headers::CONTENT_TYPE => "#{CONTENT}; charset=#{body.encoding.name}"
      ).post(url, body: body),
      data: data
    )
  end
end