Skip to content

Instantly share code, notes, and snippets.

@theareba
Last active September 22, 2015 22:04
Show Gist options
  • Save theareba/6814b48e47f2b60734c8 to your computer and use it in GitHub Desktop.
Save theareba/6814b48e47f2b60734c8 to your computer and use it in GitHub Desktop.
module Thetvdb
class Client
attr_reader :token, :seriesName
def initialize(seriesName)
@token = API_KEY
@seriesName = seriesName
if @seriesName.empty? || @token.empty?
raise ArgumentError, 'Series Name and token are required'
end
end
def get_show
result = RestClient.get 'http://thetvdb.com/api/GetSeries.php?seriesname=' + @seriesName
doc = Nokogiri::XML(result)
seriesId = doc.at('seriesid').text
series_data = RestClient.get 'http://thetvdb.com/api/' + @token + '/series/' + seriesId + '/all/en.xml'
return series_data
end
end
end
source 'https://rubygems.org'
# Specify your gem's dependencies in thetvdb.gemspec
gemspec
gem 'nokogiri'
gem 'rest-client'
gem 'thetvdb-ruby', '~> 0.1.0'
..
def index
show = Thetvdb::Client.new("Amazing race").get_show
render json: Hash.from_xml(show)
end
..
require 'thetvdb'
API_KEY = "9EF1D1E7D28FDA0B"
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'thetvdb/version'
Gem::Specification.new do |spec|
spec.name = "thetvdb-ruby"
spec.version = Thetvdb::VERSION
spec.authors = ["Victor Areba"]
spec.email = ["vicgoburg@gmail.com"]
spec.summary = %q{Ruby wrapper for TVDB API}
spec.description = %q{Get access to your favorite tv shows and it's episodes details}
spec.homepage = "https://github.com/theareba/thetvdb-ruby"
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.9"
spec.add_development_dependency "rake", "~> 10.0"
end
require "thetvdb/version"
require 'rest-client'
require 'nokogiri'
require 'thetvdb/client'
require "thetvdb/version"
require 'rest-client'
require 'nokogiri'
class ThetvdbGenerator < Rails::Generators::Base
source_root File.expand_path("../templates", __FILE__)
def create_initializer_file
#create_file "config/initializers/thetvdb.rb"
copy_file "thetvdb.rb", "config/initializers/thetvdb.rb"
end
end
require 'thetvdb'
API_KEY = "Your API Key"
module Thetvdb
VERSION = "0.1.0"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment