film_on 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08b8f5e02f433943c4e6c6b9f19ea44f350d8110
4
- data.tar.gz: ddc83e4f1d96f1316ede69dbfab3a9ad1ea406df
3
+ metadata.gz: b6daa5c3826eabbbc14f6fbdbbd2c5b188a76725
4
+ data.tar.gz: 74858705d1db4df5dd193a8afe35a321d5f45134
5
5
  SHA512:
6
- metadata.gz: 86fc9879cb397f3bac8a690d01e1af7c9755c70114ca350521419d1a28d5ef0fa59e8479e4eac402229ce2700f09b1ca0a7f38d1e40fe06b83ed7149d2defe5f
7
- data.tar.gz: 553d3e11e53e8426e4c478ecd6396d913c2d0c84eb5062ab44d74cc5ac0246fb2a614e51dc96835c3ffdcbc002d62a543c4c86974e43eafa21334b062bf7440a
6
+ metadata.gz: 3d38f63ee5436ff621c56564fc2d75a647257298e4421616489c8819470e6f0f1db07fe43133a777a7a262d30bcfc9656463c6d4f77ba1324679e99f80549046
7
+ data.tar.gz: 356205369ac03fd4fed40cd60ddb692b6e047c0933b6c2470b42f026cb4027a841d71df1df5fe7ad21b3ebd40fe2852ad11c17abb0915b5b436a49d745638aee
data/README.md CHANGED
@@ -36,6 +36,7 @@ film_on = FilmOn::Base.new(app_key, app_secret)
36
36
  film_on.channels => returns list of all channels as ruby objects
37
37
  flim_on.groups => returns list of all groups as ruby objects
38
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
39
40
 
40
41
  ## Development
41
42
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
data/lib/film_on/base.rb CHANGED
@@ -12,6 +12,17 @@ module FilmOn
12
12
 
13
13
  attr_reader :app_key, :app_secret, :session_key
14
14
 
15
+ class ApiError < StandardError; end
16
+
17
+ # FilmOn Api (http://www.filmon.com/page/api)
18
+ # initialize the wrapper with your app_key and app_secret
19
+ # for development purposes you can use "foo" and "bar"
20
+ # eg.
21
+ # film_on = FilmOn::Base.new("foo", "bar")
22
+ # film_on.channels => returns an array of channels
23
+ # film_on.groups => returns an array of channel groups
24
+ # film_on.channel(14) => returns information for channel with id 14
25
+ #
15
26
  def initialize(app_key, app_secret)
16
27
  @app_key = app_key
17
28
  @app_secret = app_secret
@@ -19,6 +30,11 @@ module FilmOn
19
30
  init_request
20
31
  end
21
32
 
33
+ private
34
+
35
+ # Create the initial handshake to FilmOn
36
+ # and set the @session_key
37
+ #
22
38
  def init_request
23
39
  response = get("init")
24
40
  init_hash = JSON.parse(response)
@@ -26,8 +42,8 @@ module FilmOn
26
42
  self
27
43
  end
28
44
 
29
- private
30
-
45
+ # Make a POST request to the api with the given service, query and protocol
46
+ #
31
47
  def post(service, query={}, protocol="http://")
32
48
  query["format"] = "json"
33
49
  query["session_key"] = @session_key unless service == "init"
@@ -36,10 +52,12 @@ module FilmOn
36
52
  if response && response.code == 200
37
53
  return response.body
38
54
  else
39
- response.response
55
+ raise ApiError
40
56
  end
41
57
  end
42
58
 
59
+ # Make a GET request to the api with the given service, query and protocol
60
+ #
43
61
  def get(service, query={}, protocol="http://")
44
62
  query["format"] = "json"
45
63
  query["session_key"] = @session_key unless service == "init"
@@ -48,7 +66,7 @@ module FilmOn
48
66
  if response && response.code == 200
49
67
  return response.body
50
68
  else
51
- response.response
69
+ raise ApiError
52
70
  end
53
71
  end
54
72
 
@@ -2,15 +2,24 @@ module FilmOn
2
2
 
3
3
  module ChannelHelper
4
4
 
5
- def convert_channel(json)
6
- hash = JSON.parse(json)
7
- FilmOn::Channel.new(hash)
8
- end
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
9
14
 
10
- def convert_channels(json)
11
- hash = JSON.parse(json)
12
- hash.map{|ch| FilmOn::Channel.new(ch)}
13
- end
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
14
23
 
15
24
  end
16
25
  end
@@ -1,12 +1,19 @@
1
1
  module FilmOn
2
2
  module GroupHelper
3
3
 
4
+ # #convert_groups takes the raw JSON
5
+ # and converts it into a nice ruby array of objects
6
+ #
4
7
  def convert_groups(json)
5
8
  hash = JSON.parse(json)
6
9
  hash.map{|gr| FilmOn::Group.new(gr)}
7
10
  end
8
11
 
12
+ # #find_group, a convenience method to
13
+ # find the full detail of any given group
14
+ #
9
15
  def find_group(id)
16
+ id = id.to_s
10
17
  groups.select{|gr| gr.id == id}.first
11
18
  end
12
19
 
@@ -3,7 +3,8 @@ module FilmOn
3
3
  # FilmOn::Channel
4
4
  # Channel can have either a basic set of data or a more verbose set
5
5
  # depending on whether it is called as part of a channels list or
6
- # as in individual call
6
+ # as in individual call from #channel, takes a raw hash and converts
7
+ # it into a nice ruby object
7
8
 
8
9
  class Channel
9
10
 
@@ -1,5 +1,10 @@
1
1
  module FilmOn
2
2
 
3
+ # Group is a group of channels bundled together
4
+ # such as "Sports" or "UK Live TV"
5
+ # takes a raw hash and converts it into a nice ruby
6
+ # object
7
+
3
8
  class Group
4
9
 
5
10
  attr_reader :hash
@@ -1,5 +1,8 @@
1
1
  module FilmOn
2
2
 
3
+ # Programme holds the detail of a TV programme, it takes a raw hash and
4
+ # converts it into a nice ruby object
5
+ #
3
6
  class Programme
4
7
 
5
8
  Image = Struct.new(:id, :type, :size, :width, :height, :url, :copyright)
@@ -1,8 +1,18 @@
1
1
  module FilmOn
2
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
+ #
3
9
  module Services
4
10
 
11
+ # #channel will get the verbose details for a channel with
12
+ # the given id
13
+ #
5
14
  def channel(id, opts={})
15
+ id = id.to_s
6
16
  return @channel[id] if @channel[id] && !opts[:json]
7
17
  json = get("channel/#{id}")
8
18
  if opts[:json]
@@ -11,6 +21,10 @@ module FilmOn
11
21
  @channel[id] = convert_channel(json)
12
22
  end
13
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
+ #
14
28
  def channels(opts={})
15
29
  return @channels if @channels && !opts[:json]
16
30
  json = get("channels")
@@ -20,6 +34,9 @@ module FilmOn
20
34
  @channels = convert_channels(json)
21
35
  end
22
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
+ #
23
40
  def groups(opts={})
24
41
  return @groups if @groups && !opts[:json]
25
42
  json = get("groups")
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.10
4
+ version: 0.0.11
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-12 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler