adafruit-io 2.0.0.beta.3 → 2.0.0.beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82354463cf584413ee421f62dc087fa182b191a3
4
- data.tar.gz: 7569063a8a78d7c97189a66bf89894f8c0f089dd
3
+ metadata.gz: 967481a3470b1c2b5c71f10d52aa0d0a11c3502c
4
+ data.tar.gz: 7d3fa8e6f776d95523763e4c7f0497bc071097df
5
5
  SHA512:
6
- metadata.gz: d3dd1a6feec6e1804a08c0b5a805fb2053d35a4854acd354e018dc5f2815cb57454c7fb433eaf01be3ce1578f4e65a60b5b531aec8bcc69b6811d327c466fc23
7
- data.tar.gz: 69e5cdb283b4d8d615fc3c575d0df498f82ecd04c1933b90f3d507a1cdd4c6983fcef7506040d226f60d788f3c2f10195351ce77ab31a877c678a838ab6e0db3
6
+ metadata.gz: 1fc64bb0cb2d05d80cab90bb7af67462c116ae333ae7ecbdce5f5e34e777c0c53fbdbc0be3cd2305d09772fedd8f2516e149aabe2e5e961bb52f165a14b61962
7
+ data.tar.gz: 547aef766d609a9d3f65b89d51577964f9692e42d471f98128e86967b0e02d91e9e7fe3314194cf7361bb26818d4157cfd6eb1f19257850589e931bc200961ea
data/README.md CHANGED
@@ -26,12 +26,12 @@ It is our goal to eventually support all API V2 methods, but that will happen in
26
26
  - [x] Data `2.0.0.beta.1`
27
27
  - [x] Groups `2.0.0.beta.1`
28
28
  - [x] MQTT `2.0.0.beta.3`
29
+ - [x] Tokens `2.0.0.beta.4`
30
+ - [x] Blocks `2.0.0.beta.4`
31
+ - [x] Dashboards `2.0.0.beta.4`
29
32
  - [] Activities
30
- - [] Blocks
31
- - [] Dashboards
32
33
  - [] Permissions
33
34
  - [] Sessions
34
- - [] Tokens
35
35
  - [] Triggers
36
36
 
37
37
  ## Installation
@@ -110,40 +110,11 @@ puts "read?"
110
110
  puts api.feed(garbage['key']).inspect
111
111
  ```
112
112
 
113
- ## Table of Contents
114
-
115
- * [Feeds](#feeds)
116
- * [Data](#data)
117
- * [Groups](#groups)
118
- * [Dashboards](#dashboards)
119
- * [Blocks](#blocks)
120
- * [Activities](#activities)
121
- * [Triggers](#triggers)
122
- * [Permissions](#permissions)
123
- * [Tokens](#tokens)
124
-
125
- ### Feeds
126
-
127
- Create
128
-
129
-
130
-
131
-
132
-
133
- ### Data
134
- ### Groups
135
- ### Dashboards
136
- ### Blocks
137
- ### Activities
138
- ### Triggers
139
- ### Permissions
140
- ### Tokens
141
-
142
- ## Pagination
113
+ ## License
143
114
 
115
+ Copyright (c) 2017 Adafruit Industries. Licensed under the MIT license.
144
116
 
145
- ## License
146
- Copyright (c) 2014 Adafruit Industries. Licensed under the MIT license.
117
+ [Adafruit](https://adafruit.com) invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from [Adafruit](https://adafruit.com).
147
118
 
148
119
  ## Contributing
149
120
 
@@ -1,6 +1,7 @@
1
1
  module Adafruit
2
2
  module IO
3
3
  module Arguments
4
+ class ArgumentError < StandardError; end
4
5
 
5
6
  # Allows us to give a username during client initialization or with a specific method.
6
7
  def extract_username(args)
@@ -45,7 +46,7 @@ module Adafruit
45
46
  record_or_id = arguments.shift
46
47
  return nil if record_or_id.nil?
47
48
 
48
- if record_or_id.is_a?(String)
49
+ if record_or_id.is_a?(String) || record_or_id.is_a?(Fixnum)
49
50
  record_or_id
50
51
  elsif record_or_id.is_a?(Hash) && (record_or_id.has_key?('id') || record_or_id.has_key?(:id))
51
52
  record_or_id['id'] || record_or_id[:id]
@@ -68,6 +69,19 @@ module Adafruit
68
69
  query
69
70
  end
70
71
 
72
+ def require_argument(arguments, argument_name)
73
+ arg = arguments.first
74
+ if !arg.is_a?(Hash)
75
+ raise ArgumentError.new("This request requires arguments to be a Hash containing the key: :#{argument_name}")
76
+ end
77
+
78
+ if !(arg.has_key?(argument_name) || arg.has_key?(argument_name.to_s))
79
+ raise ArgumentError.new("Missing required parameter, make sure to include #{argument_name}")
80
+ end
81
+
82
+ arg[argument_name] || arg[argument_name.to_s]
83
+ end
84
+
71
85
  end
72
86
  end
73
87
  end
@@ -11,6 +11,10 @@ require 'adafruit/io/request_handler'
11
11
  require 'adafruit/io/client/feeds'
12
12
  require 'adafruit/io/client/data'
13
13
  require 'adafruit/io/client/groups'
14
+ require 'adafruit/io/client/tokens'
15
+ require 'adafruit/io/client/dashboards'
16
+ require 'adafruit/io/client/blocks'
17
+ require 'adafruit/io/client/user'
14
18
 
15
19
  module Adafruit
16
20
  module IO
@@ -43,6 +47,11 @@ module Adafruit
43
47
  include Adafruit::IO::Client::Feeds
44
48
  include Adafruit::IO::Client::Data
45
49
  include Adafruit::IO::Client::Groups
50
+ include Adafruit::IO::Client::Tokens
51
+ include Adafruit::IO::Client::Blocks
52
+ include Adafruit::IO::Client::Dashboards
53
+
54
+ include Adafruit::IO::Client::User
46
55
 
47
56
  private
48
57
 
@@ -75,7 +84,7 @@ module Adafruit
75
84
 
76
85
  # safely build URL paths from segments
77
86
  def safe_path_join(*paths)
78
- paths = paths.compact.reject(&:empty?)
87
+ paths = paths.compact.map(&:to_s).reject(&:empty?)
79
88
  last = paths.length - 1
80
89
  paths.each_with_index.map { |path, index|
81
90
  safe_path_expand(path, index, last)
@@ -0,0 +1,53 @@
1
+ module Adafruit
2
+ module IO
3
+ class Client
4
+ module Blocks
5
+
6
+ # Get all blocks for a dashboard. Requires dashboard_key.
7
+ def blocks(*args)
8
+ username, arguments = extract_username(args)
9
+ dashboard_key = require_argument(arguments, :dashboard_key)
10
+
11
+ get api_url(username, 'dashboards', dashboard_key, 'blocks')
12
+ end
13
+
14
+ # Get a block specified by ID
15
+ def block(*args)
16
+ username, arguments = extract_username(args)
17
+ dashboard_key = require_argument(arguments, :dashboard_key)
18
+ block_id = get_id_from_arguments(arguments)
19
+
20
+ get api_url(username, 'dashboards', dashboard_key, 'blocks', block_id)
21
+ end
22
+
23
+ def create_block(*args)
24
+ username, arguments = extract_username(args)
25
+ dashboard_key = require_argument(arguments, :dashboard_key)
26
+ block_attrs = arguments.shift
27
+
28
+ post api_url(username, 'groups'), group_attrs
29
+ end
30
+
31
+ def delete_block(*args)
32
+ username, arguments = extract_username(args)
33
+ dashboard_key = require_argument(arguments, :dashboard_key)
34
+ block_id = get_id_from_arguments(arguments)
35
+
36
+ delete api_url(username, 'dashboards', dashboard_key, 'blocks', block_id)
37
+ end
38
+
39
+ def update_block(*args)
40
+ username, arguments = extract_username(args)
41
+ dashboard_key = require_argument(arguments, :dashboard_key)
42
+ block_id = get_id_from_arguments(arguments)
43
+
44
+ query = get_query_from_arguments(arguments, %w(name properties visual_type column row size_x size_y block_feeds))
45
+
46
+ put api_url(username, 'dashboards', dashboard_key, 'blocks', block_id), query
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,48 @@
1
+ module Adafruit
2
+ module IO
3
+ class Client
4
+ module Dashboards
5
+
6
+ # Get all dashboards.
7
+ def dashboards(*args)
8
+ username, _ = extract_username(args)
9
+
10
+ get api_url(username, 'dashboards')
11
+ end
12
+
13
+ # Get a dashboard specified by key
14
+ def dashboard(*args)
15
+ username, arguments = extract_username(args)
16
+ dashboard_key = get_key_from_arguments(arguments)
17
+
18
+ get api_url(username, 'dashboards', dashboard_key)
19
+ end
20
+
21
+ # Create a dashboard. No attributes need to be passed in.
22
+ def create_dashboard(*args)
23
+ username, arguments = extract_username(args)
24
+ attrs = arguments.shift
25
+
26
+ post api_url(username, 'dashboards'), attrs
27
+ end
28
+
29
+ def delete_dashboard(*args)
30
+ username, arguments = extract_username(args)
31
+ dashboard_key = get_key_from_arguments(arguments)
32
+
33
+ delete api_url(username, 'dashboards', dashboard_key)
34
+ end
35
+
36
+ def update_dashboard(*args)
37
+ username, arguments = extract_username(args)
38
+ dashboard_key = get_key_from_arguments(arguments)
39
+ query = get_query_from_arguments(arguments, %w(name key))
40
+
41
+ put api_url(username, 'dashboards', dashboard_key), query
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+
@@ -13,32 +13,23 @@ module Adafruit
13
13
  # Get a token specified by key
14
14
  def token(*args)
15
15
  username, arguments = extract_username(args)
16
- token_key = get_key_from_arguments(arguments)
16
+ token_id = get_id_from_arguments(arguments)
17
17
 
18
- get api_url(username, 'tokens', token_key)
19
- end
20
-
21
- # Get a token along with additional details about the token. This method
22
- # has more to lookup and so is slower than `token`
23
- def token_details(*args)
24
- username, arguments = extract_username(args)
25
- token_key = get_id_from_arguments(arguments)
26
-
27
- get api_url(username, 'tokens', token_key, 'details')
18
+ get api_url(username, 'tokens', token_id)
28
19
  end
29
20
 
21
+ # Create a token. No attributes need to be passed in.
30
22
  def create_token(*args)
31
23
  username, arguments = extract_username(args)
32
- token_attrs = arguments.shift
33
24
 
34
- post api_url(username, 'tokens'), token_attrs
25
+ post api_url(username, 'tokens')
35
26
  end
36
27
 
37
28
  def delete_token(*args)
38
29
  username, arguments = extract_username(args)
39
- token_key = get_id_from_arguments(arguments)
30
+ token_id = get_id_from_arguments(arguments)
40
31
 
41
- delete api_url(username, 'tokens', token_key)
32
+ delete api_url(username, 'tokens', token_id)
42
33
  end
43
34
 
44
35
  end
@@ -0,0 +1,17 @@
1
+
2
+ module Adafruit
3
+ module IO
4
+ class Client
5
+ module User
6
+
7
+ # Get user associated with the current key. If this method returns nil
8
+ # it means you have a bad key.
9
+ def user(*args)
10
+ get '/api/v2/user'
11
+ end
12
+
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -1,5 +1,5 @@
1
1
  module Adafruit
2
2
  module IO
3
- VERSION = "2.0.0.beta.3"
3
+ VERSION = "2.0.0.beta.4"
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.3
4
+ version: 2.0.0.beta.4
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-04-13 00:00:00.000000000 Z
12
+ date: 2017-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -109,10 +109,13 @@ files:
109
109
  - lib/adafruit/io.rb
110
110
  - lib/adafruit/io/arguments.rb
111
111
  - lib/adafruit/io/client.rb
112
+ - lib/adafruit/io/client/blocks.rb
113
+ - lib/adafruit/io/client/dashboards.rb
112
114
  - lib/adafruit/io/client/data.rb
113
115
  - lib/adafruit/io/client/feeds.rb
114
116
  - lib/adafruit/io/client/groups.rb
115
117
  - lib/adafruit/io/client/tokens.rb
118
+ - lib/adafruit/io/client/user.rb
116
119
  - lib/adafruit/io/configurable.rb
117
120
  - lib/adafruit/io/mqtt.rb
118
121
  - lib/adafruit/io/request_handler.rb
@@ -142,4 +145,3 @@ signing_key:
142
145
  specification_version: 4
143
146
  summary: Adafruit IO API Client Library
144
147
  test_files: []
145
- has_rdoc: