Class: MiOS::Action

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

Instance Method Summary collapse

Constructor Details

#initialize(device, service_id, action, parameters = {}) ⇒ Action

Returns a new instance of Action.



5
6
7
# File 'lib/mios/action.rb', line 5

def initialize(device, service_id, action, parameters={})
  @device, @service_id, @action, @parameters = device, service_id, action, parameters
end

Instance Method Details

#take(async = false, &block) ⇒ Object



9
10
11
12
13
# File 'lib/mios/action.rb', line 9

def take(async=false, &block)
  response = MultiJson.load(@device.client.get("#{@device.base_uri}/data_request", url_params).content)
  # Are there ever more than one jobs from a device action?
  Job.new(@device, response.values.first['JobID'], async, &block)
end

#url_paramsObject



15
16
17
18
19
20
21
22
23
# File 'lib/mios/action.rb', line 15

def url_params
  {
    :id => 'action',
    :DeviceNum => @device.attributes["id"],
    :action => @action,
    :serviceId => @service_id,
    :output_format => :json,
  }.merge(@parameters)
end