Tvdbjson

Description

A super-unofficial Ruby Gem for thetvdb.com 'swagger' api, please feel free to contribute!

Install the gem

Visit rubygems for instructions on how to install this gem via the command line, or for how to include it in your gemfile.

Create some environment variables

Create an account and register for your API Key on thetvdb.com

export TVDB_API_KEY="Your API Key"
export TVDB_USER_KEY="Your User Key"
export TVDB_USER_NAME="Your User Name"

Overview

You're going to need to read the source for full details, as this gem is a work in progress.

# Create an authentication object.
  auth = Tvdbjson::Authentication.new

# An auth token lasts 24 hours, so implement this as needed
  auth.refresh_token if auth.token_expired?

# Search for a Television Series
  search_results = Tvdbjson::Series.search_by_name("Game of Thrones", auth)

# Just to make the rest of this easy, we'll store the thetvdb's result for "Game of Thrones" in a variable
  game_of_thrones = search_results.first

# By the way, this gem uses awesome_print so you can get output like this:

  ap game_of_thrones
      # => {
      #             "id" => 121361,
      #           "name" => "Game of Thrones",
      #       "overview" => "Seven noble families fight for control of the mythical land of Westeros. Friction between the houses leads to full-scale war. All while a very ancient evil awakens in the farthest north. Amidst the war, a neglected military order of misfits, the Night's Watch, is all that stands between the realms of men and the icy horrors beyond.",
      #        "network" => "HBO",
      #         "banner" => "graphical/121361-g19.jpg",
      #    "first_aired" => "2011-04-17",
      #         "status" => "Continuing",
      #        "aliases" => []
      # }

# Search for images for that Television series

  search_options = { :series_id => game_of_thrones.id, :type => "fanart" }
  image_results = Tvdbjson::Image.search_by_series(search_options, auth)

  search_options = { :series_id => game_of_thrones.id, :type => "poster" }
  image_results = Tvdbjson::Image.search_by_series(search_options, auth)

  search_options = { :series_id => game_of_thrones.id, :type => "season" }
  image_results = Tvdbjson::Image.search_by_series(search_options, auth)

  search_options = { :series_id => game_of_thrones.id, :type => "seasonwide" }
  image_results = Tvdbjson::Image.search_by_series(search_options, auth)

  search_options = { :series_id => game_of_thrones.id, :type => "series" }
  image_results = Tvdbjson::Image.search_by_series(search_options, auth)

# Or perhaps just the images for Season 5 of a Television series
  search_options = { :series_id => game_of_thrones.id, :type => "season", :subkey => 5 }
  image_results = Tvdbjson::Image.search_by_series_and_season(search_options, auth)

# Or graphical fanart of a Television series (the other option being text)
  search_options = { :series_id => game_of_thrones.id, :type => "fanart", :subkey => "graphical" }
  image_results = Tvdbjson::Image.search_by_series_and_season(search_options, auth)

# Search for a specific episode
  search_query = { :series_id => game_of_thrones.id, :season_number => 6, :episode_number => 9 }
  episode_results = Tvdbjson::Episode.search_by_season_and_episode(search_query,auth)

# Return all episodes, on all pages for a series (may take a while)
  search_options = { :series_id => game_of_thrones.id }
  episode_results = Tvdbjson::Episode.all_episodes(search_options,auth)

License

MIT - For terms refer to LICENSE.md

thetvdb

The creator of this gem is in no way affiliated with thetvdb