Class: XBMC::Connection

Inherits:
Object show all
Defined in:
lib/ruby-xbmc.rb

Overview

Connection class used to specify credentials and proxy settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = nil, user = nil, pass = nil) ⇒ Connection

Returns a new instance of Connection.



140
141
142
143
144
145
# File 'lib/ruby-xbmc.rb', line 140

def initialize(host, port=nil, user=nil, pass=nil)
    @host=host
    @port=port
    @user=user
    @password=pass
end

Instance Attribute Details

#hostObject

network hostname



129
130
131
# File 'lib/ruby-xbmc.rb', line 129

def host
  @host
end

#passwordObject

password



135
136
137
# File 'lib/ruby-xbmc.rb', line 135

def password
  @password
end

#portObject

network port



131
132
133
# File 'lib/ruby-xbmc.rb', line 131

def port
  @port
end

#proxyObject

proxy getter



148
149
150
151
# File 'lib/ruby-xbmc.rb', line 148

def proxy
    return @proxy unless @proxy.nil?
    ENV["proxy"]
end

#userObject

username



133
134
135
# File 'lib/ruby-xbmc.rb', line 133

def user
  @user
end

Instance Method Details

#exec(command) ⇒ Object

:nodoc:



153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/ruby-xbmc.rb', line 153

def exec(command) #:nodoc:
    command.rstrip!
    command += "()" if command[-1,1] != ")"
    url = SCHEME + "://" + host + ":" + port + CMDPATH + command

    begin
        return open(url,"r",http_opts)
    rescue OpenURI::HTTPError => e 
        if e.io.status.first.to_i == 401
            raise (user.nil? ? UnauthenticatedError.new  : WrongCredentialsError.new )
        end
        raise e
    end
end