Class: OSDb::Server
- Inherits:
-
Object
- Object
- OSDb::Server
- Defined in:
- lib/osdb/server.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#useragent ⇒ Object
readonly
Returns the value of attribute useragent.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #check_movie_hash(*hashes) ⇒ Object
- #info ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #login ⇒ Object
- #logout ⇒ Object
- #search_subtitles(*queries) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 |
# File 'lib/osdb/server.rb', line 10 def initialize(={}) @username = [:username] || '' @password = [:password] || '' @language = [:language] || 'eng' @useragent = [:useragent] || 'ruby-osdb v0.1' @client = ::XMLRPC::Client.new(*.values_at(:host, :path, :port, :proxy_host, :proxy_port, :http_user, :http_password, :use_ssl, :timeout)) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/osdb/server.rb', line 8 def client @client end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
8 9 10 |
# File 'lib/osdb/server.rb', line 8 def language @language end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
8 9 10 |
# File 'lib/osdb/server.rb', line 8 def password @password end |
#useragent ⇒ Object (readonly)
Returns the value of attribute useragent.
8 9 10 |
# File 'lib/osdb/server.rb', line 8 def useragent @useragent end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
8 9 10 |
# File 'lib/osdb/server.rb', line 8 def username @username end |
Instance Method Details
#check_movie_hash(*hashes) ⇒ Object
35 36 37 |
# File 'lib/osdb/server.rb', line 35 def check_movie_hash(*hashes) client.call('CheckMovieHash', token, hashes) end |
#info ⇒ Object
44 45 46 |
# File 'lib/osdb/server.rb', line 44 def info client.call('ServerInfo') end |
#login ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/osdb/server.rb', line 22 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 ⇒ Object
30 31 32 33 |
# File 'lib/osdb/server.rb', line 30 def logout client.call('LogOut', token) @token = nil end |
#search_subtitles(*queries) ⇒ Object
39 40 41 42 |
# File 'lib/osdb/server.rb', line 39 def search_subtitles(*queries) subs = client.call('SearchSubtitles', token, queries)['data'] subs ? subs.map{ |s| Sub.new(s) } : [] end |
#token ⇒ Object
18 19 20 |
# File 'lib/osdb/server.rb', line 18 def token @token ||= login end |