Class: BadFruit::Movies

Inherits:
Object
  • Object
show all
Defined in:
lib/badfruit/Movies/movies.rb

Constant Summary collapse

MAX_PAGE_LIMIT =
50

Instance Method Summary collapse

Constructor Details

#initialize(badfruit) ⇒ Movies

Returns a new instance of Movies.



5
6
7
# File 'lib/badfruit/Movies/movies.rb', line 5

def initialize(badfruit)
  @badfruit = badfruit
end

Instance Method Details

#search_by_alias(alias_id, type = 'imdb') ⇒ Object

search by alias (currently only IMDB is supported)



25
26
27
28
29
30
# File 'lib/badfruit/Movies/movies.rb', line 25

def search_by_alias(alias_id,type='imdb')
  movie = @badfruit.get_movie_alias_info(alias_id, type)
  json = JSON.parse(movie)
  raise 'Movie not found' if !json['error'].nil?
  @badfruit.parse_movie_array(json)
end

#search_by_id(movie_id) ⇒ Object

search by id



18
19
20
21
22
# File 'lib/badfruit/Movies/movies.rb', line 18

def search_by_id(movie_id)
  movie = @badfruit.get_movie_info(movie_id, "main")
  raise 'Movie not found' if movie.nil? || movie.empty?
  @badfruit.parse_movie_array(JSON.parse(movie))
end

#search_by_name(name, page_limit = 1, page = 1) ⇒ Object

returns an array of movie objects from the given search result.



10
11
12
13
14
15
# File 'lib/badfruit/Movies/movies.rb', line 10

def search_by_name(name, page_limit=1, page=1)
  if page_limit > 50
    page_limit = MAX_PAGE_LIMIT #current limitation of the rotten tomatos API
  end
  return @badfruit.parse_movies_array(JSON.parse(@badfruit.search_movies(name, page_limit, page)))
end

#similar_movies(movie_id) ⇒ Object

similar movie



33
34
35
# File 'lib/badfruit/Movies/movies.rb', line 33

def similar_movies(movie_id)
  return @badfruit.parse_movies_array(JSON.parse(@badfruit.similar_movies(movie_id)))
end