Sha256: 52f12157216e7b9c6ed7b66a7e8b7e8ed86ce25799f0c2d503b7fbdd43b422fc

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module Omdb
  module Api
    class Request
      BASE_URI = 'https://www.omdbapi.com'

      attr_reader :client, :field, :value, :options

      def self.call(client, method, value, options, &block)
        new(client, method, value, options).make_get_to_imdb_api(&block)
      end

      def initialize(client, method, value, options)
        @client  = client
        @value   = CGI.escape(value)
        @options = options
        @field   = if /id/.match?(method)
                     'i'
                   elsif /title/.match?(method)
                     't'
                   else
                     's'
                   end
      end

      def make_get_to_imdb_api
        params = {
          query: {
            apikey: client.api_key,
            field.to_s => value.to_s
          }.merge(options)
        }

        yield HTTParty.get(BASE_URI, params)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omdb-api-1.4.3 lib/omdb/api/request.rb