lib/arlo/devices.rb in arlo-0.0.7 vs lib/arlo/devices.rb in arlo-0.0.8
- old
+ new
@@ -30,30 +30,38 @@
payload, 'xcloudId': device['xCloudId'])
JSON.parse(ret_val.body)
end
- def take_snapshot(camera)
- camera_id = camera['deviceId']
+ def set_siren_on(device, duration)
+ device_id = device['deviceId']
payload = {
- 'to': camera_id,
- 'from': 'ArloGem',
- 'resource': "cameras/#{camera_id}",
+ 'from': 'arlogem',
+ 'to': device_id,
'action': 'set',
- 'publishResponse': true,
'transId': SecureRandom.uuid,
+ 'publishResponse': true,
+ 'resource': 'siren',
'properties': {
- 'activityState': 'startUserStream',
- 'cameraId': camera_id
+ 'duration': duration,
+ 'pattern': 'alarm',
+ 'sirenState': 'on',
+ 'volume': 8
}
}
- ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/startStream',
- payload, 'xcloudId': camera['xCloudId'])
+ ret_val = post("https://arlo.netgear.com/hmsweb/users/devices/notify/#{device_id}",
+ payload, 'xcloudId': device['xCloudId'])
- ret_val = JSON.parse(ret_val.body)
+ JSON.parse(ret_val.body)
+ end
+
+ def take_snapshot(camera)
+ camera_id = camera['deviceId']
+
+ ret_val = start_stream(camera, camera_id)
return ret_val unless ret_val['success']
payload = {
'cameraId': camera_id,
'parentId': camera_id,
@@ -64,77 +72,79 @@
ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/takeSnapshot',
payload, 'xcloudId': camera['xCloudId'])
snapshot_ret_val = JSON.parse(ret_val.body)
+ stop_stream(camera)
+ snapshot_ret_val
+ end
+
+ def record_video(camera, duration)
+ camera_id = camera['deviceId']
+ parent_id = camera['parentId']
+
+ ret_val = start_stream(camera, parent_id)
+ return ret_val unless ret_val['success']
+
+ # ret_val['data']['url']
payload = {
- 'to': camera_id,
- 'from': 'ArloGem',
- 'resource': "cameras/#{camera_id}",
- 'action': 'set',
- 'publishResponse': true,
- 'transId': SecureRandom.uuid,
- 'properties': {
- 'activityState': 'stopUserStream',
- 'cameraId': camera_id
- }
+ 'xcloudId': camera['xCloudId'],
+ 'parentId': parent_id,
+ 'deviceId': camera_id,
+ 'olsonTimeZone': camera['properties']['olsonTimeZone']
}
- ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/stopStream',
+ ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/startRecord',
payload, 'xcloudId': camera['xCloudId'])
+ sleep(duration)
+
+ stop_stream(camera)
+
JSON.parse(ret_val.body)
- snapshot_ret_val
end
- def record_video(camera, duration)
+ private
+
+ def stop_stream(camera)
camera_id = camera['deviceId']
- parent_id = camera['parentId']
payload = {
- 'to': parent_id,
+ 'to': camera_id,
'from': 'ArloGem',
'resource': "cameras/#{camera_id}",
'action': 'set',
- 'responseUrl': '',
'publishResponse': true,
'transId': SecureRandom.uuid,
'properties': {
- 'activityState': 'startUserStream',
+ 'activityState': 'stopUserStream',
'cameraId': camera_id
}
}
- ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/startStream',
+ ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/stopStream',
payload, 'xcloudId': camera['xCloudId'])
- ret_val = JSON.parse(ret_val.body)
- payload = {
- 'xcloudId': camera['xCloudId'],
- 'parentId': camera['parentId'],
- 'deviceId': camera_id,
- 'olsonTimeZone': camera['properties']['olsonTimeZone']
-
- }
-
- ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/startRecord',
- payload, 'xcloudId': camera['xCloudId'])
-
JSON.parse(ret_val.body)
+ end
- sleep(duration)
-
+ def start_stream(camera, dest)
+ camera_id = camera['deviceId']
payload = {
- 'xcloudId': camera['xCloudId'],
- 'parentId': camera['parentId'],
- 'deviceId': camera_id,
- 'olsonTimeZone': camera['properties']['olsonTimeZone']
-
+ 'to': dest,
+ 'from': 'ArloGem',
+ 'resource': "cameras/#{camera_id}",
+ 'action': 'set',
+ 'publishResponse': true,
+ 'transId': SecureRandom.uuid,
+ 'properties': {
+ 'activityState': 'startUserStream',
+ 'cameraId': camera_id
+ }
}
- ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/stopRecord',
- payload, 'xcloudId': camera['xCloudId'])
-
+ ret_val = post('https://arlo.netgear.com/hmsweb/users/devices/startStream',
+ payload, 'xcloudId': camera['xCloudId'])
JSON.parse(ret_val.body)
end
end
end