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

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

Constant Summary collapse

CONTENT =
MediaTypes::Product.to_constructable.version(2).view('create')
SUCCESS =
MediaTypes::Product.to_constructable.version(2)
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:) ⇒ Create

Returns a new instance of Create.



25
26
27
# File 'lib/trailer_vote/api/product/create.rb', line 25

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

Instance Method Details

#backTrailerVote::Api::Product

Returns api to deal with products.

Returns:



30
31
32
# File 'lib/trailer_vote/api/product/create.rb', line 30

def back
  configuration.product
end

#call(data:, url: resolve_url) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/trailer_vote/api/product/create.rb', line 34

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