Class: CanControlsGateway::RcaCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rci_uri, target, arguments = {}) ⇒ RcaCommand

Returns a new instance of RcaCommand.



10
11
12
13
14
# File 'lib/rca_command.rb', line 10

def initialize rci_uri, target, arguments={}
  @rci_uri   = rci_uri
  @target    = target
  @arguments = prepare_command_arguments arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



8
9
10
# File 'lib/rca_command.rb', line 8

def arguments
  @arguments
end

#rci_uriObject (readonly)

Returns the value of attribute rci_uri.



8
9
10
# File 'lib/rca_command.rb', line 8

def rci_uri
  @rci_uri
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/rca_command.rb', line 8

def target
  @target
end

Instance Method Details

#send_commandObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rca_command.rb', line 16

def send_command
  post_data = "target=#{@target}&arguments=#{@arguments}"
  url       = URI.parse(@rci_uri)
  request   = Net::HTTP::Post.new(url.path)
  begin
    response = Net::HTTP::start(url.host, url.port) { |http|
                 http.request(request, post_data)
             }
    return response.code.to_i, response.body
  rescue Exception => e
    return 500, "#{e}"
  end
end