Class: Omdb::Api::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/omdb/api/request.rb

Constant Summary collapse

BASE_URI =
'https://www.omdbapi.com'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, method, value, options) ⇒ Request

Returns a new instance of Request.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/omdb/api/request.rb', line 14

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/omdb/api/request.rb', line 8

def client
  @client
end

#fieldObject (readonly)

Returns the value of attribute field.



8
9
10
# File 'lib/omdb/api/request.rb', line 8

def field
  @field
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/omdb/api/request.rb', line 8

def options
  @options
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/omdb/api/request.rb', line 8

def value
  @value
end

Class Method Details

.call(client, method, value, options, &block) ⇒ Object



10
11
12
# File 'lib/omdb/api/request.rb', line 10

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

Instance Method Details

#make_get_to_imdb_api {|HTTParty.get(BASE_URI, params)| ... } ⇒ Object

Yields:



27
28
29
30
31
32
33
34
35
36
# File 'lib/omdb/api/request.rb', line 27

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