bierdopje 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ require 'rest-client'
2
+ require 'nokogiri'
3
+
4
+ require 'bierdopje/base'
5
+ require 'bierdopje/show'
6
+ require 'bierdopje/episode'
7
+ require 'bierdopje/subtitle'
@@ -0,0 +1,36 @@
1
+ module Bierdopje
2
+ class Base
3
+ @@api_key = nil
4
+
5
+ def initialize attributes = {}
6
+ attributes.keys.each do |key|
7
+ self.send "#{key}=", attributes[key]
8
+ end
9
+ end
10
+
11
+ protected
12
+ def fetch path
13
+ self.class.send :fetch, path
14
+ end
15
+
16
+ class << self
17
+ def api_key
18
+ @@api_key
19
+ end
20
+
21
+ def api_key= api_key
22
+ @@api_key = api_key
23
+ end
24
+
25
+ protected
26
+ def fetch path
27
+ parse(path).at_xpath('bierdopje/response')
28
+ end
29
+
30
+ def parse path
31
+ response = RestClient.get "http://api.bierdopje.com/#{api_key}/#{path}"
32
+ Nokogiri::XML.parse response
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
1
+ module Bierdopje
2
+ class Episode < Base
3
+ attr_accessor :id, :season, :episode, :code, :title, :summary, :air_date, :show_name
4
+
5
+ # Retrieve the Show this Episode belongs to.
6
+ def show
7
+ Show.find_by_name show_name
8
+ end
9
+
10
+ # Retrieve all Subtitles for this Episode.
11
+ # You can pass the language as an option.
12
+ # This either has to be +:nl+ (default) or +:en+.
13
+ def subtitles language=:nl
14
+ response = fetch "GetAllSubsForEpisode/#{id}/#{language}"
15
+ response.xpath('results/result').collect do |result|
16
+ Subtitle.new(result)
17
+ end
18
+ end
19
+
20
+ def initialize doc
21
+ attributes = {
22
+ :id => doc.at_xpath('episodeid').content,
23
+ :season => doc.at_xpath('season').content,
24
+ :episode => doc.at_xpath('episode').content,
25
+ :code => doc.at_xpath('formatted').content,
26
+ :title => doc.at_xpath('title').content,
27
+ :summary => doc.at_xpath('summary').content,
28
+ :air_date => doc.at_xpath('airdate').content,
29
+ :show_name => doc.at_xpath('showlink').content.match(/^http:\/\/www\.bierdopje\.com\/shows\/(.*)$/)[1]
30
+ }
31
+ super attributes
32
+ end
33
+
34
+ class << self
35
+ # Retrieve an Episode based on it's id.
36
+ def find id
37
+ response = parse("GetEpisodeById/#{id}").at_xpath('bierdopje/response/results')
38
+ Episode.new response
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,63 @@
1
+ module Bierdopje
2
+ class Show < Base
3
+ attr_accessor :id, :tvdb_id, :name
4
+
5
+ def initialize doc
6
+ attributes = {
7
+ :id => doc.at_xpath('showid').content,
8
+ :tvdb_id => doc.at_xpath('tvdbid').content,
9
+ :name => doc.at_xpath('showname').content
10
+ }
11
+ super attributes
12
+ end
13
+
14
+ # Retrieve Episodes that belong to this Show.
15
+ def episodes season=nil
16
+ path = season ? "GetEpisodesForSeason/#{id}/#{season}" : "GetAllEpisodesForShow/#{id}"
17
+ response = fetch path
18
+
19
+ response.xpath('results/result').collect do |result|
20
+ Episode.new(result)
21
+ end
22
+ end
23
+
24
+ # Retrieve all Subtitles for the given season for this Show.
25
+ # The season number is a required parameter.
26
+ # You can pass the language as an option.
27
+ # This either has to be +:nl+ (default) or +:en+.
28
+ def subtitles season, language=:nl
29
+ response = fetch "GetSubsForSeason/#{id}/#{season}/#{language}"
30
+ response.xpath('results/result').collect do |result|
31
+ Subtitle.new(result)
32
+ end
33
+ end
34
+
35
+ class << self
36
+ # Retrieve a Show based on it's id.
37
+ def find id
38
+ response = fetch "GetShowById/#{id}"
39
+ Show.new response
40
+ end
41
+
42
+ # Retrieve a Show based on it's thetvdb.com id.
43
+ def find_by_tvdb_id id
44
+ response = fetch "GetShowByTVDBID/#{id}"
45
+ Show.new response
46
+ end
47
+
48
+ # Retrieve a Show based on it's exact name.
49
+ def find_by_name name
50
+ response = fetch "GetShowByName/#{name}"
51
+ Show.new response
52
+ end
53
+
54
+ # Searches for Shows based on it's name.
55
+ def search query
56
+ response = fetch "FindShowByName/#{query}"
57
+ response.xpath('results/result').collect do |result|
58
+ Show.new(result)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,27 @@
1
+ module Bierdopje
2
+ class Subtitle < Base
3
+ attr_accessor :file_name, :file_size, :uploaded_at, :link
4
+
5
+ def initialize doc
6
+ attributes = {
7
+ :file_name => doc.at_xpath('filename').content,
8
+ :file_size => doc.at_xpath('filesize').content,
9
+ :uploaded_at => doc.at_xpath('pubdate').content,
10
+ :link => doc.at_xpath('downloadlink').content
11
+ }
12
+ super attributes
13
+ end
14
+
15
+ class << self
16
+ # Retrieve a Subtitle based on Show id, season number and episode number.
17
+ # You can pass the language as an option.
18
+ # This either has to be +:nl+ (default) or +:en+.
19
+ def find show_id, season_number, episode_number, language=:nl
20
+ response = fetch "GetAllSubsFor/#{show_id}/#{season_number}/#{episode_number}/#{language}"
21
+ response.xpath('results/result').collect do |result|
22
+ Subtitle.new(result)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Bierdopje
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1 @@
1
+ key: AD1E97978FD73FB3
@@ -0,0 +1 @@
1
+ key: YOUR_KEY_HERE
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Bierdopje::Episode do
4
+ describe "instance" do
5
+ describe "subtitles" do
6
+ it "should find all subtitles for a given episode" do
7
+ episode = Bierdopje::Episode.find 163480
8
+ subtitles = episode.subtitles
9
+ subtitles.count.should >= 2
10
+ subtitles.collect(&:file_name).should include('Lost.S01E01.DVDRip.XviD.AC3-UnSeeN.srt')
11
+ subtitles.collect(&:file_name).should include('lost.s01e01.dvdrip.xvid-wat.nl.srt')
12
+ end
13
+ end
14
+ end
15
+
16
+ describe "#find" do
17
+ it "should find the correct episode based on the id" do
18
+ episode = Bierdopje::Episode.find 163480
19
+ episode.id.should == '163480'
20
+ episode.season.should == '1'
21
+ episode.episode.should == '1'
22
+ episode.code.should == 'S01E01'
23
+ episode.title.should == 'Pilot (1)'
24
+ episode.summary.should include('Stripped of everything, the 48 survivors scavenge what they can from the plane for their survival.')
25
+ episode.air_date.should == '22-09-2004'
26
+ episode.show_name.should == 'lost'
27
+ episode.show.name.should == 'Lost'
28
+ episode.show.id.should == '5517'
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,66 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Bierdopje::Show do
4
+ describe "instance" do
5
+ describe "#episodes" do
6
+ it "should find all episodes for a given show" do
7
+ show = Bierdopje::Show.find 5517
8
+ episodes = show.episodes
9
+ episodes.collect(&:code).should include('S01E01')
10
+ episodes.collect(&:code).should include('S06E18')
11
+ end
12
+
13
+ it "should find all episodes within the given season for a given show" do
14
+ show = Bierdopje::Show.find 5517
15
+ episodes = show.episodes(1)
16
+ episodes.count.should == 24
17
+ episodes.collect(&:code).should include('S01E01')
18
+ episodes.collect(&:code).should_not include('S02E01')
19
+ end
20
+ end
21
+
22
+ describe "#subtitles" do
23
+ it "should find all subtitles within the given season for a given show" do
24
+ show = Bierdopje::Show.find 5517
25
+ subtitles = show.subtitles(1)
26
+ subtitles.collect(&:file_name).should include('Lost.S01E01.DVDRip.XviD.AC3-UnSeeN.srt')
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#find" do
32
+ it "should find the correct show based on the id" do
33
+ show = Bierdopje::Show.find 5517
34
+ show.id.should == '5517'
35
+ show.tvdb_id.should == '73739'
36
+ show.name.should == 'Lost'
37
+ end
38
+ end
39
+
40
+ describe "find_by_tvdb_id" do
41
+ it "should find the correct show on it's tvdb_id" do
42
+ show = Bierdopje::Show.find_by_tvdb_id 73739
43
+ show.id.should == '5517'
44
+ show.tvdb_id.should == '73739'
45
+ show.name.should == 'Lost'
46
+ end
47
+ end
48
+
49
+ describe "find_by_name" do
50
+ it "should find the correct show based on it's exact name" do
51
+ show = Bierdopje::Show.find_by_name 'Lost'
52
+ show.id.should == '5517'
53
+ show.tvdb_id.should == '73739'
54
+ show.name.should == 'Lost'
55
+ end
56
+ end
57
+
58
+ describe "search" do
59
+ it "should return all matches for the given search query" do
60
+ shows = Bierdopje::Show.search 'Lost'
61
+ shows.collect(&:id).should include('5517')
62
+ shows.collect(&:tvdb_id).should include('73739')
63
+ shows.collect(&:name).should include('Lost')
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'bierdopje'
4
+
5
+ RSpec.configure do |config|
6
+ config.before :each do
7
+ api_config = YAML.load_file(File.dirname(__FILE__) + '/api.yml')
8
+ Bierdopje::Base.api_key = api_config['key']
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Bierdopje::Episode do
4
+ describe "#find" do
5
+ it "should find the correct subtitles based on the show_id, season_number and episode_number" do
6
+ subtitles = Bierdopje::Subtitle.find 5517, 1, 1
7
+ subtitles.count.should >= 2
8
+ subtitles.collect(&:file_name).should include('Lost.S01E01.DVDRip.XviD.AC3-UnSeeN.srt')
9
+ subtitles.collect(&:file_name).should include('lost.s01e01.dvdrip.xvid-wat.nl.srt')
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bierdopje
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jeroen Jacobs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-26 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest-client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 6
33
+ - 1
34
+ version: 1.6.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 15
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 4
50
+ version: 1.4.4
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 9
62
+ segments:
63
+ - 2
64
+ - 5
65
+ version: "2.5"
66
+ type: :development
67
+ version_requirements: *id003
68
+ description: A ruby wrapper around the Bierdopje.com api
69
+ email: gems@jeroenj.be
70
+ executables: []
71
+
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - lib/bierdopje/base.rb
78
+ - lib/bierdopje/episode.rb
79
+ - lib/bierdopje/show.rb
80
+ - lib/bierdopje/subtitle.rb
81
+ - lib/bierdopje/version.rb
82
+ - lib/bierdopje.rb
83
+ - spec/api.yml
84
+ - spec/api.yml.example
85
+ - spec/episodes_spec.rb
86
+ - spec/shows_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/subtitles_spec.rb
89
+ has_rdoc: true
90
+ homepage: http://jeroenj.be
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project:
119
+ rubygems_version: 1.5.0
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: A ruby wrapper around the Bierdopje.com api
123
+ test_files:
124
+ - spec/api.yml
125
+ - spec/api.yml.example
126
+ - spec/episodes_spec.rb
127
+ - spec/shows_spec.rb
128
+ - spec/spec_helper.rb
129
+ - spec/subtitles_spec.rb