class FilmOn::Base
Constants
- TV_URI
- VOD_URI
Attributes
app_key[R]
app_secret[R]
session_key[R]
Public Class Methods
new(app_key, app_secret)
click to toggle source
FilmOn
Api (www.filmon.com/page/api) initialize the wrapper with your app_key
and app_secret
for development purposes you can use “foo” and “bar” eg. film_on = FilmOn::Base.new
(“foo”, “bar”) film_on.channels => returns an array of channels film_on.groups => returns an array of channel groups film_on.channel(14) => returns information for channel with id 14
# File lib/film_on/base.rb, line 27 def initialize(app_key, app_secret) @app_key = app_key @app_secret = app_secret @channel = {} @movie = {} @vod_search = {} init_request end
Private Instance Methods
get(service, query={}, protocol="http://")
click to toggle source
Make a GET request to the api with the given service, query and protocol
# File lib/film_on/base.rb, line 63 def get(service, query={}, protocol="http://") query["format"] = "json" query["session_key"] = @session_key unless service == "init" query_string = query.map{|k,v| "#{k}=#{v}"}.join("&") response = HTTParty.get("#{protocol}#{TV_URI}#{service}?#{query_string}") if response && response.code == 200 return response.body else raise ApiError end end
get_vod(service, query={}, protocol="http://")
click to toggle source
# File lib/film_on/base.rb, line 75 def get_vod(service, query={}, protocol="http://") query_string = query.map{|k,v| "#{k}=#{v}"}.join("&") response = HTTParty.get("#{protocol}#{VOD_URI}#{service}?#{query_string}") if response && response.code == 200 return response.body else raise ApiError end end
init_request()
click to toggle source
Create the initial handshake to FilmOn
and set the @session_key
# File lib/film_on/base.rb, line 41 def init_request response = get("init") init_hash = JSON.parse(response) @session_key = init_hash["session_key"] self end
post(service, query={}, protocol="http://")
click to toggle source
Make a POST request to the api with the given service, query and protocol
# File lib/film_on/base.rb, line 50 def post(service, query={}, protocol="http://") query["format"] = "json" query["session_key"] = @session_key unless service == "init" response = HTTParty.post("#{protocol}#{TV_URI}#{service}", {body: query, headers: {'Content-Type' => 'application/json'}}) if response && response.code == 200 return response.body else raise ApiError end end