class OSDb::Server

Constants

CLIENT_ARGS
DEFAULT_OPTIONS

Attributes

client[R]
language[R]
password[R]
useragent[R]
username[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/osdb/server.rb, line 20
def initialize(options={})
  @username = options[:username] || ''
  @password = options[:password] || ''
  @language = options[:language] || 'eng'
  @useragent = options[:useragent] || 'ruby-osdb v0.1'
  options = DEFAULT_OPTIONS.merge(options)
  @client = ::XMLRPC::Client.new(*options.values_at(*CLIENT_ARGS))
end

Public Instance Methods

check_movie_hash(*hashes) click to toggle source
# File lib/osdb/server.rb, line 46
def check_movie_hash(*hashes)
  client.call('CheckMovieHash', token, hashes)
end
get_imdb_movie_details(id) click to toggle source
# File lib/osdb/server.rb, line 65
def get_imdb_movie_details(id)
  Movie.new(client.call('GetIMDBMovieDetails', token, id)['data'])
end
info() click to toggle source
# File lib/osdb/server.rb, line 61
def info
  client.call('ServerInfo')
end
login() click to toggle source
# File lib/osdb/server.rb, line 33
def login
  response = client.call('LogIn', username, password, language, useragent)
  if response['status'] != '200 OK'
    raise LoginFailed.new("Failed to login with #{username} : #{password}. Server return code: #{response['status']}")
  end
  response['token']
end
logout() click to toggle source
# File lib/osdb/server.rb, line 41
def logout
  client.call('LogOut', token)
  @token = nil
end
search_imdb(options={}) click to toggle source
# File lib/osdb/server.rb, line 55
def search_imdb(options={})
  query = options.delete(:query)
  imdb = client.call('SearchMoviesOnIMDB', token, query)['data']
  imdb.size > 0 ? imdb.map{ |i| OpenStruct.new(:imdbid => i['id'], :title => i['title']) } : []
end
search_subtitles(*queries) click to toggle source
# File lib/osdb/server.rb, line 50
def search_subtitles(*queries)
  subs = client.call('SearchSubtitles', token, queries)['data']
  subs ? subs.map{ |s| Sub.new(s) } : []
end
token() click to toggle source
# File lib/osdb/server.rb, line 29
def token
  @token ||= login
end