Class: TrailerVote::Api::Product::Lookup

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

Overview

Looks up a product by a set of authority and identifiers in lookups

Examples:

lookup a product by imdb or tmdb authority


lookups = [
  { authority: 'imdb', identifier: 'tt1825683'},
  { authority: 'tmdb', identifier: '284054' }
]
result = TrailerVote::Api.configure(...).product.lookup.call(data: lookups)
result.product
# => { "title": "" }

try to lookup multiple products at the same time


lookups = [
  { authority: 'imdb', identifier: 'tt1825683'},
  { authority: 'isbn', identifier: '978-1-59448-194-9' }
]
result = TrailerVote::Api.configure(...).product.lookup.call(data: lookups)
result.errors
# => [{ "message": "Found multiple products for the given identifiers, only one result ..." }]

Constant Summary collapse

CONTENT =
MediaTypes::ProductLookup.to_constructable.version(1)
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:) ⇒ Lookup

Returns a new instance of Lookup.



57
58
59
# File 'lib/trailer_vote/api/product/lookup.rb', line 57

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

Instance Method Details

#backTrailerVote::Api::Product

Returns api to deal with products.

Returns:



62
63
64
# File 'lib/trailer_vote/api/product/lookup.rb', line 62

def back
  configuration.product
end

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



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/trailer_vote/api/product/lookup.rb', line 66

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