Class: TrailerVote::Api::Issue::Create

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

Constant Summary collapse

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

Returns a new instance of Create.



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

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

Instance Method Details

#backObject



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

def back
  configuration.issue
end

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

Create an issue

Parameters:

  • data (String, Hash)

    the data conform to the Issue media type

  • url (String) (defaults to: resolve_url)

    (#resolve_url result) the url to post to

Returns:

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trailer_vote/api/issue/create.rb', line 41

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