lib/arlo/devices.rb in arlo-0.0.3 vs lib/arlo/devices.rb in arlo-0.0.4

- old
+ new

@@ -1,13 +1,35 @@ +require 'securerandom' + module Arlo class API - def get_devices token - profile = get('https://arlo.netgear.com/hmsweb/users/devices', token) - JSON.parse(profile.body) + def get_devices + devices = get 'https://arlo.netgear.com/hmsweb/users/devices' + @devices = JSON.parse(devices.body) end - def get_device_info device_name, device_list + def get_device_info(device_name) raise 'Missing device_name' unless device_name - device_list['data'].select {|device| device['deviceName'] == device_name }[0] + @devices['data'].select {|device| device['deviceName'] == device_name }[0] + end + + def arm_device(base_station, armed) + station_id = base_station['deviceId'] + payload = { + 'from': 'arlogem', + 'to': station_id, + 'action': 'set', + 'resource': 'modes', + 'transId': SecureRandom.uuid, + 'publishResponse': true, + 'properties': { + 'active': armed ? 'mode1' : 'mode0' + } + } + + ret_val = post("https://arlo.netgear.com/hmsweb/users/devices/notify/#{station_id}", + payload, + 'xcloudId': base_station['xCloudId']) + JSON.parse(ret_val.body) end end end