Class: OSDb::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/osdb/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
# File 'lib/osdb/server.rb', line 12

def initialize(options={})
  @username = options[:username] || ''
  @password = options[:password] || ''
  @language = options[:language] || 'eng'
  @useragent = options[:useragent] || 'ruby-osdb v0.1'
  @client = ::XMLRPC::Client.new(*options.values_at(:host, :path, :port, :proxy_host, :proxy_port, :http_user, :http_password, :use_ssl, :timeout))
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/osdb/server.rb', line 10

def client
  @client
end

#languageObject (readonly)

Returns the value of attribute language.



10
11
12
# File 'lib/osdb/server.rb', line 10

def language
  @language
end

#passwordObject (readonly)

Returns the value of attribute password.



10
11
12
# File 'lib/osdb/server.rb', line 10

def password
  @password
end

#useragentObject (readonly)

Returns the value of attribute useragent.



10
11
12
# File 'lib/osdb/server.rb', line 10

def useragent
  @useragent
end

#usernameObject (readonly)

Returns the value of attribute username.



10
11
12
# File 'lib/osdb/server.rb', line 10

def username
  @username
end

Instance Method Details

#check_movie_hash(*hashes) ⇒ Object



37
38
39
# File 'lib/osdb/server.rb', line 37

def check_movie_hash(*hashes)
  client.call('CheckMovieHash', token, hashes)
end

#infoObject



52
53
54
# File 'lib/osdb/server.rb', line 52

def info
  client.call('ServerInfo')
end

#loginObject



24
25
26
27
28
29
30
# File 'lib/osdb/server.rb', line 24

def 
  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

#logoutObject



32
33
34
35
# File 'lib/osdb/server.rb', line 32

def logout
  client.call('LogOut', token)
  @token = nil
end

#search_imdb(options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/osdb/server.rb', line 46

def search_imdb(options={})
  query = options.delete(:query)
  imdb = client.call('SearchMoviesOnIMDB', token, query)['data']
  imdb ? imdb.map{ |i| OpenStruct.new(:imdbid => i['id'], :title => i['title']) } : []
end

#search_subtitles(*queries) ⇒ Object



41
42
43
44
# File 'lib/osdb/server.rb', line 41

def search_subtitles(*queries)
  subs = client.call('SearchSubtitles', token, queries)['data']
  subs ? subs.map{ |s| Sub.new(s) } : []
end

#tokenObject



20
21
22
# File 'lib/osdb/server.rb', line 20

def token
  @token ||= 
end