Ruby wrapper for TVDB json api version 2.
The TVDB api version 2 documentation can be found here.
Add this line to your application's Gemfile:
gem 'tvdb2'
And then execute:
$ bundle
Or install it yourself as:
$ gem install tvdb2
First of all you need to get your API key:
require 'tvdb2'
# Create a client object with your api key
client = TVDB.new(apikey: 'YOUR_API_KEY', language: 'en')
# Search series by name
results = client.search(name: 'Game of Thrones')
puts results.map(&:name).inspect
# Get best series result by name
got = best_result = client.best_search('Game of Thrones')
puts got.name
# Get list of actors
actors = got.actors
puts actors.first.name
puts actors.first.role
puts actors.first.image_url
# Print some info about all episodes
got.episodes.each do |episode|
puts episode.x
puts episode.absoluteNumber
puts episode.seasonNumber
puts episode.number
puts episode.overview
end
# Get only episodes from 101 and 200
episodes = got.episodes(page: 2)
# Get all episodes of season 1
episodes = got.episodes(airedSeason: 1)
# Get episode by index
puts got[3].name
# Get episode by x syntax (SEASON_NUMBERxEPISODE_NUMBER)
ep = got['3x9']
puts ep.name
puts ep.x # print '3x9'
# Get banner
url = got.banner_url
# Get random banner
url = got.banner_url(random: true)
# Get poster
url = got.poster_url
# Get random poster
url = got.poster_url(random: true)
# Get all posters
posters = got.posters
puts posters.first.url
# or
posters = got.images(keyType: 'poster')
# Get all season images
images = got.season_images
puts images.first.url
# Get all season images of season 2
images = got.season_images(season: 2)
puts images.first.url
# Switch language
ep = got['3x9']
client.language = 'it'
puts ep.name # print episode title in italian
client.language = 'en'
puts ep.name # print episode title in english
# or you can swith language only in a block
client.with_language(:it) do
puts ep.name
end
The complete documentation can be found here.
This wrapper do not coverage all 100% api REST endpoints. Missing methods are:
GET /series/{id}/filter
GET /updated/query
GET /user
GET /user/favorites
DELETE /user/favorites/{id}
PUT /user/favorites/{id}
GET /user/ratings
GET /user/ratings/query
DELETE /user/ratings/{itemType}/{itemId}
PUT /user/ratings/{itemType}/{itemId}/{itemRating}
Bug reports and pull requests are welcome on GitHub at https://github.com/pioz/tvdb2.
The gem is available as open source under the terms of the MIT License.