adafruit-io 2.0.0.beta.5 → 2.0.0.beta.6

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: 4ed2fec0eb82155a7ad3f23f7ec4551688a58ea6
4
- data.tar.gz: 6b4bd9d8f0aa88935e1027567699c2b073585c61
3
+ metadata.gz: 1eaa78ed8fc5921d2af4d16d7fa1defb321eecb2
4
+ data.tar.gz: 7ee9adca6975f86882faea7f6c40bcba3c91b74f
5
5
  SHA512:
6
- metadata.gz: ec2ca90fccb200ca93be9de61fab6bf2b4f4cec7677d6ec84296c10f85c711627c30fca427bfcfc656da00d3e80aff8837698cc7b4c2f59e18b9184ce67efec3
7
- data.tar.gz: 292aa24ca1b0313b54a1228c8bdaf8ab639cfa2860559c9f4c974f67e3ea79ed4b7b5b99f3b7d44e58f5061b2dc350f5343f069d47defb98687082c6fc8cad06
6
+ metadata.gz: c58dedbafaae234314a9e0dcddcb67fad758479fed2ad141a2956d247ff83ef037bc5f25805adbbd6110026611521c08fa326236183b9ea45d4eacd6f22a3a6f
7
+ data.tar.gz: 0fe5158a4d1a5523b4e4638ad29f3c194918171f1ae814285221f2328a4f9a1270678c86b181d19797e6e300666d5d2bfc663a2a8670f9bab0352fe5f520a725
data/README.md CHANGED
@@ -31,7 +31,7 @@ It is our goal to eventually support all API V2 methods, but that will happen in
31
31
  - [x] Dashboards `2.0.0.beta.4`
32
32
  - [x] Activities `2.0.0.beta.5`
33
33
  - [x] Permissions `2.0.0.beta.5`
34
- - [] Triggers
34
+ - [x] Triggers `2.0.0.beta.6`
35
35
 
36
36
  ## Installation
37
37
 
@@ -52,24 +52,22 @@ Or install it yourself as:
52
52
  Each time you use the library, you'll want to pass your [AIO Key][4] to the client.
53
53
 
54
54
  ```ruby
55
-
56
55
  require 'adafruit/io'
57
56
 
58
57
  # create an instance
59
58
  aio = Adafruit::IO::Client.new key: 'KEY'
60
59
  ```
61
60
 
62
- Since every API request requires a username, you can also pass a username to the client initializer.
61
+ Since every API request requires a username, you can also pass a username to the client initializer to use it for every request.
63
62
 
64
63
  ```ruby
65
-
66
64
  require 'adafruit/io'
67
65
 
68
66
  # create an instance
69
67
  aio = Adafruit::IO::Client.new key: 'KEY', username: 'USERNAME'
70
68
  ```
71
69
 
72
- All return values are plain Ruby hashes based on the JSON response returned by the API. Most basic requests should get back a Hash with a `key` field. The key can be used in subsequent requests. API requests that return a list of objects will return a simple array of hashes.
70
+ All return values are plain Ruby hashes based on the JSON response returned by the API. Most basic requests should get back a Hash with a `key` field. The key can be used in subsequent requests. API requests that return a list of objects will return a simple array of hashes. Feeds, Groups, and Dashboards all rely on the `key` value, other endpoints (Blocks, Permissions, Tokens, Triggers) use `id`.
73
71
 
74
72
  Here's an example of creating, adding data to, and deleting a feed.
75
73
 
@@ -16,7 +16,7 @@ require 'adafruit/io/client/feeds'
16
16
  require 'adafruit/io/client/groups'
17
17
  require 'adafruit/io/client/permissions'
18
18
  require 'adafruit/io/client/tokens'
19
-
19
+ require 'adafruit/io/client/triggers'
20
20
  require 'adafruit/io/client/user'
21
21
 
22
22
  module Adafruit
@@ -55,7 +55,7 @@ module Adafruit
55
55
  include Adafruit::IO::Client::Groups
56
56
  include Adafruit::IO::Client::Permissions
57
57
  include Adafruit::IO::Client::Tokens
58
-
58
+ include Adafruit::IO::Client::Triggers
59
59
  include Adafruit::IO::Client::User
60
60
 
61
61
  private
@@ -30,7 +30,7 @@ module Adafruit
30
30
 
31
31
  def create_feed(*args)
32
32
  username, arguments = extract_username(args)
33
- feed_attrs = arguments.shift
33
+ feed_attrs = valid_feed_attrs(arguments)
34
34
 
35
35
  post api_url(username, 'feeds'), feed_attrs
36
36
  end
@@ -45,13 +45,19 @@ module Adafruit
45
45
  def update_feed(*args)
46
46
  username, arguments = extract_username(args)
47
47
  feed_key = get_key_from_arguments(arguments)
48
+ feed_attrs = valid_feed_attrs(arguments)
49
+
50
+ put api_url(username, 'feeds', feed_key), feed_attrs
51
+ end
52
+
53
+ private
54
+
55
+ def valid_feed_attrs(arguments)
48
56
  query = get_query_from_arguments(
49
57
  arguments,
50
58
  %w(name key description unit_type unit_symbol history visibility
51
59
  license status_notify status_timeout)
52
60
  )
53
-
54
- put api_url(username, 'feeds', feed_key), query
55
61
  end
56
62
 
57
63
  end
@@ -0,0 +1,58 @@
1
+ module Adafruit
2
+ module IO
3
+ class Client
4
+ module Triggers
5
+
6
+ # Get all triggers.
7
+ def triggers(*args)
8
+ username, _ = extract_username(args)
9
+
10
+ get api_url(username, 'triggers')
11
+ end
12
+
13
+ # Get a trigger specified by key
14
+ def trigger(*args)
15
+ username, arguments = extract_username(args)
16
+ trigger_id = get_id_from_arguments(arguments)
17
+
18
+ get api_url(username, 'triggers', trigger_id)
19
+ end
20
+
21
+ # Create a trigger. No attributes need to be passed in.
22
+ def create_trigger(*args)
23
+ username, arguments = extract_username(args)
24
+ attrs = valid_trigger_attrs(arguments)
25
+
26
+ post api_url(username, 'triggers'), attrs
27
+ end
28
+
29
+ def delete_trigger(*args)
30
+ username, arguments = extract_username(args)
31
+ trigger_id = get_id_from_arguments(arguments)
32
+
33
+ delete api_url(username, 'triggers', trigger_id)
34
+ end
35
+
36
+ def update_trigger(*args)
37
+ username, arguments = extract_username(args)
38
+ trigger_id = get_id_from_arguments(arguments)
39
+ attrs = valid_trigger_attrs(arguments)
40
+
41
+ put api_url(username, 'triggers', feed_key), query
42
+ end
43
+
44
+ private
45
+
46
+ def valid_trigger_attrs(arguments)
47
+ get_query_from_arguments(
48
+ arguments,
49
+ %w(feed_id operator value action to_feed_id action_feed_id
50
+ action_value enabled trigger_type)
51
+ )
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -1,5 +1,5 @@
1
1
  module Adafruit
2
2
  module IO
3
- VERSION = "2.0.0.beta.5"
3
+ VERSION = "2.0.0.beta.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adafruit-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta.5
4
+ version: 2.0.0.beta.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Cooper
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-06 00:00:00.000000000 Z
12
+ date: 2017-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -117,6 +117,7 @@ files:
117
117
  - lib/adafruit/io/client/groups.rb
118
118
  - lib/adafruit/io/client/permissions.rb
119
119
  - lib/adafruit/io/client/tokens.rb
120
+ - lib/adafruit/io/client/triggers.rb
120
121
  - lib/adafruit/io/client/user.rb
121
122
  - lib/adafruit/io/configurable.rb
122
123
  - lib/adafruit/io/mqtt.rb