Class: KodiClient::KodiMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/kodi_client/kodi_method.rb

Overview

the client that stores

Instance Method Summary collapse

Instance Method Details

#apply_options(options) ⇒ Object



8
9
10
11
# File 'lib/kodi_client/kodi_method.rb', line 8

def apply_options(options)
  @endpoint_url = "#{options.tls ? 'https://' : 'http://'}#{options.ip}:#{options.port}/jsonrpc"
  @options = options
end

#invoke_api(request) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/kodi_client/kodi_method.rb', line 13

def invoke_api(request)
  h = request.instance_variables.each_with_object({}) do |var, hash|
    hash[var.to_s.delete('@')] = request.instance_variable_get(var)
  end

  @http_client ||= build_client
  response = @http_client.post(@endpoint_url, json: h).to_s
  JSON.parse(response)
end