sleepiq 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/lib/sleepiq/client.rb +6 -21
- data/lib/sleepiq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa8c91485795d2ccd9ffbc45823cef841e33dc497fbf9a4be19b1cc1b7b6e24
|
4
|
+
data.tar.gz: 2d3e8af55460dd8b89fccf4cda928a51432196082b1841686984d11a0b590b18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d33150cdf0de6ba676a7e572974b6440b6e81db85c3293779cfbd16dd05e6d16b9d108872c0f60499e364238050f090a790fb0d5d25b1bfb42628f51a5edb8a
|
7
|
+
data.tar.gz: 536d0c1b30855031ef354176ba39a63e91e8166262824e9bf473459709cb45c177e133a288e1eeb325a8cecc533a5e013b0de4dd1cf9b88a179d94ab47b31d37
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/lib/sleepiq/client.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
require 'dalli'
|
2
1
|
require 'faraday'
|
3
2
|
require 'faraday_middleware'
|
4
3
|
|
5
4
|
module SleepIQ
|
6
5
|
class Client
|
7
6
|
attr_accessor :key, :sessid, :awsalb, :bedid
|
8
|
-
attr_reader :cache
|
9
7
|
|
10
8
|
include SleepIQ::Family
|
11
9
|
include SleepIQ::Bed
|
@@ -13,21 +11,13 @@ module SleepIQ
|
|
13
11
|
include SleepIQ::Pump
|
14
12
|
include SleepIQ::Sleeper
|
15
13
|
|
16
|
-
def initialize(**opts)
|
17
|
-
@cache = Dalli::Client.new('localhost:11211', namespace: 'sleep_iq')
|
14
|
+
def initialize(**opts)
|
18
15
|
@username = opts[:username].nil? ? ENV['sleepiq_username'] : opts[:username]
|
19
16
|
@password = opts[:password].nil? ? ENV['sleepiq_password'] : opts[:password]
|
20
|
-
@login_cache_time = opts[:logic_cache_time].nil? ? 60 : opts[:login_cache_time]
|
21
|
-
|
22
|
-
login if @cache.get('api_key').nil? || @cache.get('session_id') || @cache.get('awsalb')
|
23
|
-
|
24
|
-
@sessid = @cache.get('session_id')
|
25
|
-
@key = @cache.get('api_key')
|
26
|
-
@awsalb = @cache.get('awsalb')
|
27
17
|
|
18
|
+
login
|
28
19
|
@conn = Faraday.new(
|
29
20
|
url: 'https://api.sleepiq.sleepnumber.com',
|
30
|
-
ssl: { verify: false, ca_file: '/Users/miverso2/Downloads/optum_ca1_full_chain.pem' },
|
31
21
|
headers: default_headers,
|
32
22
|
params: { _k: @key },
|
33
23
|
request: { timeout: 10, open_timeout: 3, write_timeout: 10 }
|
@@ -36,7 +26,7 @@ module SleepIQ
|
|
36
26
|
conn.adapter :net_http
|
37
27
|
end
|
38
28
|
|
39
|
-
@bedid =
|
29
|
+
@bedid = family_status['beds'][0]['bedId']
|
40
30
|
end
|
41
31
|
|
42
32
|
def login(username = @username, password = @password) # rubocop:disable Metrics/AbcSize
|
@@ -60,10 +50,10 @@ module SleepIQ
|
|
60
50
|
raise "status code was #{result.status}" unless result.status == 200
|
61
51
|
|
62
52
|
result.headers['set-cookie'].split(' ').each do |k, _v|
|
63
|
-
@
|
64
|
-
@
|
53
|
+
@sessid = k.split('=')[1].delete_suffix(';')
|
54
|
+
@awsalb = k.split('=')[1].delete_suffix(';')
|
65
55
|
end
|
66
|
-
@
|
56
|
+
@key = result.body['key']
|
67
57
|
end
|
68
58
|
|
69
59
|
def default_headers
|
@@ -75,10 +65,5 @@ module SleepIQ
|
|
75
65
|
'Connection': 'keep-alive',
|
76
66
|
'Cookie': "AWSALB=#{@awsalb}; JSESSIONID=#{@sessid}" }
|
77
67
|
end
|
78
|
-
|
79
|
-
def default_bed
|
80
|
-
@cache.set('bedid', family_status['beds'][0]['bedId'], @login_cache_time) if @cache.get('bedid').nil?
|
81
|
-
@cache.get('bedid')
|
82
|
-
end
|
83
68
|
end
|
84
69
|
end
|
data/lib/sleepiq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sleepiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- esity
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|