class Kodi::RPC

Public Class Methods

new(uri) click to toggle source
# File lib/kodi/RPC.rb, line 7
def initialize(uri)
  @uri = uri
end

Public Instance Methods

dispatch(name, args = {}) click to toggle source
# File lib/kodi/RPC.rb, line 11
def dispatch(name, args = {})
  post_body = { 'method' => name, 'params' => args, 'jsonrpc' => '2.0', 'id' => '1' }.to_json
  resp = JSON.parse( http_post_request(post_body) )
  raise JSONRPCError, resp['error'] if resp['error']
  resp['result']
end

Private Instance Methods

http_post_request(post_body) click to toggle source
# File lib/kodi/RPC.rb, line 22
def http_post_request(post_body)
  http = Net::HTTP.new(@uri.host, @uri.port)
  request = Net::HTTP::Post.new(@uri.request_uri)
  request.basic_auth @uri.user, @uri.password
  request.content_type = 'application/json'
  request.body = post_body
  http.request(request).body
end