Class: Rosumi::Locator

Inherits:
Object
  • Object
show all
Includes:
PostHelper
Defined in:
lib/rosumi/locator.rb

Constant Summary

Constants included from PostHelper

PostHelper::PORT, PostHelper::URL

Instance Attribute Summary

Attributes included from PostHelper

#devices, #http, #partition

Instance Method Summary collapse

Methods included from PostHelper

#update_devices

Constructor Details

#initialize(user, pass) ⇒ Locator

Returns a new instance of Locator.



12
13
14
15
16
17
# File 'lib/rosumi/locator.rb', line 12

def initialize(user, pass)
  @user = user
  @pass = pass
  @devices = []
  super()
end

Instance Method Details

#locate(device_num = 0, max_wait = 300) ⇒ Object

Find a device by it’s number.

Attributes

  • device_num - Device number as returned from the update_devices method.

  • max_wait - Maximum wait in seconds to wait for call to complete.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rosumi/locator.rb', line 25

def locate(device_num = 0, max_wait = 300)
  
  start = Time.now
  
  begin
    raise "Unable to find location within '#{max_wait}' seconds" if ((Time.now - start) > max_wait)

    sleep(5)
    update_devices
    raise "Invalid device number!" if @devices[device_num].nil?  
    raise "There is no location data for this device (#{@devices[device_num]['name']})" if @devices[device_num]['location'].nil?
  end while (@devices[device_num]['location']['locationFinished'] == 'false') 

  loc = {
    :name      => @devices[device_num]['name'],
    :latitude  => @devices[device_num]['location']['latitude'],
    :longitude => @devices[device_num]['location']['longitude'],
    :accuracy  => @devices[device_num]['location']['horizontalAccuracy'],
    :timestamp => @devices[device_num]['location']['timeStamp'],
    :position_type  => @devices[device_num]['location']['positionType']
    };

  return loc;
end