thetvdb_api 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +72 -1
- data/lib/thetvdb_api.rb +4 -1
- data/lib/thetvdb_api/actor.rb +2 -2
- data/lib/thetvdb_api/banner.rb +2 -2
- data/lib/thetvdb_api/base.rb +30 -9
- data/lib/thetvdb_api/episode.rb +10 -10
- data/lib/thetvdb_api/mappers/actor.rb +17 -0
- data/lib/thetvdb_api/mappers/actors.rb +10 -0
- data/lib/thetvdb_api/mappers/banner.rb +32 -0
- data/lib/thetvdb_api/mappers/banners.rb +10 -0
- data/lib/thetvdb_api/mappers/base.rb +13 -0
- data/lib/thetvdb_api/mappers/episode.rb +32 -0
- data/lib/thetvdb_api/mappers/full_series.rb +12 -0
- data/lib/thetvdb_api/mappers/search_episode.rb +10 -0
- data/lib/thetvdb_api/mappers/search_series.rb +10 -0
- data/lib/thetvdb_api/mappers/search_series/series.rb +25 -0
- data/lib/thetvdb_api/mappers/series.rb +37 -0
- data/lib/thetvdb_api/mappers/update.rb +14 -0
- data/lib/thetvdb_api/mappers/update/banner.rb +19 -0
- data/lib/thetvdb_api/mappers/update/element.rb +10 -0
- data/lib/thetvdb_api/mappers/update/episode.rb +8 -0
- data/lib/thetvdb_api/mappers/update/series.rb +8 -0
- data/lib/thetvdb_api/response.rb +30 -0
- data/lib/thetvdb_api/search.rb +8 -8
- data/lib/thetvdb_api/series.rb +4 -4
- data/lib/thetvdb_api/update.rb +42 -8
- data/lib/thetvdb_api/version.rb +1 -1
- data/spec/integrations/actor_spec.rb +1 -1
- data/spec/integrations/banner_spec.rb +1 -1
- data/spec/integrations/client_spec.rb +16 -16
- data/spec/integrations/episode_spec.rb +4 -4
- data/spec/integrations/search_spec.rb +5 -5
- data/spec/integrations/series_spec.rb +2 -2
- data/spec/integrations/update_spec.rb +10 -4
- data/spec/spec_helper.rb +4 -0
- data/spec/thetvdb_api/base_spec.rb +39 -7
- data/spec/thetvdb_api/episode_spec.rb +4 -4
- data/spec/thetvdb_api/mappers/actor_spec.rb +15 -0
- data/spec/thetvdb_api/mappers/banner_spec.rb +31 -0
- data/spec/thetvdb_api/mappers/search_series/series_spec.rb +15 -0
- data/spec/thetvdb_api/mappers/series_spec.rb +31 -0
- data/spec/thetvdb_api/mappers/update/banner_spec.rb +15 -0
- data/spec/thetvdb_api/response_spec.rb +60 -0
- data/spec/thetvdb_api/search_spec.rb +13 -13
- data/spec/thetvdb_api/series_spec.rb +6 -6
- data/spec/thetvdb_api/update_spec.rb +24 -0
- data/thetvdb_api.gemspec +2 -1
- metadata +48 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85d1ce2f2bb54573fe303c0ec2bdf4c00c3ca8b0
|
4
|
+
data.tar.gz: 5fd366803383b832fe7ce43733ddbd2b9e6ee593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ad836dd05a2e2936e516742d35c9c7ca3379190058878c38dcc0614b0b426857ee494bb8cfe5d100af97f0e423f18e8ce72b1369b74a605ac6d339b3c354f6e
|
7
|
+
data.tar.gz: 5727390c2cc4016737ce73be4ce21b529894082334d07f8cc97ccc7058ae234d9e1991529b8275fb5c12e42e604da54a5cc660911d17925543fb0269e85a59ff
|
data/README.md
CHANGED
@@ -41,7 +41,7 @@ client = ThetvdbApi::Client.new
|
|
41
41
|
client.search.get_series('buffy')
|
42
42
|
client.search.get_series_by_imdb_id('...')
|
43
43
|
client.search.get_series_by_zap2it_id('...')
|
44
|
-
client.search.
|
44
|
+
client.search.get_episode('123', air_date)
|
45
45
|
```
|
46
46
|
|
47
47
|
Search series by id
|
@@ -86,6 +86,77 @@ client.update.month
|
|
86
86
|
client.update.all
|
87
87
|
```
|
88
88
|
|
89
|
+
ThetvdbApi return response class with pure xml (in body method) string fetched by Faraday, but it can be automatically mapped to Object. I have prepared some class for it which using happymapper gem. You should pass mapper options at the end of method arguments.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'thetvdb_api/mappers/update'
|
93
|
+
client = ThetvdbApi::Client.new
|
94
|
+
client.update.day(mapper: ThetvdbApi::Mappers::Update)
|
95
|
+
```
|
96
|
+
|
97
|
+
## Mappers for:
|
98
|
+
|
99
|
+
### Search
|
100
|
+
```ruby
|
101
|
+
require 'thetvdb_api/mappers/search_series'
|
102
|
+
client = ThetvdbApi::Client.new
|
103
|
+
client.search.get_series('buffy', mapper: ThetvdbApi::Mappers::SearchSeries)
|
104
|
+
client.search.get_series_by_imdb_id('...', mapper: ThetvdbApi::Mappers::SearchSeries)
|
105
|
+
client.search.get_series_by_zap2it_id('...', mapper: ThetvdbApi::Mappers::SearchSeries)
|
106
|
+
```
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
require 'thetvdb_api/mappers/search_episode'
|
110
|
+
client = ThetvdbApi::Client.new
|
111
|
+
client.search.get_episode('123', air_date, mapper: ThetvdbApi::Mappers::SearchEpisode)
|
112
|
+
```
|
113
|
+
|
114
|
+
### Series
|
115
|
+
```ruby
|
116
|
+
require 'thetvdb_api/mappers/series'
|
117
|
+
client = ThetvdbApi::Client.new
|
118
|
+
client.series.find('123', mapper: ThetvdbApi::Mappers::Series)
|
119
|
+
```
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
require 'thetvdb_api/mappers/full_series'
|
123
|
+
client = ThetvdbApi::Client.new
|
124
|
+
client.series.find_full('123', mapper: ThetvdbApi::Mappers::FullSeries)
|
125
|
+
```
|
126
|
+
|
127
|
+
### Actors
|
128
|
+
```ruby
|
129
|
+
require 'thetvdb_api/mappers/actors'
|
130
|
+
client = ThetvdbApi::Client.new
|
131
|
+
client.actor.all(series_id, mapper: ThetvdbApi::Mappers::Actors)
|
132
|
+
```
|
133
|
+
|
134
|
+
### Banners
|
135
|
+
```ruby
|
136
|
+
require 'thetvdb_api/mappers/banners'
|
137
|
+
client = ThetvdbApi::Client.new
|
138
|
+
client.banner.all(series_id, mapper: ThetvdbApi::Mappers::Banners)
|
139
|
+
```
|
140
|
+
|
141
|
+
### Episodes
|
142
|
+
```ruby
|
143
|
+
require 'thetvdb_api/mappers/episode'
|
144
|
+
client = ThetvdbApi::Client.new
|
145
|
+
client.episode.find_by_default_order(series_id, season, episode, mapper: ThetvdbApi::Mappers::Episode)
|
146
|
+
client.episode.find_by_dvd_order(series_id, season, episode, mapper: ThetvdbApi::Mappers::Episode)
|
147
|
+
client.episode.find_by_absolute_order(series_id, absolute, mapper: ThetvdbApi::Mappers::Episode)
|
148
|
+
client.episode.find(episode_id, mapper: ThetvdbApi::Mappers::Episode)
|
149
|
+
```
|
150
|
+
|
151
|
+
### Updates
|
152
|
+
```ruby
|
153
|
+
require 'thetvdb_api/mappers/update'
|
154
|
+
client = ThetvdbApi::Client.new
|
155
|
+
client.update.day(mapper: ThetvdbApi::Mappers::Update)
|
156
|
+
```
|
157
|
+
|
158
|
+
You can write own mappers which parse xml and convert it to hash. Remember that your class must have "parse" class method.
|
159
|
+
|
89
160
|
## Contributing
|
90
161
|
|
91
162
|
1. Fork it
|
data/lib/thetvdb_api.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
module ThetvdbApi
|
1
|
+
module ThetvdbApi
|
2
|
+
module Mappers; end
|
3
|
+
end
|
2
4
|
|
3
5
|
require 'thetvdb_api/version'
|
4
6
|
require 'thetvdb_api/configuration'
|
7
|
+
require 'thetvdb_api/response'
|
5
8
|
require 'thetvdb_api/client'
|
6
9
|
require 'thetvdb_api/base'
|
7
10
|
require 'thetvdb_api/search'
|
data/lib/thetvdb_api/actor.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class ThetvdbApi::Actor < ThetvdbApi::Base
|
2
|
-
def find(series_id)
|
3
|
-
get("#{series_uri}/actors.xml").params(series_id: series_id).response
|
2
|
+
def find(series_id, options = {})
|
3
|
+
get("#{series_uri}/actors.xml").params({ series_id: series_id }.merge(options)).response
|
4
4
|
end
|
5
5
|
end
|
data/lib/thetvdb_api/banner.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class ThetvdbApi::Banner < ThetvdbApi::Base
|
2
|
-
def find(series_id)
|
3
|
-
get("#{series_uri}/banners.xml").params(series_id: series_id).response
|
2
|
+
def find(series_id, options = {})
|
3
|
+
get("#{series_uri}/banners.xml").params({ series_id: series_id }.merge(options)).response
|
4
4
|
end
|
5
5
|
end
|
data/lib/thetvdb_api/base.rb
CHANGED
@@ -1,33 +1,40 @@
|
|
1
|
-
require '
|
1
|
+
require 'faraday'
|
2
2
|
require 'uri_template'
|
3
3
|
|
4
4
|
class ThetvdbApi::Base
|
5
|
-
include HTTParty
|
6
|
-
base_uri 'http://thetvdb.com/api/'
|
7
|
-
|
8
5
|
def initialize(client)
|
9
6
|
@client = client
|
10
7
|
@params = {}
|
8
|
+
@mapper = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def connection
|
12
|
+
@connection ||= Faraday.new(url: base_url)
|
11
13
|
end
|
12
14
|
|
13
15
|
def get(uri)
|
14
16
|
@uri_template = URITemplate.new(uri)
|
15
|
-
|
16
17
|
self
|
17
18
|
end
|
18
19
|
|
19
20
|
def params(options)
|
20
|
-
@
|
21
|
-
|
21
|
+
@mapper = options.delete(:mapper)
|
22
|
+
@params = { language: @client.language }.merge(options)
|
22
23
|
self
|
23
24
|
end
|
24
25
|
|
25
26
|
def response
|
26
|
-
|
27
|
+
assert_uri_template
|
28
|
+
ThetvdbApi::Response.new(connection.get(uri, @options), @mapper)
|
27
29
|
end
|
28
30
|
|
29
31
|
def prepare_uri
|
30
|
-
|
32
|
+
assert_uri_template
|
33
|
+
@uri_template.expand(@params.merge(api_key: api_key))
|
34
|
+
end
|
35
|
+
|
36
|
+
def url
|
37
|
+
"#{base_url}#{uri}"
|
31
38
|
end
|
32
39
|
|
33
40
|
def uri
|
@@ -49,4 +56,18 @@ class ThetvdbApi::Base
|
|
49
56
|
def language
|
50
57
|
@client.language
|
51
58
|
end
|
59
|
+
|
60
|
+
def api_key
|
61
|
+
@client.api_key
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def assert_uri_template
|
67
|
+
raise "Path doesn't exists, use get(path) to setup path for request" unless @uri_template
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_url
|
71
|
+
'http://thetvdb.com/api/'
|
72
|
+
end
|
52
73
|
end
|
data/lib/thetvdb_api/episode.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
class ThetvdbApi::Episode < ThetvdbApi::Base
|
2
|
-
def find_by_default_order(series_id, season, episode,
|
3
|
-
find_by_order('default', series_id, season, episode,
|
2
|
+
def find_by_default_order(series_id, season, episode, options = {})
|
3
|
+
find_by_order('default', series_id, season, episode, options)
|
4
4
|
end
|
5
5
|
|
6
|
-
def find_by_dvd_order(series_id, season, episode,
|
7
|
-
find_by_order('dvd', series_id, season, episode,
|
6
|
+
def find_by_dvd_order(series_id, season, episode, options = {})
|
7
|
+
find_by_order('dvd', series_id, season, episode, options)
|
8
8
|
end
|
9
9
|
|
10
|
-
def find_by_absolute_order(series_id, absolute,
|
10
|
+
def find_by_absolute_order(series_id, absolute, options = {})
|
11
11
|
get("#{series_uri}/absolute/{absolute}/{language}.xml").
|
12
|
-
params(series_id: series_id, absolute: absolute
|
12
|
+
params({ series_id: series_id, absolute: absolute }.merge(options)).response
|
13
13
|
end
|
14
14
|
|
15
|
-
def find(episode_id,
|
16
|
-
get("{api_key}/episodes/{episode_id}/{language}.xml").params(episode_id: episode_id
|
15
|
+
def find(episode_id, options = {})
|
16
|
+
get("{api_key}/episodes/{episode_id}/{language}.xml").params({ episode_id: episode_id }.merge(options)).response
|
17
17
|
end
|
18
18
|
|
19
|
-
def find_by_order(order, series_id, season, episode,
|
19
|
+
def find_by_order(order, series_id, season, episode, options)
|
20
20
|
get("#{series_uri}/{order}/{season}/{episode}/{language}.xml").
|
21
|
-
params(series_id: series_id, season: season, episode: episode,
|
21
|
+
params({ series_id: series_id, season: season, episode: episode, order: order }.merge(options)).response
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
|
3
|
+
class ThetvdbApi::Mappers::Actor
|
4
|
+
include HappyMapper
|
5
|
+
|
6
|
+
tag 'Actor'
|
7
|
+
|
8
|
+
element :id, Integer
|
9
|
+
element :image_path, String, tag: 'Image'
|
10
|
+
element :name, String, tag: 'Name'
|
11
|
+
element :role, String, tag: 'Role'
|
12
|
+
element :sort_order, Integer, tag: 'SortOrder'
|
13
|
+
|
14
|
+
def image_url
|
15
|
+
image_path ? "http://thetvdb.com/banners/#{image_path}" : nil
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
|
3
|
+
class ThetvdbApi::Mappers::Banner
|
4
|
+
include HappyMapper
|
5
|
+
|
6
|
+
tag 'Banner'
|
7
|
+
|
8
|
+
element :id, Integer
|
9
|
+
element :path, String, tag: 'BannerPath'
|
10
|
+
element :thumbnail_path, String, tag: 'ThumbnailPath'
|
11
|
+
element :vignette_path, String, tag: 'VignettePath'
|
12
|
+
element :type, String, tag: 'BannerType'
|
13
|
+
element :type2, String, tag: 'BannerType2'
|
14
|
+
element :language, String, tag: 'Language'
|
15
|
+
element :season, Integer, tag: 'Season'
|
16
|
+
element :rating, Float, tag: 'Rating'
|
17
|
+
element :rating_count, Integer, tag: 'RatingCount'
|
18
|
+
element :series_name, String, tag: 'SeriesName'
|
19
|
+
element :colors, String, tag: 'Colors'
|
20
|
+
|
21
|
+
def url
|
22
|
+
path ? "http://thetvdb.com/banners/#{path}" : nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def thumbnail_url
|
26
|
+
thumbnail_path ? "http://thetvdb.com/banners/#{thumbnail_path}" : nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def vignette_url
|
30
|
+
vignette_path ? "http://thetvdb.com/banners/#{vignette_path}" : nil
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
|
3
|
+
class ThetvdbApi::Mappers::Base
|
4
|
+
include HappyMapper
|
5
|
+
|
6
|
+
element :id, Integer
|
7
|
+
element :first_aired, Date, tag: 'FirstAired'
|
8
|
+
element :imdb_id, String, tag: 'IMDB_ID'
|
9
|
+
element :language, String, tag: 'Language'
|
10
|
+
element :overview, String, tag: 'Overview'
|
11
|
+
element :rating, Float, tag: 'Rating'
|
12
|
+
element :rating_count, Integer, tag: 'RatingCount'
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
require 'base'
|
3
|
+
|
4
|
+
class ThetvdbApi::Mappers::Episode < ThetvdbApi::Mappers::Base
|
5
|
+
tag 'Episode'
|
6
|
+
|
7
|
+
element :combined_episode_number, Integer, tag: 'Combined_episodenumber'
|
8
|
+
element :combined_season, Integer, tag: 'Combined_season'
|
9
|
+
element :dvd_chapter, String, tag: 'DVD_chapter'
|
10
|
+
element :dvd_discid, String, tag: 'DVD_discid'
|
11
|
+
element :dvd_episodenumber, String, tag: 'DVD_episodenumber'
|
12
|
+
element :dvd_season, String, tag: 'DVD_season'
|
13
|
+
element :director, String, tag: 'Director'
|
14
|
+
element :ep_img_flag, Integer, tag: 'EpImgFlag'
|
15
|
+
element :name, String, tag: 'EpisodeName'
|
16
|
+
element :number, String, tag: 'EpisodeNumber'
|
17
|
+
element :guest_stars, String, tag: 'GuestStars'
|
18
|
+
element :production_code, String, tag: 'ProductionCode'
|
19
|
+
element :season_number, Integer, tag: 'SeasonNumber'
|
20
|
+
element :writer, String, tag: 'Writer'
|
21
|
+
element :absolute_number, Integer
|
22
|
+
element :airs_after_season, Integer, tag: 'airsafter_season'
|
23
|
+
element :airs_before_episode, Integer, tag: 'airsbefore_episode'
|
24
|
+
element :airs_before_season, Integer, tag: 'airsbefore_season'
|
25
|
+
element :filename, String
|
26
|
+
element :last_updated_timestamp, Integer, tag: 'lastupdated'
|
27
|
+
element :season_id, Integer, tag: 'seasonid'
|
28
|
+
element :series_id, Integer, tag: 'seriesid'
|
29
|
+
element :thumb_added_at, Time, tag: 'thumb_added'
|
30
|
+
element :thumb_height, Integer
|
31
|
+
element :thumb_width, Integer
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
require 'thetvdb_api/mappers/episode'
|
3
|
+
require 'thetvdb_api/mappers/series'
|
4
|
+
|
5
|
+
class ThetvdbApi::Mappers::FullSeries
|
6
|
+
include HappyMapper
|
7
|
+
|
8
|
+
tag 'Data'
|
9
|
+
|
10
|
+
element :series, ThetvdbApi::Mappers::Series, tag: 'Series'
|
11
|
+
has_many :episodes, ThetvdbApi::Mappers::Episode, tag: 'Episodes'
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
|
3
|
+
class ThetvdbApi::Mappers::SearchSeries
|
4
|
+
class Series
|
5
|
+
include HappyMapper
|
6
|
+
|
7
|
+
tag 'Series'
|
8
|
+
|
9
|
+
element :id, Integer
|
10
|
+
element :series_id, Integer, tag: 'seriesid'
|
11
|
+
element :language, String
|
12
|
+
element :name, String, tag: 'SeriesName'
|
13
|
+
element :aliases, String, tag: 'AliasNames'
|
14
|
+
element :banner_path, String, tag: 'banner'
|
15
|
+
element :overview, String, tag: 'Overview'
|
16
|
+
element :first_aired, Date
|
17
|
+
element :imdb_id, String, tag: 'IMDB_ID'
|
18
|
+
element :zap2it_id, String
|
19
|
+
element :network, String, tag: 'Network'
|
20
|
+
|
21
|
+
def banner_url
|
22
|
+
banner_path ? "http://thetvdb.com/banners/#{banner_path}" : nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'happymapper'
|
2
|
+
require 'base'
|
3
|
+
|
4
|
+
class ThetvdbApi::Mappers::Series < ThetvdbApi::Mappers::Base
|
5
|
+
tag 'Series'
|
6
|
+
|
7
|
+
element :actors, String, tag: 'Actors'
|
8
|
+
element :airs_day_of_week, String, tag: 'Airs_DayOfWeek'
|
9
|
+
element :airs_time, String, tag: 'Airs_Time'
|
10
|
+
element :content_rating, String, tag: 'ContentRating'
|
11
|
+
element :genres, String, tag: 'Genre'
|
12
|
+
element :network, String, targ: 'Network'
|
13
|
+
element :network_id, Integer, targ: 'NetworkID'
|
14
|
+
element :runtime, Integer, tag: 'Runtime'
|
15
|
+
element :series_id, Integer, tag: 'SeriesID'
|
16
|
+
element :name, String, tag: 'SeriesName'
|
17
|
+
element :status, String, tag: 'Status'
|
18
|
+
element :added_at, Time, tag: 'added'
|
19
|
+
element :added_by, Integer, tag: 'adddedBy'
|
20
|
+
element :banner_path, String, tag: 'banner'
|
21
|
+
element :fanart_path, String, tag: 'fanart'
|
22
|
+
element :last_updated_timestamp, Integer, tag: 'lastupdated'
|
23
|
+
element :poster_path, String, tag: 'posters'
|
24
|
+
element :zap2it_id, String
|
25
|
+
|
26
|
+
def banner_url
|
27
|
+
banner_path ? "http://thetvdb.com/banners/#{banner_path}" : nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def fanart_url
|
31
|
+
fanart_path ? "http://thetvdb.com/banners/#{fanart_path}" : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def poster_url
|
35
|
+
poster_path ? "http://thetvdb.com/banners/#{poster_path}" : nil
|
36
|
+
end
|
37
|
+
end
|