Class: Omdb::Api::Request
- Inherits:
-
Object
- Object
- Omdb::Api::Request
- Defined in:
- lib/omdb/api/request.rb
Constant Summary collapse
- BASE_URI =
'https://www.omdbapi.com'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, method, value, options) ⇒ Request
constructor
A new instance of Request.
- #make_get_to_imdb_api {|HTTParty.get(BASE_URI, params)| ... } ⇒ Object
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, ) @client = client @value = CGI.escape(value) = @field = if /id/.match?(method) 'i' elsif /title/.match?(method) 't' else 's' end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/omdb/api/request.rb', line 8 def client @client end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
8 9 10 |
# File 'lib/omdb/api/request.rb', line 8 def field @field end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/omdb/api/request.rb', line 8 def end |
#value ⇒ Object (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, , &block) new(client, method, value, ).make_get_to_imdb_api(&block) end |
Instance Method Details
#make_get_to_imdb_api {|HTTParty.get(BASE_URI, params)| ... } ⇒ Object
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() } yield HTTParty.get(BASE_URI, params) end |