Class: MovieAPI

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

Constant Summary collapse

API_URL =
'http://mymovieapi.com/'

Class Method Summary collapse

Class Method Details

.search_by_id(options = {}) ⇒ Object



9
10
11
# File 'lib/mmapi.rb', line 9

def self.search_by_id(options = {})

end

.search_by_title(title, options = {}) ⇒ Array

Queries the API for a movie title

Parameters:

  • title (String) —

    The title of the movie

  • options (Hash) (defaults to: {}) —

    The options to create a search query

Options Hash (options):

  • :year (Integer) — default: 2013 —

    The year you wish to search for - defaults to current year

  • :yg (Integer) — default: 0 —

    When this paramter is 0, the year parameter is disabled

  • :mt (String) — default: 'none' —

    The movie type you wish to search for

  • :plot (String) — default: 'simple' —

    The plot type you with the API to return

  • :episode (Integer) — default: 1 —

    When the parameter is 0, "episodes" is not included in the result

  • :offset (Integer) — default: 0 —

    Paging offset

  • :limit (Integer) — default: 1 —

    The maximum number of records to return

  • :lang (String) — default: 'en-US' —

    The data language you wish to return

  • :aka (String) — default: 'simple' —

    The aka type you with to return

  • :release (String) — default: 'simple' —

    The release date type you with to return

  • :business (Integer) — default: 0 —

    Include the business field

  • :tech (Integer) — default: 0 —

    Include the technical field

Returns:

  • (Array) —

    Returns an array of hashes.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mmapi.rb', line 32

def self.search_by_title(title, options = {})

  params = options ? options.collect {|key, value| "#{key}=#{URI::encode(value)}"}.join('&') : ''


  uri = "http://mymovieapi.com?q=#{URI::encode(title)}" + params

  p uri

  response = open("http://mymovieapi.com?q=#{URI::encode(title)}&" + params).read
  data = JSON.parse(response)

  return data

end