Class: TrailerVote::Api::Place::Create

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

Constant Summary collapse

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

Returns a new instance of Create.



28
29
30
31
# File 'lib/trailer_vote/api/place/create.rb', line 28

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

Instance Method Details

#backTrailerVote::Api::Place::Find

Returns the found place.

Returns:



34
35
36
# File 'lib/trailer_vote/api/place/create.rb', line 34

def back
  place
end

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

Create a place

Parameters:

  • data (String, Hash)

    the data conform to the Place media type

  • url (String) (defaults to: resolve_url)

    (#resolve_url result) the url to post to

Returns:

See Also:



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

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