film_on 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6daa5c3826eabbbc14f6fbdbbd2c5b188a76725
4
- data.tar.gz: 74858705d1db4df5dd193a8afe35a321d5f45134
3
+ metadata.gz: e337a6f5e24579677972f39b52b2cd3214a6ab43
4
+ data.tar.gz: 0637963eabb1d25c451be26e2db024b7b6808f0e
5
5
  SHA512:
6
- metadata.gz: 3d38f63ee5436ff621c56564fc2d75a647257298e4421616489c8819470e6f0f1db07fe43133a777a7a262d30bcfc9656463c6d4f77ba1324679e99f80549046
7
- data.tar.gz: 356205369ac03fd4fed40cd60ddb692b6e047c0933b6c2470b42f026cb4027a841d71df1df5fe7ad21b3ebd40fe2852ad11c17abb0915b5b436a49d745638aee
6
+ metadata.gz: a4904487a19a2e9e4f27f4c04f9045ad0a132e638fa9c62cae1f211f155e172b208030fa354ddc4835c98c6af71769d51a8081a6306e0f13834ab247a5aa2830
7
+ data.tar.gz: 6d5c99daef0888fb10f81f26130faec795c58f28b521dfd5be40c172e6f61a435ca05e35aab9756ce3fdab17f48a8120fec55f95f8cebe308736a588c41dba3a
data/README.md CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  A Ruby wrapper for the FilmOn API: http://www.filmon.com/page/api
4
4
 
5
- This is currently at version 0.0.1 and only handles channels, channel
6
- and groups methods
7
-
5
+ This is currently at version < 0.1. It handles TV Streams: channels and groups methods
6
+ and the Video On Demand: movie search
8
7
 
9
8
  ## Installation
10
9
 
@@ -28,15 +27,27 @@ Refer to FilmOn Api (http://www.filmon.com/page/api):
28
27
 
29
28
  Obtain your app_key and app_secret from FilmOn
30
29
 
31
- app_key = "foo"
32
- app_secret = "bar"
30
+ `app_key = "foo"`
31
+
32
+ `app_secret = "bar"`
33
+
34
+ `film_on = FilmOn::Base.new(app_key, app_secret)`
35
+
36
+ ### TV Streaming examples
37
+
38
+ `film_on.channels` => returns list of all channels as ruby objects
39
+
40
+ `flim_on.groups` => returns list of all groups as ruby objects
41
+
42
+ `film_on.channel(id)` => returns info for given channel as a ruby object
43
+
44
+ `film_on.find_group(id)` => returns the information for a given group id
45
+
46
+ ### Video On Demand examples
33
47
 
34
- film_on = FilmOn::Base.new(app_key, app_secret)
48
+ `film_on.movies(genre: "horror")` => returns all movies within the horror genre
35
49
 
36
- film_on.channels => returns list of all channels as ruby objects
37
- flim_on.groups => returns list of all groups as ruby objects
38
- film_on.channel(id) => returns info for given channel as a ruby object
39
- film_on.find_group(id) => returns the information for a given group id
50
+ `film_on.movie(id)` => returns information on the movie with the given id
40
51
 
41
52
  ## Development
42
53
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.11
1
+ 0.0.12
data/lib/film_on/base.rb CHANGED
@@ -4,11 +4,12 @@ module FilmOn
4
4
 
5
5
  class Base
6
6
 
7
- include Services
8
- include ChannelHelper
9
- include GroupHelper
7
+ include Services::Channels
8
+ include Services::Groups
9
+ include Services::VideoOnDemand
10
10
 
11
- URI = "www.filmon.com/tv/api/"
11
+ TV_URI = "www.filmon.com/tv/api/"
12
+ VOD_URI = "www.filmon.com/api/vod/"
12
13
 
13
14
  attr_reader :app_key, :app_secret, :session_key
14
15
 
@@ -27,6 +28,8 @@ module FilmOn
27
28
  @app_key = app_key
28
29
  @app_secret = app_secret
29
30
  @channel = {}
31
+ @movie = {}
32
+ @vod_search = {}
30
33
  init_request
31
34
  end
32
35
 
@@ -47,8 +50,7 @@ module FilmOn
47
50
  def post(service, query={}, protocol="http://")
48
51
  query["format"] = "json"
49
52
  query["session_key"] = @session_key unless service == "init"
50
- full_service_url = "#{protocol}#{URI}#{service}"
51
- response = HTTParty.post(full_service_url, {body: query, headers: {'Content-Type' => 'application/json'}})
53
+ response = HTTParty.post("#{protocol}#{TV_URI}#{service}", {body: query, headers: {'Content-Type' => 'application/json'}})
52
54
  if response && response.code == 200
53
55
  return response.body
54
56
  else
@@ -61,8 +63,18 @@ module FilmOn
61
63
  def get(service, query={}, protocol="http://")
62
64
  query["format"] = "json"
63
65
  query["session_key"] = @session_key unless service == "init"
64
- full_service_url = "#{protocol}#{URI}#{service}?#{query.map{|k,v| "#{k}=#{v}"}.join("&")}"
65
- response = HTTParty.get(full_service_url)
66
+ query_string = query.map{|k,v| "#{k}=#{v}"}.join("&")
67
+ response = HTTParty.get("#{protocol}#{TV_URI}#{service}?#{query_string}")
68
+ if response && response.code == 200
69
+ return response.body
70
+ else
71
+ raise ApiError
72
+ end
73
+ end
74
+
75
+ def get_vod(service, query={}, protocol="http://")
76
+ query_string = query.map{|k,v| "#{k}=#{v}"}.join("&")
77
+ response = HTTParty.get("#{protocol}#{VOD_URI}#{service}?#{query_string}")
66
78
  if response && response.code == 200
67
79
  return response.body
68
80
  else
@@ -16,7 +16,6 @@ module FilmOn
16
16
  attr_reader :preload_message, :preload_timeout, :is_local, :preload_intro, :images, :schedule, :now_playing, :next_playing, :tvguide
17
17
 
18
18
  def initialize(hash)
19
- @hash = hash
20
19
  @id = hash["id"]
21
20
  @title = hash["title"]
22
21
  @alias = hash["alias"]
@@ -7,12 +7,10 @@ module FilmOn
7
7
 
8
8
  class Group
9
9
 
10
- attr_reader :hash
11
10
  attr_reader :group_id, :id, :title, :group, :original_name, :alias, :description
12
11
  attr_reader :weight, :logo_uri, :logo_148x148_uri, :logos, :channels, :channels_count
13
12
 
14
13
  def initialize(hash)
15
- @hash = hash
16
14
  @group_id = hash["group_id"]
17
15
  @id = hash["id"]
18
16
  @title = hash["title"]
@@ -0,0 +1,47 @@
1
+ module FilmOn
2
+
3
+ # FilmOn::Movie
4
+ # Movie can have either a basic set of data or a more verbose set
5
+ # depending on whether it is called as part of a vod_search or
6
+ # as in individual call from #movie, takes a raw hash and converts
7
+ # it into a nice ruby object
8
+
9
+ class Movie
10
+
11
+ attr_reader :id, :title, :slug, :description, :type_id, :series_number, :episodes_count, :vendor_id, :vendorka_id
12
+ attr_reader :content_host, :low_quality_file_id, :high_quality_file_id, :parent_id, :exists_on_edgecast
13
+ attr_reader :is_featured, :is_enabled, :deleted_at, :genres, :cast, :crew, :artwork, :poster, :georule, :type
14
+ attr_reader :streams, :content_blocked
15
+
16
+ def initialize(hash)
17
+ @id = hash["id"]
18
+ @title = hash["title"]
19
+ @slug = hash["slug"]
20
+ @description = hash["description"]
21
+ @type_id = hash["type_id"]
22
+ @series_number = hash["series_number"]
23
+ @episodes_count = hash["episodes_count"]
24
+ @vendor_id = hash["vendor_id"]
25
+ @vendorka_id = hash["vendorka_id"]
26
+ @content_host = hash["content_host"]
27
+ @low_quality_file_id = hash["low_quality_file_id"]
28
+ @high_quality_file_id = hash["high_quality_file_id"]
29
+ @parent_id = hash["parent_id"]
30
+ @exists_on_edgecast = hash["exists_on_edgecast"]
31
+ @is_featured = hash["is_featured"]
32
+ @is_enabled = hash["is_enabled"]
33
+ @deleted_at = hash["deleted_at"]
34
+ @genres = hash["genres"]
35
+ @cast = hash["cast"]
36
+ @crew = hash["crew"]
37
+ @artwork = hash["artwork"] #TODO convert to image structs
38
+ @poster = hash["poster"] #TODO convert to image structs
39
+ @georule = hash["georule"]
40
+ @type = hash["type"]
41
+ @streams = hash["streams"]
42
+ @content_blocked = hash["content_blocked"]
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -7,12 +7,10 @@ module FilmOn
7
7
 
8
8
  Image = Struct.new(:id, :type, :size, :width, :height, :url, :copyright)
9
9
 
10
- attr_reader :hash
11
10
  attr_reader :programme, :startdatetime, :enddatetime, :duration, :length, :programme_description, :programme_name, :allow_dvr
12
11
  attr_reader :allow_reminder, :channel_id, :images, :provider, :vendor_id, :series_number, :episode_number, :series_id, :is_series
13
12
 
14
13
  def initialize(hash)
15
- @hash = hash
16
14
  @programme = hash["programme"]
17
15
  @startdatetime = hash["startdatetime"]
18
16
  @enddatetime = hash["enddatetime"]
@@ -0,0 +1,52 @@
1
+ module FilmOn
2
+ module Services
3
+ module Channels
4
+
5
+ # channel: will get the verbose details for a channel with
6
+ # the given id
7
+ #
8
+ def channel(id, opts={})
9
+ id = id.to_s
10
+ return @channel[id] if @channel[id] && !opts[:json]
11
+ json = get("channel/#{id}")
12
+ if opts[:json]
13
+ return json
14
+ end
15
+ @channel[id] = convert_channel(json)
16
+ end
17
+
18
+ # channels: will get the entire current list of channels for
19
+ # FilmOn, each channels has a small amount of useful data,
20
+ # refer to #channel for additional channel information.
21
+ #
22
+ def channels(opts={})
23
+ return @channels if @channels && !opts[:json]
24
+ json = get("channels")
25
+ if opts[:json]
26
+ return json
27
+ end
28
+ @channels = convert_channels(json)
29
+ end
30
+
31
+ # convert_channel: takes the raw JSON
32
+ # and coverts it into a nice ruby object
33
+ # normal for use after storing the JSON in
34
+ # a caching mechanism
35
+ #
36
+ def convert_channel(json)
37
+ hash = JSON.parse(json)
38
+ FilmOn::Channel.new(hash)
39
+ end
40
+
41
+ # convert_channels: takes the raw JSON
42
+ # and coverts it into a nice ruby array of
43
+ # objects
44
+ #
45
+ def convert_channels(json)
46
+ hash = JSON.parse(json)
47
+ hash.map{|ch| FilmOn::Channel.new(ch)}
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,35 @@
1
+ module FilmOn
2
+ module Services
3
+ module Groups
4
+
5
+ # groups: will get the entire current list of groups for
6
+ # FilmOn, each group holds an array of ids of associated channels
7
+ #
8
+ def groups(opts={})
9
+ return @groups if @groups && !opts[:json]
10
+ json = get("groups")
11
+ if opts[:json]
12
+ return json
13
+ end
14
+ @groups = convert_groups(json)
15
+ end
16
+
17
+ # convert_groups: takes the raw JSON
18
+ # and converts it into a nice ruby array of objects
19
+ #
20
+ def convert_groups(json)
21
+ hash = JSON.parse(json)
22
+ hash.map{|gr| FilmOn::Group.new(gr)}
23
+ end
24
+
25
+ # find_group: a convenience method to
26
+ # find the full detail of any given group
27
+ #
28
+ def find_group(id)
29
+ id = id.to_s
30
+ groups.select{|gr| gr.id == id}.first
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,55 @@
1
+ module FilmOn
2
+ module Services
3
+ module VideoOnDemand
4
+
5
+ # movies: calls the vod/search and returns
6
+ # a list of movies filtered by the params
7
+ # i.e. film_on.movies(genre: "horror") will
8
+ # return all horror movies
9
+ #
10
+ def movies(params={}, opts={})
11
+ key = Digest::MD5.hexdigest(params.to_s)
12
+ return @vod_search[key] if @vod_search[key] && !opts[:json]
13
+ json = get_vod("search", params)
14
+ if opts[:json]
15
+ return json
16
+ end
17
+ @vod_search[key] = convert_movies(json)
18
+ end
19
+
20
+ # movie: retrieve a specific movie with a given id
21
+ #
22
+ def movie(id, opts={})
23
+ id = id.to_s
24
+ return @movie[id] if @movie[id] && !opts[:json]
25
+ json = get_vod("movie", {id: id})
26
+ if opts[:json]
27
+ return json
28
+ end
29
+ @movie[id] = convert_movie(json)
30
+ end
31
+
32
+ # convert_movies: takes the raw JSON
33
+ # and coverts it into a nice array of ruby objects
34
+ # normal for use after storing the JSON in
35
+ # a caching mechanism
36
+ #
37
+ def convert_movies(json)
38
+ hash = JSON.parse(json)["response"]
39
+ hash.map{|movie| FilmOn::Movie.new(movie) }
40
+ end
41
+
42
+ # convert_movie: takes the raw JSON
43
+ # and coverts it into a nice ruby object
44
+ # normal for use after storing the JSON in
45
+ # a caching mechanism
46
+ #
47
+ def convert_movie(json)
48
+ hash = JSON.parse(json)["response"]
49
+ FilmOn::Movie.new(hash)
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+
data/lib/film_on.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "film_on/version"
2
- require "film_on/services"
3
- require "film_on/helpers/channel_helper"
4
- require "film_on/helpers/group_helper"
2
+ require "film_on/services/channels"
3
+ require "film_on/services/groups"
4
+ require "film_on/services/video_on_demand"
5
5
  require "film_on/base"
6
6
  require "film_on/models/channel"
7
7
  require "film_on/models/group"
8
8
  require "film_on/models/programme"
9
+ require "film_on/models/movie"
9
10
 
10
11
  module FilmOn
11
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: film_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Hanscombe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,12 +114,13 @@ files:
114
114
  - film_on.gemspec
115
115
  - lib/film_on.rb
116
116
  - lib/film_on/base.rb
117
- - lib/film_on/helpers/channel_helper.rb
118
- - lib/film_on/helpers/group_helper.rb
119
117
  - lib/film_on/models/channel.rb
120
118
  - lib/film_on/models/group.rb
119
+ - lib/film_on/models/movie.rb
121
120
  - lib/film_on/models/programme.rb
122
- - lib/film_on/services.rb
121
+ - lib/film_on/services/channels.rb
122
+ - lib/film_on/services/groups.rb
123
+ - lib/film_on/services/video_on_demand.rb
123
124
  - lib/film_on/version.rb
124
125
  homepage: https://github.com/thelazycamel/film_on
125
126
  licenses:
@@ -1,25 +0,0 @@
1
- module FilmOn
2
-
3
- module ChannelHelper
4
-
5
- # #convert_channel takes the raw JSON
6
- # and coverts it into a nice ruby object
7
- # normal for use after storing the JSON in
8
- # a caching mechanism
9
- #
10
- def convert_channel(json)
11
- hash = JSON.parse(json)
12
- FilmOn::Channel.new(hash)
13
- end
14
-
15
- # #convert_channel takes the raw JSON
16
- # and coverts it into a nice ruby array of
17
- # objects
18
- #
19
- def convert_channels(json)
20
- hash = JSON.parse(json)
21
- hash.map{|ch| FilmOn::Channel.new(ch)}
22
- end
23
-
24
- end
25
- end
@@ -1,21 +0,0 @@
1
- module FilmOn
2
- module GroupHelper
3
-
4
- # #convert_groups takes the raw JSON
5
- # and converts it into a nice ruby array of objects
6
- #
7
- def convert_groups(json)
8
- hash = JSON.parse(json)
9
- hash.map{|gr| FilmOn::Group.new(gr)}
10
- end
11
-
12
- # #find_group, a convenience method to
13
- # find the full detail of any given group
14
- #
15
- def find_group(id)
16
- id = id.to_s
17
- groups.select{|gr| gr.id == id}.first
18
- end
19
-
20
- end
21
- end
@@ -1,51 +0,0 @@
1
- module FilmOn
2
-
3
- # Services: calls to the actual services of the API
4
- # each call is memoized to save calling the API multiple times
5
- # except when json requested:
6
- # pass {json: true} to get the raw JSON representation
7
- # of the channel, normally for self storage in memcache/redis cache
8
- #
9
- module Services
10
-
11
- # #channel will get the verbose details for a channel with
12
- # the given id
13
- #
14
- def channel(id, opts={})
15
- id = id.to_s
16
- return @channel[id] if @channel[id] && !opts[:json]
17
- json = get("channel/#{id}")
18
- if opts[:json]
19
- return json
20
- end
21
- @channel[id] = convert_channel(json)
22
- end
23
-
24
- # #channels will get the entire current list of channels for
25
- # FilmOn, each channels has a small amount of useful data,
26
- # refer to #channel for additional channel information.
27
- #
28
- def channels(opts={})
29
- return @channels if @channels && !opts[:json]
30
- json = get("channels")
31
- if opts[:json]
32
- return json
33
- end
34
- @channels = convert_channels(json)
35
- end
36
-
37
- # #groups will get the entire current list of groups for
38
- # FilmOn, each group holds an array of ids of associated channels
39
- #
40
- def groups(opts={})
41
- return @groups if @groups && !opts[:json]
42
- json = get("groups")
43
- if opts[:json]
44
- return json
45
- end
46
- @groups = convert_groups(json)
47
- end
48
-
49
- end
50
-
51
- end