em-tvdb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +17 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +18 -0
- data/em-tvdb.gemspec +23 -0
- data/lib/em-tvdb/client.rb +133 -0
- data/lib/em-tvdb/version.rb +3 -0
- data/lib/em-tvdb/xml_middleware.rb +30 -0
- data/lib/em-tvdb.rb +2 -0
- data/specs/spec_helper.rb +25 -0
- metadata +143 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
gem 'rake'
|
6
|
+
|
7
|
+
group(:test) do
|
8
|
+
gem 'schmurfy-bacon'
|
9
|
+
gem 'mocha', '~> 0.10.0'
|
10
|
+
gem 'factory_girl'
|
11
|
+
|
12
|
+
gem 'simplecov'
|
13
|
+
gem 'guard'
|
14
|
+
gem 'guard-bacon'
|
15
|
+
gem 'rb-fsevent'
|
16
|
+
gem 'growl'
|
17
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
# parameters:
|
3
|
+
# output => the formatted to use
|
4
|
+
# backtrace => number of lines, nil = everything
|
5
|
+
guard 'bacon', :output => "BetterOutput", :backtrace => nil do
|
6
|
+
watch(%r{^lib/em-tvdb/(.+)\.rb$}) { |m| "specs/unit/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{specs/.+\.rb$})
|
8
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Julien Ammous
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
task :test do
|
8
|
+
require 'bacon'
|
9
|
+
|
10
|
+
ENV['COVERAGE'] = "1"
|
11
|
+
|
12
|
+
Dir[File.expand_path('../specs/**/*_spec.rb', __FILE__)].each do |file|
|
13
|
+
puts "File: #{file}:"
|
14
|
+
load(file)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
data/em-tvdb.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/em-tvdb/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Julien Ammous"]
|
6
|
+
gem.email = ["schmurfy@gmail.com"]
|
7
|
+
gem.description = %q{EM tvdb website wrapper}
|
8
|
+
gem.summary = %q{EM tvdb website wrapper}
|
9
|
+
gem.homepage = "https://github.com/schmurfy/em-tvdb"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.name = "em-tvdb"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = EmTvdb::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'rest-core'
|
18
|
+
gem.add_dependency 'nokogiri', '~> 1.5.0'
|
19
|
+
gem.add_dependency 'em-http-request'
|
20
|
+
gem.add_dependency 'hashie'
|
21
|
+
gem.add_dependency 'eventmachine', '~> 1.0.0.rc'
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rest-core'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'hashie/mash'
|
5
|
+
|
6
|
+
require_relative 'xml_middleware'
|
7
|
+
|
8
|
+
|
9
|
+
class Nokogiri::XML::Node
|
10
|
+
def content_node(css)
|
11
|
+
nodes = css(css)
|
12
|
+
if nodes.size == 0
|
13
|
+
nil
|
14
|
+
elsif nodes.size == 1
|
15
|
+
nodes[0].content
|
16
|
+
else
|
17
|
+
raise "more then one node for #{css}: #{nodes.size}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module EM
|
23
|
+
|
24
|
+
class TvDB
|
25
|
+
Client = RestCore::Builder.client do
|
26
|
+
s = RestCore
|
27
|
+
use s::DefaultSite , 'http://www.thetvdb.com/api'
|
28
|
+
use s::XmlDecode
|
29
|
+
use s::CommonLogger, method(:puts)
|
30
|
+
use s::Cache , nil, 3600
|
31
|
+
run s::EmHttpRequest
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(api_key)
|
35
|
+
@api_key = api_key
|
36
|
+
@client = Client.new
|
37
|
+
end
|
38
|
+
|
39
|
+
# <?xml version="1.0"?>
|
40
|
+
# <Data>
|
41
|
+
# <Series>
|
42
|
+
# <seriesid>158661</seriesid>
|
43
|
+
# <language>en</language>
|
44
|
+
# <SeriesName>Haven</SeriesName>
|
45
|
+
# <banner>graphical/158661-g2.jpg</banner>
|
46
|
+
# <Overview>...</Overview>
|
47
|
+
# <FirstAired>2010-07-09</FirstAired>
|
48
|
+
# <IMDB_ID>tt1519931</IMDB_ID>
|
49
|
+
# <zap2it_id>SH01281487</zap2it_id>
|
50
|
+
# <id>158661</id>
|
51
|
+
# </Series>
|
52
|
+
# <Series>
|
53
|
+
# <seriesid>70971</seriesid>
|
54
|
+
# <language>en</language>
|
55
|
+
# <SeriesName>Castle Haven</SeriesName>
|
56
|
+
# <FirstAired>1969-04-01</FirstAired>
|
57
|
+
# <id>70971</id>
|
58
|
+
# </Series>
|
59
|
+
# </Data>
|
60
|
+
def search_serie(name, &block)
|
61
|
+
@client.get("/GetSeries.php", :seriesname => name) do |xml|
|
62
|
+
series = xml.css('Series').map do |serie|
|
63
|
+
Hashie::Mash.new(
|
64
|
+
:id => serie.content_node('seriesid'),
|
65
|
+
:name => serie.content_node('SeriesName'),
|
66
|
+
:overview => serie.content_node('Overview')
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
block.call(series)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# <Episode>
|
75
|
+
# <id>4158103</id>
|
76
|
+
# <Combined_episodenumber>13</Combined_episodenumber>
|
77
|
+
# <Combined_season>2</Combined_season>
|
78
|
+
# <DVD_chapter></DVD_chapter>
|
79
|
+
# <DVD_discid></DVD_discid>
|
80
|
+
# <DVD_episodenumber></DVD_episodenumber>
|
81
|
+
# <DVD_season></DVD_season>
|
82
|
+
# <Director>Shawn Piller</Director>
|
83
|
+
# <EpImgFlag>2</EpImgFlag>
|
84
|
+
# <EpisodeName>Silent Night</EpisodeName>
|
85
|
+
# <EpisodeNumber>13</EpisodeNumber>
|
86
|
+
# <FirstAired>2011-12-06</FirstAired>
|
87
|
+
# <GuestStars>Niamh Wilson|Craig Eldridge</GuestStars>
|
88
|
+
# <IMDB_ID></IMDB_ID>
|
89
|
+
# <Language>en</Language>
|
90
|
+
# <Overview>...</Overview>
|
91
|
+
# <ProductionCode></ProductionCode>
|
92
|
+
# <Rating>7.9</Rating>
|
93
|
+
# <RatingCount>14</RatingCount>
|
94
|
+
# <SeasonNumber>2</SeasonNumber>
|
95
|
+
# <Writer>Brian Millikin</Writer>
|
96
|
+
# <absolute_number></absolute_number>
|
97
|
+
# <filename>episodes/158661/4158103.jpg</filename>
|
98
|
+
# <lastupdated>1327959365</lastupdated>
|
99
|
+
# <seasonid>463844</seasonid>
|
100
|
+
# <seriesid>158661</seriesid>
|
101
|
+
# </Episode>
|
102
|
+
def episodes(serie_id, &block)
|
103
|
+
@client.get("/#{@api_key}/series/#{serie_id}/all/en.xml") do |xml|
|
104
|
+
episodes = xml.css('Episode').map do |ep|
|
105
|
+
Hashie::Mash.new(
|
106
|
+
:id => ep.content_node('id'),
|
107
|
+
:name => ep.content_node('EpisodeName'),
|
108
|
+
:episode_number => ep.content_node('EpisodeNumber').to_i,
|
109
|
+
:season_number => ep.content_node('SeasonNumber').to_i,
|
110
|
+
:overview => ep.content_node('Overview')
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
episodes.select!{|ep| ep.season_number > 0 }.sort_by(&:episode_number)
|
115
|
+
|
116
|
+
block.call(episodes)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
def xml_node(root, css)
|
122
|
+
nodes = root.css(css)
|
123
|
+
if nodes.size == 0
|
124
|
+
nil
|
125
|
+
elsif nodes.size == 1
|
126
|
+
nodes[0].content
|
127
|
+
else
|
128
|
+
raise "more then one node for #{css}: #{nodes.size}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rest-core/middleware'
|
2
|
+
|
3
|
+
class RestCore::XmlDecode
|
4
|
+
def self.members; [:xml_decode]; end
|
5
|
+
include RestCore::Middleware
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
return app.call(env) if env[DRY]
|
9
|
+
if env[ASYNC]
|
10
|
+
app.call(env.merge(ASYNC => lambda{ |response|
|
11
|
+
env[ASYNC].call(process(response))
|
12
|
+
}))
|
13
|
+
else
|
14
|
+
process(app.call(env))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def process(response)
|
19
|
+
response['RESPONSE_BODY'] = xml_decode(response['RESPONSE_BODY'])
|
20
|
+
response
|
21
|
+
# rescue
|
22
|
+
# fail(response, error)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def xml_decode(data)
|
27
|
+
Nokogiri::XML::parse(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/em-tvdb.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'bacon'
|
5
|
+
|
6
|
+
if ENV['COVERAGE']
|
7
|
+
Bacon.allow_focused_run = false
|
8
|
+
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter ".*_spec"
|
12
|
+
add_filter "/helpers/"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
$LOAD_PATH.unshift( File.expand_path('../../lib' , __FILE__) )
|
18
|
+
require 'em-tvdb'
|
19
|
+
|
20
|
+
# require 'bacon/ext/mocha'
|
21
|
+
# require 'bacon/ext/em'
|
22
|
+
|
23
|
+
# Thread.abort_on_exception = true
|
24
|
+
|
25
|
+
Bacon.summary_on_exit()
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-tvdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Julien Ammous
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-core
|
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
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.5.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: em-http-request
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hashie
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: eventmachine
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.0.0.rc
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.0.0.rc
|
94
|
+
description: EM tvdb website wrapper
|
95
|
+
email:
|
96
|
+
- schmurfy@gmail.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- Guardfile
|
104
|
+
- LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- em-tvdb.gemspec
|
108
|
+
- lib/em-tvdb.rb
|
109
|
+
- lib/em-tvdb/client.rb
|
110
|
+
- lib/em-tvdb/version.rb
|
111
|
+
- lib/em-tvdb/xml_middleware.rb
|
112
|
+
- specs/spec_helper.rb
|
113
|
+
homepage: https://github.com/schmurfy/em-tvdb
|
114
|
+
licenses: []
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: -254866884193124726
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
hash: -254866884193124726
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.24
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: EM tvdb website wrapper
|
143
|
+
test_files: []
|