Midna 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Joost Baaij
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,91 @@
1
+ = midna
2
+
3
+ Ruby interface to the Midna API. See the [Rdoc]http://rdoc.info/projects/tilsammans/midna on how to use it.
4
+
5
+ This gem chats with the Midna API so you don't have to. It will give you objects in the Midna namespace, which you can query like Active Record:
6
+
7
+ # Information about a Broadcaster, such as AVRO
8
+ Midna::Broadcaster.find('avro')
9
+ # All series for the given Broadcaster
10
+ Midna::Broadcaster.series('avro')
11
+
12
+ # all channels
13
+ Midna::Channel.all
14
+ # alphanumeric; like NL1
15
+ Midna::Channel.find(code)
16
+
17
+ # series ID from the omroep player
18
+ Midna::Series.find(id)
19
+ # searches the Solr index by series name
20
+ Midna::Series.search(query)
21
+
22
+ # aflevering/episode ID from the omroep player
23
+ Midna::Episode.find(id)
24
+ # all episodes for the given Series
25
+ Midna::Episode.series(id)
26
+ # all episodes for the given Series in the given time window
27
+ # start and end are integers (unixtimes)
28
+ Midna::Episode.series_window(id, start, end)
29
+ # all episodes for the given Series until the given time
30
+ # start is an integer (unixtime) and defaults to the current time
31
+ Midna::Episode.series_until(id, start)
32
+ # all episodes for the given Series since the given time
33
+ # start is an integer (unixtime) and defaults to the current time
34
+ Midna::Episode.series_since(id, start)
35
+
36
+ # code is Channel code
37
+ Midna::Broadcast.channel(code)
38
+ # all broadcasts for the given Channel in the given time window
39
+ # start and end are integers (unixtimes)
40
+ Midna::Broadcast.channel_window(id, start, end)
41
+
42
+ All of these methods will return hashes or arrays of hashes.
43
+
44
+ Also, Midna is Zelda's goth sister.
45
+
46
+ == Installation in Rails
47
+
48
+ Install this plugin as a gem.
49
+
50
+ For Rails 2, in config/environment.rb
51
+
52
+ config.gem 'midna'
53
+
54
+ For Rails 3, in Gemfile
55
+
56
+ gem 'midna'
57
+
58
+ Then run <tt>rake gems:install</tt>.
59
+
60
+ == Usage in plain Ruby
61
+
62
+ First install the gem on your machine like usual:
63
+
64
+ $ gem install midna
65
+
66
+ Use <tt>sudo</tt> if your setup requires it. After this you can require it in your code and work with Midna from there.
67
+
68
+ require 'rubygems'
69
+ require 'midna'
70
+
71
+ puts Midna::Channel.all
72
+ # => [{"name"=>"Nederland 1", "code"=>"NL1"}, {"name"=>"Nederland 2", "code"=>"NL2"}, {"name"=>"Nederland 3 & Z@pp", "code"=>"NL3"}]
73
+
74
+
75
+ == Configuration
76
+
77
+ If you are using rails, create a file called <tt>config/initializers/midna.rb</tt> with the following configuration. If you are using the gem, execute these lines before you first call any Midna objects.
78
+
79
+ The gem connects to <tt>midna.omroep.nl</tt> by default. You can override this by setting the +base_uri+:
80
+
81
+ Midna.base_uri = 'http://some.other.host'
82
+
83
+ == Prerequisites
84
+
85
+ The HTTparty[http://github.com/jnunemaker/httparty] gem.
86
+
87
+ gem install httparty
88
+
89
+ == Copyright
90
+
91
+ Copyright (c) 2010 Joost Baaij. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.0
data/lib/midna.rb ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'httparty'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'httparty', '>= 0.4.4'
6
+ require 'httparty'
7
+ end
8
+
9
+ require 'midna/channel'
10
+ require 'midna/episode'
11
+ require 'midna/series'
12
+ require 'midna/broadcast'
13
+ require 'midna/broadcaster'
14
+
15
+ class Midna
16
+ include HTTParty
17
+ base_uri 'http://midna.omroep.nl'
18
+ format :xml
19
+
20
+ # allow override of the base uri
21
+ def self.base_uri=(uri)
22
+ base_uri(uri)
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class Midna
2
+ class Broadcast
3
+ # Return broadcasts for a Channel, based on the channel +code+.
4
+ def self.channel(code)
5
+ Midna.get("/channels/#{code}/broadcasts.xml").to_hash["broadcasts"]
6
+ end
7
+
8
+ # Return broadcasts for a Channel in a given time window.
9
+ # +starttime+ and +endtime+ are integers (unixtimes).
10
+ def self.channel_window(code, starttime, endtime)
11
+ Midna.get("/channels/#{code}/broadcasts.xml?start=#{starttime}&end=#{endtime}").to_hash["broadcasts"]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class Midna
2
+ class Broadcaster
3
+ # Return one Broadcaster based on its +slug+.
4
+ def self.find(slug)
5
+ Midna.get("/broadcasters/#{slug}.xml").to_hash['broadcaster']
6
+ end
7
+
8
+ # Return series for a Broadcaster, based on its +slug+.
9
+ def self.series(slug)
10
+ Midna.get("/broadcasters/#{slug}/series.xml").to_hash['series']
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class Midna
2
+ class Channel
3
+ def self.all
4
+ Midna.get("/channels.xml").to_hash["channels"]
5
+ end
6
+
7
+ def self.find(code)
8
+ Midna.get("/channels/#{code}.xml").to_hash["channel"]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ class Midna
2
+ class Episode
3
+ # Return one Episode based on its +id+.
4
+ def self.find(id)
5
+ Midna.get("/episodes/#{id}.xml").to_hash["episode"]
6
+ end
7
+
8
+ # Return episodes for a Series, based on the series +id+.
9
+ def self.series(id)
10
+ Midna.get("/series/#{id}/episodes.xml").to_hash["episodes"]
11
+ end
12
+
13
+ # Return episodes for a Series in a given time window.
14
+ # +starttime+ and +endtime+ are integers (unixtimes).
15
+ def self.series_window(id, starttime, endtime)
16
+ Midna.get("/series/#{id}/episodes.xml?start=#{starttime}&end=#{endtime}").to_hash["episodes"]
17
+ end
18
+
19
+ # Return episodes for a Series until a certain time.
20
+ # +starttime+ is an integer (unixtime) and defaults to the current time.
21
+ def self.series_until(id, starttime=nil)
22
+ if starttime.nil?
23
+ Midna.get("/series/#{id}/episodes/until.xml").to_hash["episodes"]
24
+ else
25
+ Midna.get("/series/#{id}/episodes/until.xml?start=#{starttime}").to_hash["episodes"]
26
+ end
27
+ end
28
+
29
+ # Return episodes for a Series since a certain time.
30
+ # +starttime+ is an integer (unixtime) and defaults to the current time.
31
+ def self.series_since(id, starttime=nil)
32
+ if starttime.nil?
33
+ Midna.get("/series/#{id}/episodes/since.xml").to_hash["episodes"]
34
+ else
35
+ Midna.get("/series/#{id}/episodes/since.xml?start=#{starttime}").to_hash["episodes"]
36
+ end
37
+ end
38
+
39
+ # Returns the last aired Episode for a Series.
40
+ def self.series_last(id)
41
+ Midna.get("/series/#{id}/episodes/last.xml").to_hash["episode"]
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ class Midna
2
+ class Series
3
+ def self.find(id)
4
+ Midna.get("/series/#{id}.xml").to_hash["series"]
5
+ end
6
+
7
+ def self.search(query)
8
+ Midna.get("/series/search.xml?query=#{query}").to_hash["nebo_series"]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ class Midna
2
+ VERSION = "0.8.0"
3
+ end
data/midna.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "midna/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "Midna"
7
+ s.version = Midna::VERSION
8
+ s.authors = ["Joost Baaij"]
9
+ s.email = ["joost@spacebabies.nl"]
10
+ s.homepage = "https://github.com/tilsammans/midna"
11
+ s.summary = "Ruby interface to the Midna API"
12
+ s.description = %q{This gem chats with the Midna API so you don't have to. It will give you objects in the Midna namespace, which you can query like Active Record. All of these methods will return hashes or arrays of hashes.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+
18
+ s.add_dependency 'httparty'
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Midna::Broadcast do
4
+ its(:class) { should respond_to(:channel) }
5
+ its(:class) { should respond_to(:channel_window) }
6
+
7
+ describe 'channel' do
8
+ it "should get /channels/NL1/broadcasts.xml" do
9
+ hash = stub
10
+ Midna.should_receive(:get).with("/channels/NL1/broadcasts.xml").and_return(channel = stub)
11
+ channel.stub!(:to_hash).and_return({"broadcasts" => hash})
12
+ Midna::Broadcast.channel('NL1').should equal(hash)
13
+ end
14
+ end
15
+
16
+ describe 'channel_window' do
17
+ it "should get /channels/NL1/broadcasts.xml?start=123&end=456" do
18
+ hash = stub
19
+ Midna.should_receive(:get).with("/channels/NL1/broadcasts.xml?start=123&end=456").and_return(channels = stub)
20
+ channels.stub!(:to_hash).and_return({"broadcasts" => hash})
21
+ Midna::Broadcast.channel_window('NL1', 123, 456).should equal(hash)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Midna::Broadcaster do
4
+ its(:class) { should respond_to(:find) }
5
+ its(:class) { should respond_to(:series) }
6
+
7
+ describe 'find' do
8
+ it "should get /broadcasters/slug.xml" do
9
+ hash = stub
10
+ Midna.should_receive(:get).with("/broadcasters/avro.xml").and_return(broadcaster = stub)
11
+ broadcaster.stub!(:to_hash).and_return({"broadcaster" => hash})
12
+ Midna::Broadcaster.find('avro').should equal(hash)
13
+ end
14
+ end
15
+
16
+ describe 'series' do
17
+ it "should get /broadcasters/slug/series.xml" do
18
+ hash = stub
19
+ Midna.should_receive(:get).with("/broadcasters/avro/series.xml").and_return(series = stub)
20
+ series.stub!(:to_hash).and_return({"series" => hash})
21
+ Midna::Broadcaster.series('avro').should equal(hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Midna::Channel do
4
+ its(:class) { should respond_to(:all) }
5
+ its(:class) { should respond_to(:find) }
6
+
7
+ describe 'all' do
8
+ it "should get /channels.xml" do
9
+ hash = stub
10
+ Midna.should_receive(:get).with("/channels.xml").and_return(all = stub)
11
+ all.stub!(:to_hash).and_return({"channels" => hash})
12
+ Midna::Channel.all.should equal(hash)
13
+ end
14
+ end
15
+
16
+ describe 'find' do
17
+ it "should get /channel/CODE.xml" do
18
+ hash = stub
19
+ Midna.should_receive(:get).with("/channels/NL3.xml").and_return(channel = stub)
20
+ channel.stub!(:to_hash).and_return({"channel" => hash})
21
+ Midna::Channel.find('NL3').should equal(hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe Midna::Episode do
4
+ its(:class) { should respond_to(:find) }
5
+ its(:class) { should respond_to(:series) }
6
+ its(:class) { should respond_to(:series_window) }
7
+
8
+ describe 'find' do
9
+ it "should get /episodes/ID.xml" do
10
+ hash = stub
11
+ Midna.should_receive(:get).with("/episodes/1138.xml").and_return(episode = stub)
12
+ episode.stub!(:to_hash).and_return({"episode" => hash})
13
+ Midna::Episode.find('1138').should equal(hash)
14
+ end
15
+ end
16
+
17
+ describe 'series' do
18
+ it "should get /series/ID/episodes.xml" do
19
+ hash = stub
20
+ Midna.should_receive(:get).with("/series/400/episodes.xml").and_return(episodes = stub)
21
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
22
+ Midna::Episode.series('400').should equal(hash)
23
+ end
24
+ end
25
+
26
+ describe 'series_window' do
27
+ it "should get /series/ID/episodes?start=123&end=456.xml" do
28
+ hash = stub
29
+ Midna.should_receive(:get).with("/series/400/episodes.xml?start=123&end=456").and_return(episodes = stub)
30
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
31
+ Midna::Episode.series_window('400', 123, 456).should equal(hash)
32
+ end
33
+ end
34
+
35
+ describe 'series_until' do
36
+ describe 'without time' do
37
+ it "should get /series/ID/episodes/until.xml" do
38
+ hash = stub
39
+ Midna.should_receive(:get).with("/series/400/episodes/until.xml").and_return(episodes = stub)
40
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
41
+ Midna::Episode.series_until('400').should equal(hash)
42
+ end
43
+ end
44
+
45
+ describe 'with time' do
46
+ it "should get /series/ID/episodes/until.xml" do
47
+ hash = stub
48
+ Midna.should_receive(:get).with("/series/400/episodes/until.xml?start=123").and_return(episodes = stub)
49
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
50
+ Midna::Episode.series_until('400', 123).should equal(hash)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'series_since' do
56
+ describe 'without time' do
57
+ it "should get /series/ID/episodes/since.xml" do
58
+ hash = stub
59
+ Midna.should_receive(:get).with("/series/400/episodes/since.xml").and_return(episodes = stub)
60
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
61
+ Midna::Episode.series_since('400').should equal(hash)
62
+ end
63
+ end
64
+
65
+ describe 'with time' do
66
+ it "should get /series/ID/episodes/since.xml" do
67
+ hash = stub
68
+ Midna.should_receive(:get).with("/series/400/episodes/since.xml?start=123").and_return(episodes = stub)
69
+ episodes.stub!(:to_hash).and_return({"episodes" => hash})
70
+ Midna::Episode.series_since('400', 123).should equal(hash)
71
+ end
72
+ end
73
+
74
+ describe "last" do
75
+ it "should get /series/ID/episodes/last.xml" do
76
+ hash = stub
77
+ Midna.should_receive(:get).with("/series/400/episodes/last.xml").and_return(episode = stub)
78
+ episode.stub!(:to_hash).and_return({"episode" => hash})
79
+ Midna::Episode.series_last('400').should equal(hash)
80
+ end
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Midna::Series do
4
+ its(:class) { should respond_to(:find) }
5
+ its(:class) { should respond_to(:search) }
6
+
7
+ describe 'find' do
8
+ it "should get /series/ID.xml" do
9
+ hash = stub
10
+ Midna.should_receive(:get).with("/series/1200.xml").and_return(series = stub)
11
+ series.stub!(:to_hash).and_return({"series" => hash})
12
+ Midna::Series.find(1200).should equal(hash)
13
+ end
14
+ end
15
+
16
+ describe 'search' do
17
+ it "should get /series/search.xml?query=QUERY" do
18
+ hash = stub
19
+ Midna.should_receive(:get).with("/series/search.xml?query=sesam").and_return(series = stub)
20
+ series.stub!(:to_hash).and_return({"nebo_series" => hash})
21
+ Midna::Series.search('sesam').should equal(hash)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Midna" do
4
+ it "defines Midna::Channel" do
5
+ defined?(Midna::Channel).should be_true
6
+ end
7
+
8
+ it "allows base_uri override" do
9
+ Midna.base_uri = 'bloep'
10
+ Midna.base_uri.should == 'http://bloep'
11
+ end
12
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'midna'
5
+
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ # some optional config here
10
+ end
@@ -0,0 +1 @@
1
+ Midna::BASE_URI = 'midna.local'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Midna
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joost Baaij
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: This gem chats with the Midna API so you don't have to. It will give
31
+ you objects in the Midna namespace, which you can query like Active Record. All
32
+ of these methods will return hashes or arrays of hashes.
33
+ email:
34
+ - joost@spacebabies.nl
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .document
40
+ - .gitignore
41
+ - LICENSE
42
+ - README.rdoc
43
+ - Rakefile
44
+ - VERSION
45
+ - lib/midna.rb
46
+ - lib/midna/broadcast.rb
47
+ - lib/midna/broadcaster.rb
48
+ - lib/midna/channel.rb
49
+ - lib/midna/episode.rb
50
+ - lib/midna/series.rb
51
+ - lib/midna/version.rb
52
+ - midna.gemspec
53
+ - spec/midna/broadcast_spec.rb
54
+ - spec/midna/broadcaster_spec.rb
55
+ - spec/midna/channel_spec.rb
56
+ - spec/midna/episode_spec.rb
57
+ - spec/midna/series_spec.rb
58
+ - spec/midna_spec.rb
59
+ - spec/spec.opts
60
+ - spec/spec_helper.rb
61
+ - spec/support/midna.rb
62
+ homepage: https://github.com/tilsammans/midna
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Ruby interface to the Midna API
86
+ test_files:
87
+ - spec/midna/broadcast_spec.rb
88
+ - spec/midna/broadcaster_spec.rb
89
+ - spec/midna/channel_spec.rb
90
+ - spec/midna/episode_spec.rb
91
+ - spec/midna/series_spec.rb
92
+ - spec/midna_spec.rb
93
+ - spec/spec.opts
94
+ - spec/spec_helper.rb
95
+ - spec/support/midna.rb