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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5939f1cb0963428836c54e6a654a670b68b07265
4
- data.tar.gz: d1f8c771cc61061e184dc97bfbb0707bb5118ecb
3
+ metadata.gz: 28e81dce292292d00f32065e6364a559a882c5d2
4
+ data.tar.gz: 8831f1e6c85907d2059c92c96a487c627eb92159
5
5
  SHA512:
6
- metadata.gz: 692b4b4c63f637a979125811e0a13812b2a292c13990615285823fa270f966ed2d337a5bf45c2410e78b6a99cc08e986cc2e33fc08cdf946ba5b94fe2f4d5bd1
7
- data.tar.gz: e6e84626eb776761ef5b2a24d133ea098d2dd7d1ba3a49c4315a92bea933158643d048e2c6ea73145e43548f2840448898ac4b5b62585c79b03c13acd6d54ae1
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
- options = {
27
- timeout: WAIT_BLOCK_TIMEOUT
28
- }.merge(options)
29
- start = Time.now
30
- until (success = boolean_proc.call) || Time.now > start+options[:timeout]
31
- result = yield
32
- sleep WAIT_BLOCK_SLEEP
33
- end
34
- if success
35
- return result
36
- else
37
- raise "Device #{self.type} #{self.name} not updated."
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
@@ -1,3 +1,3 @@
1
1
  module Winker
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
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.11
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-16 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler