winker 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/winker/devices/device_methods.rb +14 -12
- data/lib/winker/version.rb +1 -1
- data/lib/winker.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e81dce292292d00f32065e6364a559a882c5d2
|
4
|
+
data.tar.gz: 8831f1e6c85907d2059c92c96a487c627eb92159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e29dd7f3f720afd02da14958d5f338dfdd9740dbc66934b7506de3529d917aace53821ac90df021fb602fb95b75629a1b47b07d0778bfd83e8ebdb24fbc993d7
|
7
|
+
data.tar.gz: cc70bb390ca55386fa1a4e85c0a1eab83d801167eb44ba1d2ab2f0e9a089fe31e6617a406af93893ea67d2903ffb876eb15182f47c010d1cb75003604e99c4cf
|
data/README.md
CHANGED
@@ -36,6 +36,7 @@ Or install it yourself as:
|
|
36
36
|
wink.username = "email@domain.com"
|
37
37
|
wink.password = "**********"
|
38
38
|
wink.endpoint = "https://winkapi.quirky.com"
|
39
|
+
wink.wait_for_updates = true #this is the default setting is optional
|
39
40
|
end
|
40
41
|
|
41
42
|
#retrieve the access_token and refresh_token
|
@@ -54,12 +55,25 @@ Or install it yourself as:
|
|
54
55
|
#Device Methods/Attributes
|
55
56
|
Some status methods are blocking in the sense that if a status change is sent, such as powering the device on or off, the next time you call powered? it will refresh every 2 seconds until last updated at time is greater than when the status change was called. If 20 seconds pass before an update then the it throws and error that it hasn't received an update. During my testing an update normally took about 4 seconds. But at times would take much longer.
|
56
57
|
|
58
|
+
To temporarily disable or enable blocking use the Winker.wait_for_update block method
|
59
|
+
|
57
60
|
examples
|
58
61
|
|
59
62
|
devices = Winker.devices #returns an array of device objects
|
60
63
|
devices[1].type
|
61
64
|
=> "light_bulb"
|
62
65
|
|
66
|
+
Winker.wait_for_update(false) do
|
67
|
+
devices[1].off
|
68
|
+
end
|
69
|
+
devices[1].powered? #it takes time for update to reach bulb and signal completion
|
70
|
+
=> true
|
71
|
+
Winker.wait_for_update(true) do
|
72
|
+
devices[1].off
|
73
|
+
end
|
74
|
+
devices[1].powered? #blocks until status updated_at is greater than the time we called the off method
|
75
|
+
=> false
|
76
|
+
|
63
77
|
Each device has it's own associated type. To make things easier when devices are loaded methods are included to help interact with the device so update(options) doesn't have to be called for every interaction.
|
64
78
|
|
65
79
|
##Generic
|
@@ -23,18 +23,20 @@ module Winker
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def wait_for_update(boolean_proc, options = {}, &block)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
26
|
+
if Winker.wait_for_updates
|
27
|
+
options = {
|
28
|
+
timeout: WAIT_BLOCK_TIMEOUT
|
29
|
+
}.merge(options)
|
30
|
+
start = Time.now
|
31
|
+
until (success = boolean_proc.call) || Time.now > start+options[:timeout]
|
32
|
+
result = yield
|
33
|
+
sleep WAIT_BLOCK_SLEEP
|
34
|
+
end
|
35
|
+
if success
|
36
|
+
return result
|
37
|
+
else
|
38
|
+
raise "Device #{self.type} #{self.name} not updated and timed out after #{options[:timeout]}."
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
data/lib/winker/version.rb
CHANGED
data/lib/winker.rb
CHANGED
@@ -36,13 +36,26 @@ module Winker
|
|
36
36
|
end
|
37
37
|
|
38
38
|
module Configuration
|
39
|
-
attr_accessor :client_id, :client_secret, :access_token, :refresh_token, :username, :password, :endpoint, :server_time_dif
|
39
|
+
attr_accessor :client_id, :client_secret, :access_token, :refresh_token, :username, :password, :endpoint, :server_time_dif, :wait_for_updates
|
40
40
|
|
41
41
|
def configure
|
42
|
+
self.wait_for_updates = true
|
42
43
|
yield self
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
47
|
+
def self.wait_for_update(should_i_wait = true)
|
48
|
+
_default_setting = self.wait_for_updates
|
49
|
+
self.wait_for_updates = should_i_wait
|
50
|
+
begin
|
51
|
+
yield
|
52
|
+
rescue Exception => e
|
53
|
+
self.wait_for_updates = _default_setting
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
46
59
|
extend Parser
|
47
60
|
extend Configuration
|
48
61
|
extend Connection
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Mahan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|