You can now access MoosTrax with Ruby.
Install the gem
1 2 | $ wget http://www.moostrax.com/static/MoosTrax-0.1.gem $ sudo gem install MoosTrax-0.1.gem |
Try out this demo script
make sure to fill your API_KEY in.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | require 'rubygems' require 'moostrax' require 'time' def get_local_date(date_str) Time.parse(date_str + ' UTC').getlocal.asctime end mt = MoosTrax.new('API_KEY') begin devices = mt.devices devices.each do |device| info = mt.device_info(device) puts "Device ID: #{info['device_id']}\n" puts "Device Name: #{info['device_name']}\n" puts "Last Contact: #{get_local_date(info['last_contact'])}\n" puts "Date Added: #{get_local_date(info['date_added'])}\n" location = mt.location(device) puts "Most Recent Location: #{location['latitude']}, #{location['longitude']} #{get_local_date(location['date'])}\r\n" history = mt.history(device, Time.now-86400, Time.now) puts "Number of location updates in past 24 hours: #{history.length}\r\n" puts "First Location in History: #{history[0]['latitude']}, #{history[0]['longitude']}\r\n" if history.length >=1 puts '------------------------------------------------------' end rescue MoosTrax::APIError => e puts "Unable to access MoosTrax: #{e.message}" end |
For more information, check out the Developer API Wiki.
