Class: TomatoPower::API

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

Overview

API class to interface with Client

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ API

Returns a new instance of API.



8
9
10
11
# File 'lib/tomato_power/api/api.rb', line 8

def initialize api_key
  @api_key = api_key
  API.define_tomato_methods(*TOMATO_METHODS.keys)
end

Class Method Details

.define_tomato_methods(*methods) ⇒ Object

Note:

TOMATO_METHODS is a hash containing all of the Rotten Tomatoes API calls.

Defines methods that are in TOMATO_METHODS

Parameters:

  • methods (Array)

    methods to be created.

  • options (Hash)

    options for function call.



18
19
20
21
22
23
24
# File 'lib/tomato_power/api/api.rb', line 18

def self.define_tomato_methods(*methods)
  methods.each do |method|
    define_method(method) do |options={}|
      fetch(TOMATO_METHODS[method][:url], @api_key, options) if options_valid? method, options
    end
  end
end