Class: Opensubtitles::Server
- Inherits:
-
Object
- Object
- Opensubtitles::Server
- Defined in:
- lib/opensubtitles/server.rb
Constant Summary collapse
- CLIENT_ARGS =
[:host, :path, :port, :proxy_host, :proxy_port, :http_user, :http_password, :use_ssl, :timeout]
- DEFAULT_OPTIONS =
{ :host => 'api.opensubtitles.org', :path => '/xml-rpc', :timeout => 10 }.freeze
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
- #get_imdb_movie_details(id) ⇒ Object
- #info ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #login ⇒ Object
- #logout ⇒ Object
- #search_imdb(options = {}) ⇒ Object
- #search_subtitles(*queries) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
20 21 22 23 24 25 26 27 |
# File 'lib/opensubtitles/server.rb', line 20 def initialize(={}) @username = [:username] || '' @password = [:password] || '' @language = [:language] || 'eng' @useragent = [:useragent] || 'opensubtitles v0.1' = DEFAULT_OPTIONS.merge() @client = ::XMLRPC::Client.new(*.values_at(*CLIENT_ARGS)) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/opensubtitles/server.rb', line 10 def client @client end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
10 11 12 |
# File 'lib/opensubtitles/server.rb', line 10 def language @language end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/opensubtitles/server.rb', line 10 def password @password end |
#useragent ⇒ Object (readonly)
Returns the value of attribute useragent.
10 11 12 |
# File 'lib/opensubtitles/server.rb', line 10 def useragent @useragent end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/opensubtitles/server.rb', line 10 def username @username end |
Instance Method Details
#check_movie_hash(*hashes) ⇒ Object
46 47 48 |
# File 'lib/opensubtitles/server.rb', line 46 def check_movie_hash(*hashes) client.call('CheckMovieHash', token, hashes) end |
#get_imdb_movie_details(id) ⇒ Object
65 66 67 |
# File 'lib/opensubtitles/server.rb', line 65 def get_imdb_movie_details(id) Movie.new(client.call('GetIMDBMovieDetails', token, id)['data']) end |
#info ⇒ Object
61 62 63 |
# File 'lib/opensubtitles/server.rb', line 61 def info client.call('ServerInfo') end |
#login ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/opensubtitles/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 ⇒ Object
41 42 43 44 |
# File 'lib/opensubtitles/server.rb', line 41 def logout client.call('LogOut', token) @token = nil end |
#search_imdb(options = {}) ⇒ Object
55 56 57 58 59 |
# File 'lib/opensubtitles/server.rb', line 55 def search_imdb(={}) query = .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) ⇒ Object
50 51 52 53 |
# File 'lib/opensubtitles/server.rb', line 50 def search_subtitles(*queries) subs = client.call('SearchSubtitles', token, queries)['data'] subs ? subs.map{ |s| Sub.new(s) } : [] end |
#token ⇒ Object
29 30 31 |
# File 'lib/opensubtitles/server.rb', line 29 def token @token ||= login end |