Class: CanControlsGateway::RcaCommand
- Inherits:
-
Object
- Object
- CanControlsGateway::RcaCommand
- Defined in:
- lib/rca_command.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#rci_uri ⇒ Object
readonly
Returns the value of attribute rci_uri.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(rci_uri, target, arguments = {}) ⇒ RcaCommand
constructor
A new instance of RcaCommand.
- #send_command ⇒ Object
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
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
8 9 10 |
# File 'lib/rca_command.rb', line 8 def arguments @arguments end |
#rci_uri ⇒ Object (readonly)
Returns the value of attribute rci_uri.
8 9 10 |
# File 'lib/rca_command.rb', line 8 def rci_uri @rci_uri end |
#target ⇒ Object (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_command ⇒ Object
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 |