arlo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44cee407e50a4c30b276fb1cecb57a98cdd75901
4
- data.tar.gz: d38d7b7ae6aeac5a63046b9cdcc11befe46912d7
3
+ metadata.gz: 2ef361a03fce87641da660189ebb83dd3b7fbfc4
4
+ data.tar.gz: d89c72f4e22601bf702807624fb515116b8c5f68
5
5
  SHA512:
6
- metadata.gz: c0f8c8fdf8139f0f3158431f36d3eac1cd178b77e8504be5d3fcb25d71c689639a87b7dae69574c4691a9f375d5cc0107078c677ebd3a58de97ad5a37d017378
7
- data.tar.gz: 02d385f3f1e1ec5ee9f97aff371353b2d9c627b2f34a7755d3bf83652fcc0772e75232f67bfbbabd93f121d798465f2032f07a1fc7285a9e2001223cc123f9f1
6
+ metadata.gz: 5aa0bccc7721415c7a78e6b745b45a81acf4ed67828dbe12de1099ca3362fd47e839e2d97c4f25b0f7140f6ff634495052fa394855321359c878a86d9b289657
7
+ data.tar.gz: 96c787a6bd3f6716e8f43c1a64fc44adc5cb80d11ffe308e006a34c9e65123b1f891b7da39b8c19f43a89c549f2fc3c08712db39f9b063801b98abae5ad6d07b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arlo (0.0.3)
4
+ arlo (0.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/arlo.svg)](https://badge.fury.io/rb/arlo) [![Build Status](https://travis-ci.org/ihassin/arlo.svg?branch=master)](https://travis-ci.org/ihassin/arlo)
4
4
 
5
- Get information about your Arlo account as well as your devices.
5
+ Get and set information about your Arlo account as well as your devices.
6
6
 
7
7
  # Installation
8
8
 
@@ -35,37 +35,77 @@ Set up the environment variables reflecting your Arlo credentials:
35
35
  export ARLO_EMAIL=xxx
36
36
  export ARLO_PASSWORD=yyy
37
37
 
38
- ## get_token
39
-
40
- Call this to gain access to the other APIs.
41
-
42
38
  ## get_profile
43
39
 
44
40
  Call this to get your profile information.
45
41
 
42
+ ```
43
+ api = Arlo::API.new
44
+ profile = api.get_profile
45
+ firstName = api.profile['data']['firstName']
46
+ ```
47
+
48
+ Note: This method is implicitly called when instantiating the API object, so you can directly see the profile by:
49
+ ```
50
+ api = Arlo::API.new
51
+ firstName = api.profile['data']['firstName']
52
+ ```
53
+
46
54
  ## get_devices
47
55
 
48
56
  Call this to get the list of devices (including basestations) registered with the account.
49
57
 
58
+ ```
59
+ api = Arlo::API.new
60
+ devices = api.get_devices
61
+ first_device = api.devices['data'][0]
62
+ ```
63
+
64
+ Note: This method is implicitly called when instantiating the API object, so you can directly see the devices by:
65
+ ```
66
+ api = Arlo::API.new
67
+ first_device = api.devices['data'][0]
68
+ ```
69
+
50
70
  ## get_device_info
51
71
 
52
72
  Call this to get device information.
53
73
 
74
+ ```
75
+ api = Arlo::API.new
76
+ camera1 = api.get_device_info 'Camera1"
77
+ ```
78
+
79
+ ## arm_device
80
+
81
+ Call this to arm or disarm a device
82
+
83
+ ```
84
+ api = Arlo::API.new
85
+ camera1 = api.arm_device 'Camera1", true|false
86
+ ```
87
+
54
88
  ## get_library
55
89
 
56
90
  Call this to get the library's index of all the recordings it has between the two supplied dates.
57
91
 
92
+ ```
93
+ api = Arlo::API.new
94
+ library = api.get_library '20180802', '20180803'
95
+ ```
96
+
58
97
  # TODO
59
98
 
60
- * Provide a convenient interface to manage devices
61
- * Control cameras (start/stop recordings)
99
+ * Control cameras (start/stop recordings, take snapshots)
62
100
  * Download videos
63
101
 
64
102
  # Development
65
103
 
66
104
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
105
 
68
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+ To install this gem onto your local machine, run `bundle exec rake install`.
107
+
108
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
109
 
70
110
  # Contributing
71
111
 
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 2018-08-05
4
+
5
+ ### Breaking
6
+
7
+ * No need to pass the token to methods anymore
8
+ * No need to pass the device-list to methods
9
+
10
+ ### Non-breaking
11
+
12
+ * API object is logged-in when created
13
+ * Devices and Profile are loaded when API object is created
14
+ * Added arm/disarm API method
@@ -2,7 +2,7 @@ require_relative 'arlo/network_helper'
2
2
 
3
3
  module Arlo
4
4
  require 'arlo/version'
5
- require 'arlo/token'
5
+ require 'arlo/init'
6
6
  require 'arlo/profile'
7
7
  require 'arlo/devices'
8
8
  require 'arlo/library'
@@ -1,13 +1,35 @@
1
+ require 'securerandom'
2
+
1
3
  module Arlo
2
4
  class API
3
- def get_devices token
4
- profile = get('https://arlo.netgear.com/hmsweb/users/devices', token)
5
- JSON.parse(profile.body)
5
+ def get_devices
6
+ devices = get 'https://arlo.netgear.com/hmsweb/users/devices'
7
+ @devices = JSON.parse(devices.body)
6
8
  end
7
9
 
8
- def get_device_info device_name, device_list
10
+ def get_device_info(device_name)
9
11
  raise 'Missing device_name' unless device_name
10
- device_list['data'].select {|device| device['deviceName'] == device_name }[0]
12
+ @devices['data'].select {|device| device['deviceName'] == device_name }[0]
13
+ end
14
+
15
+ def arm_device(base_station, armed)
16
+ station_id = base_station['deviceId']
17
+ payload = {
18
+ 'from': 'arlogem',
19
+ 'to': station_id,
20
+ 'action': 'set',
21
+ 'resource': 'modes',
22
+ 'transId': SecureRandom.uuid,
23
+ 'publishResponse': true,
24
+ 'properties': {
25
+ 'active': armed ? 'mode1' : 'mode0'
26
+ }
27
+ }
28
+
29
+ ret_val = post("https://arlo.netgear.com/hmsweb/users/devices/notify/#{station_id}",
30
+ payload,
31
+ 'xcloudId': base_station['xCloudId'])
32
+ JSON.parse(ret_val.body)
11
33
  end
12
34
  end
13
35
  end
@@ -2,22 +2,35 @@ module Arlo
2
2
  class API
3
3
 
4
4
  def initialize
5
- @@token = nil
5
+ @token = login
6
+ @devices = get_devices
7
+ @profile = get_profile
6
8
  end
7
9
 
8
- def get_token
9
- return @@token if @@token
10
+ def token
11
+ @token
12
+ end
13
+
14
+ def devices
15
+ @devices
16
+ end
17
+
18
+ def profile
19
+ @profile
20
+ end
21
+
22
+ def login
10
23
  email = ENV['ARLO_EMAIL']
11
24
  raise 'Missing ARLO_EMAIL environment variable' unless email
12
25
  password = ENV['ARLO_PASSWORD']
13
26
  raise 'Missing ARLO_PASSWORD environment variable' unless password
14
27
 
15
28
  payload = {
16
- "email": email,
17
- "password": password
29
+ 'email': email,
30
+ 'password': password
18
31
  }
19
32
  response = post('https://arlo.netgear.com/hmsweb/login/v2', payload)
20
- @@token = JSON.parse(response.body)['data']['token']
33
+ JSON.parse(response.body)['data']['token']
21
34
  end
22
35
 
23
36
  end
@@ -1,11 +1,11 @@
1
1
  module Arlo
2
2
  class API
3
- def get_library(token, from_date, to_date)
3
+ def get_library(from_date, to_date)
4
4
  payload = {
5
- "dateFrom": "20180802",
6
- "dateTo": "20180803"
5
+ 'dateFrom': from_date,
6
+ 'dateTo': to_date
7
7
  }
8
- library = post('https://arlo.netgear.com/hmsweb/users/library', payload, token)
8
+ library = post('https://arlo.netgear.com/hmsweb/users/library', payload)
9
9
  JSON.parse(library.body)
10
10
  end
11
11
  end
@@ -5,26 +5,35 @@ require 'openssl'
5
5
 
6
6
  module Arlo
7
7
  class API
8
- def get url, token
8
+ def get url
9
9
  uri = URI.parse(url)
10
10
  http = Net::HTTP.new(uri.host, uri.port)
11
11
  http.use_ssl = true
12
12
 
13
13
  request = Net::HTTP::Get.new(uri)
14
14
  request.add_field('Content-Type', 'application/json;charset=UTF-8')
15
- request.add_field('Authorization', token)
15
+ request.add_field('Authorization', @token)
16
16
 
17
17
  http.request(request)
18
18
  end
19
19
 
20
- def post url, payload, token = nil
20
+ def post url, payload, xheaders = nil
21
21
  uri = URI.parse(url)
22
22
  http = Net::HTTP.new(uri.host, uri.port)
23
23
  http.use_ssl = true
24
24
 
25
25
  request = Net::HTTP::Post.new(uri)
26
- request.add_field('Content-Type', 'application/json;charset=UTF-8')
27
- request.add_field('Authorization', token) if token
26
+
27
+ headers = {
28
+ 'Content-Type': 'application/json;charset=UTF-8',
29
+ 'Authorization': @token
30
+ }
31
+
32
+ headers.merge!(xheaders) if xheaders
33
+
34
+ headers.each do |key, value|
35
+ request.add_field(key, value)
36
+ end
28
37
  request.body = payload.to_json
29
38
 
30
39
  http.request(request)
@@ -1,8 +1,8 @@
1
1
  module Arlo
2
2
  class API
3
- def get_profile token
4
- profile = get('https://arlo.netgear.com/hmsweb/users/profile', token)
5
- JSON.parse(profile.body)
3
+ def get_profile
4
+ profile = get 'https://arlo.netgear.com/hmsweb/users/profile'
5
+ @profile = JSON.parse(profile.body)
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Arlo
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arlo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Itamar Hassin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-04 00:00:00.000000000 Z
11
+ date: 2018-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,13 +106,14 @@ files:
106
106
  - arlo.gemspec
107
107
  - bin/console
108
108
  - bin/setup
109
+ - changelog.md
109
110
  - exe/arlo
110
111
  - lib/arlo.rb
111
112
  - lib/arlo/devices.rb
113
+ - lib/arlo/init.rb
112
114
  - lib/arlo/library.rb
113
115
  - lib/arlo/network_helper.rb
114
116
  - lib/arlo/profile.rb
115
- - lib/arlo/token.rb
116
117
  - lib/arlo/version.rb
117
118
  homepage: https://github.com/ihassin/arlo
118
119
  licenses: