Module: FilmOn::Services::VideoOnDemand

Included in:
Base
Defined in:
lib/film_on/services/video_on_demand.rb

Defined Under Namespace

Classes: VodSearchResult

Instance Method Summary collapse

Instance Method Details

#convert_genres(json) ⇒ Object

convert_genres: takes the raw JSON and converts it into a nice ruby array of objects



103
104
105
106
# File 'lib/film_on/services/video_on_demand.rb', line 103

def convert_genres(json)
  hash = JSON.parse(json)["response"]
  hash.map{|gen| FilmOn::Genre.new(gen)}
end

#convert_movie(json) ⇒ Object

convert_movie: takes the raw JSON and coverts it into a nice ruby object normal for use after storing the JSON in a caching mechanism



95
96
97
98
# File 'lib/film_on/services/video_on_demand.rb', line 95

def convert_movie(json)
  hash = JSON.parse(json)["response"]
  FilmOn::Movie.new(hash)
end

#convert_vod_search(json) ⇒ Object

convert_vod_search: takes the raw JSON and coverts it into an object, which includes the total, total_found and a nice array of movies as ruby objects normally for use after storing the JSON in a caching mechanism



81
82
83
84
85
86
87
88
# File 'lib/film_on/services/video_on_demand.rb', line 81

def convert_vod_search(json)
  hash = JSON.parse(json)
  VodSearchResult.new(
     hash["total"],
     hash["total_found"],
     hash["response"].map{|movie| FilmOn::Movie.new(movie) }
  )
end

#genres(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/film_on/services/video_on_demand.rb', line 15

def genres(opts={})
  return @genres if @genres && !opts[:json]
  json = get_vod("genres")
  if opts[:json]
    return json
  end
  @genres = convert_genres(json)
end

#movie(id, opts = {}) ⇒ Object

movie: retrieve a specific movie with a given id



66
67
68
69
70
71
72
73
74
# File 'lib/film_on/services/video_on_demand.rb', line 66

def movie(id, opts={})
  id = id.to_s
  return @movie[id] if @movie[id] && !opts[:json]
  json = get_vod("movie", {id: id})
  if opts[:json]
    return json
  end
  @movie[id] = convert_movie(json)
end

#vod_search(params = {}, opts = {}) ⇒ Object

vod_search: calls the vod/search and returns a list of movies filtered by the params and the number returned (total) and the total number for the search (total_found) i.e. film_on.vod_search(genre: “horror”).movies => will return all horror movies film_on.vod_search(genre: “horror”).total => will return the number of movies return from the feed film_on.vod_search(genre: “horror”).total_found => will return the total number of movies available with the given params (useful for pagination)

Params examples:

term: Set this to the word or term to search the catalog for. The FilmOn VOD API searches the title and synopses of catalog titles for a match. This parameter is required.

start_index: Set this to a zero-based offset into the list that results from the query. By using this with the max_results parameter, you can request successive pages of search results.

max_results: Set this to the maximum number of results to return. This number cannot be greater than 100. If you do not specify max_results, the default value is 25.

parent_id: search for episodes of specified series.

order_by: Order search results by one of following strategies: “relevance” or “date”

content_type: Filter and return search results only for specified content_type. Parameter value should be one of : “relevance” or “date”

genre: Filter and search for movies only in specified genre. Parameter value should be a slug of corresponding genre, retrieved from /api/vod/genres resource.



54
55
56
57
58
59
60
61
62
# File 'lib/film_on/services/video_on_demand.rb', line 54

def vod_search(params={}, opts={})
  key = Digest::MD5.hexdigest(params.to_s)
  return @vod_search[key] if @vod_search[key] && !opts[:json]
  json = get_vod("search", params)
  if opts[:json]
    return json
  end
  @vod_search[key] = convert_vod_search(json)
end