particlerb 1.3.1 → 1.4.0

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: 42903b63b82b54886a0445733da1e7a61a3dffad
4
- data.tar.gz: 2b70acdb2e5a7543d15e6f87c4885544c199c4f5
3
+ metadata.gz: 60ae309f5efa8ed76934ccce2800ab84ff2e73d0
4
+ data.tar.gz: 80294252d1049858593e5dadb97a9d9740f1fbf8
5
5
  SHA512:
6
- metadata.gz: cc343874fa16fba14def9c184e153b1d077e61adb5e8109370cb6e4f1ecf1ac9dae056918cf262c7550753accdbd637b607adbbe7d97a7653af9cb234eb3a753
7
- data.tar.gz: 1d6bd48d026c95289e6429bb62e454490f9a83621870404ec0c59afa9f598c2473cece8e88092c44ece31257da3bb09590d54651d873887e6c27de718b2ed5ca
6
+ metadata.gz: d70c2a7ef5356f444cc468b344cf19e457fc7dbcebe4195b56caab4406f031f9e812bd104586ca878f26962a28f51685238429d3e40649556eafcb2140ef5618
7
+ data.tar.gz: 7013f5fcb31f8eb05c19ba6ab527173d0d1b0438d0747fa254d1b4c52c5822d5c9c02633340d10660e9fe1079aab597e2c5a2a0a98bd2d57fb32a47b397533e8
data/README.md CHANGED
@@ -18,7 +18,7 @@ Ruby client for the [Particle.io] Cloud API with an object-oriented interface
18
18
  $ gem install particlerb
19
19
 
20
20
  # or add to your Gemfile
21
- gem "particlerb", "~> 0.0.3"
21
+ gem "particlerb", "~> 1.4.0"
22
22
 
23
23
  # Require the gem
24
24
  require 'particle'
@@ -62,8 +62,8 @@ client.devices
62
62
 
63
63
  When using this gem in a multi-threaded program like a Rails application running on the puma server, it's safer to use `Particle::Client.new` in each thread rather than using the global `Particle.client`.
64
64
 
65
- [Web IDE]: http://docs.particle.io/core/build/#flash-apps-with-particle-build-account-information
66
- [Particle CLI]: http://docs.particle.io/core/cli
65
+ [Web IDE]: https://docs.particle.io/guide/getting-started/build
66
+ [Particle CLI]: https://docs.particle.io/reference/cli
67
67
 
68
68
  ## Interacting with devices
69
69
 
@@ -139,6 +139,12 @@ device.variable('version') # ==> "1.0.1"
139
139
  device.get('version') # aliased as get
140
140
  ```
141
141
 
142
+ Ping a device to see if it is online. Returns true when online.
143
+
144
+ ```ruby
145
+ Particle.device('nyan_cat').ping
146
+ ```
147
+
142
148
  Signal a device to start blinking the RGB LED in rainbow patterns. Returns whether the device is signaling.
143
149
 
144
150
  ```ruby
@@ -153,12 +159,6 @@ device = Particle.provision_device(product_id: 31)
153
159
  device.claim
154
160
  ```
155
161
 
156
- Change the product id. The meaning of the product id is specific to your application and account.
157
-
158
- ```ruby
159
- Particle.device('f8bbe1e6e69e05c9c405ba1ca504d438061f1b0d').change_product(3)
160
- ```
161
-
162
162
  Update the public key for a device. The public key must be in PEM format. See <spec/fixtures/device.pub.pem> for an example.
163
163
 
164
164
  ```ruby
@@ -168,7 +168,7 @@ Particle.device('f8bbe1e6e69e05c9c405ba1ca504d438061f1b0d').update_public_key(pu
168
168
 
169
169
  See the [Particle Cloud API documentation about devices][device docs] for more details.
170
170
 
171
- [device docs]: http://docs.particle.io/core/api/#introduction-device-information
171
+ [device docs]: https://docs.particle.io/reference/api/#devices
172
172
 
173
173
  ## Interacting with events
174
174
 
@@ -185,7 +185,7 @@ Data is converted to JSON if it is a Hash or an Array, otherwise it is converted
185
185
 
186
186
  See the [Particle Cloud API documentation about publishing events][publish docs] for more details.
187
187
 
188
- [publish docs]: http://docs.particle.io/core/api/#publishing-events
188
+ [publish docs]: https://docs.particle.io/reference/api/#publish-an-event
189
189
 
190
190
  ### Limitation: Subscribe not supported
191
191
 
@@ -255,8 +255,8 @@ Particle.webhooks.each(&:remove) # remove all
255
255
 
256
256
  See the [Particle Cloud API documentation about webhooks][webhook docs] for more details.
257
257
 
258
- [webhook docs]: http://docs.particle.io/core/webhooks/
259
- [webhook options]: http://docs.particle.io/core/webhooks/#webhook-options
258
+ [webhook docs]: https://docs.particle.io/reference/webhooks
259
+ [webhook options]: https://docs.particle.io/reference/webhooks/#webhook-properties
260
260
 
261
261
  ## Authentication
262
262
 
@@ -294,6 +294,9 @@ Particle.token.create("me@example.com", "pa$$w0rd")
294
294
 
295
295
  * `expires_in`: number of seconds that the token will be valid
296
296
  * `expires_at`: `Date` when the token will become invalid
297
+ * `client`: a Particle OAuth client to use. Defaults to `particle`.
298
+ * `secret`: the corresponding OAuth secret. Defaults to `particle`.
299
+ * `grant_type`: Type of OAuth authentication flow to use. Defaults to 'password'
297
300
 
298
301
  Invalidate and delete a token. Returns true on success.
299
302
 
@@ -304,7 +307,7 @@ Particle.tokens.first.remove("me@example.com", "pa$$w0rd")
304
307
 
305
308
  See the [Particle Cloud API documentation about authentication and token][authentication docs] for more details.
306
309
 
307
- [authentication docs]: http://docs.particle.io/core/api/#introduction-authentication
310
+ [authentication docs]: https://docs.particle.io/reference/api/#authentication
308
311
 
309
312
  ## Compiling and flashing
310
313
 
@@ -343,8 +346,60 @@ File.new('application.bin', 'w') { |f| f.write(binary) }
343
346
 
344
347
  See the [Particle Cloud API documentation about firmware][firmware docs] for more details.
345
348
 
346
- [firmware docs]: http://docs.particle.io/core/api/#basic-functions-verifying-and-flashing-new-firmware
349
+ [firmware docs]: https://docs.particle.io/reference/api/#firmware
350
+
351
+ ## Libraries
352
+
353
+ Interact with firmware libraries.
354
+
355
+ List most popular libraries. Response array has pagination.
356
+
357
+ ```ruby
358
+ libs = Particle.libraries
359
+ libs.each { |lib| puts lib.name }
360
+ libs.next_page if libs.has_next?
361
+
362
+ libs = Particle.libraries name: "gps"
363
+ ```
364
+
365
+ Get details about a library.
366
+
367
+ ```ruby
368
+ lib = Particle.library("internet_button")
369
+ puts "#{lib.name}@#{lib.version}: #{lib.sentence}"
370
+ ```
371
+
372
+ See the [Particle Cloud API documentation about libraries][library docs] for more details.
373
+
374
+ [library docs]: https://docs.particle.io/reference/api/#libraries
375
+
376
+ ## OAuth Clients
377
+
378
+ Interact with OAuth clients used to authenticate requests with the Particle cloud. See [Authentication](#authentication).
379
+
380
+ List OAuth clients. Returns an `Array` of `Particle::OAuthClinet`.
381
+
382
+ ```ruby
383
+ clients = Particle.oauth_clients
384
+ clients.each { |client| puts client.id }
385
+ ```
386
+
387
+ Create an OAuth client. Returns a `Particle::OAuthClient`. Note that
388
+ this is the only time that the `secret` attribute will be returned by
389
+ the Particle API.
347
390
 
391
+ ```ruby
392
+ client = Particle.create_oauth_client(name: "my-client", type: "installed")
393
+ puts "OAuth client ID: #{client.id} OAuth client secret: #{client.secret}"
394
+ ```
395
+
396
+ Remove an OAuth client by id. Returns `true` on success.
397
+
398
+ ```ruby
399
+ Particle.remove_oauth_client("my-client-1234")
400
+ client = Particle.oauth_clients.first
401
+ client.remove
402
+ ```
348
403
 
349
404
  ## Errors
350
405
 
@@ -364,7 +419,43 @@ See [a description of each error on the Particle API docs][error docs].
364
419
 
365
420
  This gem uses the Faraday HTTP client library, so API call may raise `Faraday::ClientError` for things like SSL errors, DNS errors, HTTP connection timed out.
366
421
 
367
- [error docs]: http://docs.particle.io/core/api/#introduction-errors
422
+ [error docs]: https://docs.particle.io/reference/api/#errors
423
+
424
+ ## TODO
425
+
426
+ Some Particle API endpoints are not implemented yet
427
+
428
+ List devices in a product
429
+
430
+ Import devices into a product
431
+
432
+ Remove a device from a product
433
+
434
+ Update an OAuth client
435
+
436
+ Add device notes
437
+
438
+ Create a device claim code
439
+
440
+ Request a device transfer
441
+
442
+ Approve/deny a quarantined device
443
+
444
+ All SIM card endpoints (list, data usage, activate, deactivate, set data limit, release from account)
445
+
446
+ Integrations that are not webhooks
447
+
448
+ All product firmware endpoints (list, get, upload, edit, download, release)
449
+
450
+ Get library versions
451
+
452
+ Upload library
453
+
454
+ Publish library
455
+
456
+ Main product endpoints (list, get, invite team member, remove team member)
457
+
458
+ **Product functionality for many of the existing endpoints like device, firmware, etc**
368
459
 
369
460
  ## Advanced
370
461
 
@@ -401,6 +492,8 @@ Set the following environment variables:
401
492
  - `TEST_PARTICLE_PASSWORD`: your Particle password
402
493
  - `TEST_PARTICLE_ACCESS_TOKEN`: a Particle access token. You can get this from the web IDE
403
494
  - `TEST_PARTICLE_DEVICE_IDS`: a comma separated list of your device ids. You can get this from the Particle CLI `particle list`
495
+ - `TEST_PARTICLE_OAUTH_CLIENT`: a valid Particle OAuth client
496
+ - `TEST_PARTICLE_OAUTH_SECRET`: the corresponding OAuth secret
404
497
 
405
498
  Make sure **the first Particle device in `TEST_PARTICLE_DEVICE_IDS` is online** and run
406
499
 
@@ -22,6 +22,10 @@ module Particle
22
22
  super(client, attributes)
23
23
  end
24
24
  attribute_reader :platforms, :prereleases, :firmware_vendor, :version
25
+
26
+ def self.path
27
+ "v1/build_targets"
28
+ end
25
29
  end
26
30
  end
27
31
 
@@ -6,6 +6,7 @@ require 'particle/client/tokens'
6
6
  require 'particle/client/firmware'
7
7
  require 'particle/client/build_targets'
8
8
  require 'particle/client/platforms'
9
+ require 'particle/client/oauth_clients'
9
10
 
10
11
  module Particle
11
12
 
@@ -22,6 +23,7 @@ module Particle
22
23
  include Particle::Client::Firmware
23
24
  include Particle::Client::BuildTargets
24
25
  include Particle::Client::Platforms
26
+ include Particle::Client::OAuthClients
25
27
 
26
28
  def initialize(options = {})
27
29
  # Use options passed in, but fall back to module defaults
@@ -4,12 +4,11 @@ require 'ostruct'
4
4
  module Particle
5
5
  class Client
6
6
  module BuildTargets
7
- HTTP_PATH = "v1/build_targets"
8
7
  # List all available Particle cloud compile build targets
9
8
  #
10
9
  # @return [Array<BuildTarget>] List of Particle Build Targets you can compile sources with
11
10
  def build_targets
12
- get(HTTP_PATH)[:targets].map do |target_h|
11
+ get(BuildTarget.path)[:targets].map do |target_h|
13
12
  BuildTarget.new(self, target_h)
14
13
  end
15
14
  end
@@ -5,7 +5,7 @@ module Particle
5
5
 
6
6
  # Client methods for the Particle device API
7
7
  #
8
- # @see http://docs.particle.io/core/api/#introduction-list-devices
8
+ # @see https://docs.particle.io/reference/api/#devices
9
9
  module Devices
10
10
 
11
11
  # Create a domain model for a Particle device
@@ -97,6 +97,15 @@ module Particle
97
97
  result[:result]
98
98
  end
99
99
 
100
+ # Ping a device to see if it is online
101
+ #
102
+ # @param target [String, Device] A device id, name or {Device} object
103
+ # @return [boolean] true when online, false when offline
104
+ def ping_device(target)
105
+ result = put(device(target).ping_path)
106
+ result[:online]
107
+ end
108
+
100
109
  # Signal the device to start blinking the RGB LED in a rainbow
101
110
  # pattern. Useful to identify a particular device.
102
111
  #
@@ -108,27 +117,6 @@ module Particle
108
117
  result[:signaling]
109
118
  end
110
119
 
111
- # Change the product_id on the device.
112
- # Use this carefully, it will impact what updates you receive, and
113
- # can only be used for products that have given their permission
114
- #
115
- # @param target [String, Device] A device id, name or {Device} object
116
- # @param product_id [String] New product id
117
- # @param should_update [String] if the device should be
118
- # immediately updated after changing the product_id
119
- # @return [boolean] true on success
120
- def change_device_product(target, product_id, should_update = false)
121
- params = {
122
- product_id: product_id,
123
- update_after_claim: should_update
124
- }
125
- result = put(device(target).path, params)
126
- if result[:error] == "Nothing to do?"
127
- result[:ok] = false
128
- end
129
- result[:ok]
130
- end
131
-
132
120
  # Update the public key for a device you own
133
121
  #
134
122
  # @param target [String, Device] A device id, name or {Device} object
@@ -0,0 +1,28 @@
1
+ require 'particle/library'
2
+
3
+ module Particle
4
+ class Client
5
+
6
+ # Client methods for the Particle firmware library API
7
+ #
8
+ # @see https://docs.particle.io/reference/api/#libraries
9
+ module Libraries
10
+
11
+ # Create a domain model for a firmware library
12
+ #
13
+ # @param target [String, Hash, Library] A library name, hash of attributes or {Library} object
14
+ # @return [Library] A library object to interact with
15
+ def library(target)
16
+ if target.is_a? Library
17
+ target
18
+ else
19
+ Library.new(self, target)
20
+ end
21
+ end
22
+
23
+ # List firmware libraries, sorted, filtered and paginated
24
+ #
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,52 @@
1
+ require 'particle/oauth_client'
2
+
3
+ module Particle
4
+ class Client
5
+
6
+ # Client methods for the Particle OAuth client API
7
+ #
8
+ # @see https://docs.particle.io/reference/api/#oauth-clients
9
+ module OAuthClients
10
+
11
+ # Create a domain model for a Particle OAuth client
12
+ #
13
+ # @param target [String, Hash, OAuthClient] A client id, hash of attributes or {OAuthClient} object
14
+ # @return [OAuthClient] A OAuth client object to interact with
15
+ def oauth_client(target)
16
+ if target.is_a? OAuthClient
17
+ target
18
+ else
19
+ OAuthClient.new(self, target)
20
+ end
21
+ end
22
+
23
+ # List all Particle OAuth clients on the account
24
+ #
25
+ # @return [Array<OAuthClient>] List of Particle OAuth clients to interact with
26
+ def oauth_clients
27
+ result = get(OAuthClient.list_path)
28
+ result[:clients].map do |attributes|
29
+ oauth_client(attributes)
30
+ end
31
+ end
32
+
33
+ # Create a Particle OAuth client
34
+ #
35
+ # @param options [Hash] Options to configure the client
36
+ # @return [OAuthClient] An OAuth client object to interact with
37
+ def create_oauth_client(attributes)
38
+ result = post(OAuthClient.create_path, attributes)
39
+ oauth_client(result[:client])
40
+ end
41
+
42
+ # Remove a Particle OAuth client
43
+ #
44
+ # @param target [String, OAuthClient] A client id or {OAuthClient} object
45
+ # @return [boolean] true for success
46
+ def remove_oauth_client(target)
47
+ delete(oauth_client(target).path)
48
+ true
49
+ end
50
+ end
51
+ end
52
+ end
@@ -10,7 +10,7 @@ module Particle
10
10
  # @return [Array<Platform>] List of Particle Hardware platforms that have build targets you can compile sources with
11
11
  def platforms
12
12
  @platforms = []
13
- get(Particle::Client::BuildTargets::HTTP_PATH)[:platforms].each_pair do |platform_name, platform_id|
13
+ get(BuildTarget.path)[:platforms].each_pair do |platform_name, platform_id|
14
14
  @platforms << Platform.new(self, {name: platform_name, id: platform_id})
15
15
  end
16
16
  @platforms
@@ -49,17 +49,25 @@ module Particle
49
49
  # :expires_in => How many seconds should the token last for?
50
50
  # 0 means a token that never expires
51
51
  # :expires_at => Date and time when should the token expire
52
+ # :client => Particle OAuth client to use.
53
+ # Defaults to 'particle'
54
+ # :secret => Corresponding OAuth secret to use.
55
+ # Defaults to 'particle'
56
+ # :grant_type => Type of OAuth authentication flow to use
57
+ # Defaults to 'password'
52
58
  # @return [Token] The token object
53
59
  def create_token(username, password, options = {})
60
+ client = options.delete(:client) { 'particle' }
61
+ secret = options.delete(:secret) { 'particle' }
54
62
  data = URI.encode_www_form({
55
- grant_type: 'password', # specified by docs
63
+ grant_type: 'password',
56
64
  username: username,
57
65
  password: password
58
66
  }.merge(options))
59
67
  http_options = {
60
68
  headers: { content_type: "application/x-www-form-urlencoded" },
61
- username: 'particle', # specified by docs
62
- password: 'particle' # specified by docs
69
+ username: client,
70
+ password: secret
63
71
  }
64
72
  result = request(:post, Token.create_path, data, http_options)
65
73
  result[:token] = result.delete(:access_token)
@@ -116,6 +116,13 @@ module Particle
116
116
  end
117
117
  alias_method :get, :variable
118
118
 
119
+ # Ping a device to see if it is online
120
+ #
121
+ # @return [boolean] true when online, false when offline
122
+ def ping
123
+ @client.ping_device(self)
124
+ end
125
+
119
126
  # Signal the device to start blinking the RGB LED in a rainbow
120
127
  # pattern. Useful to identify a particular device.
121
128
  #
@@ -152,19 +159,7 @@ module Particle
152
159
  @client.compile(file_paths, device_id: id)
153
160
  end
154
161
 
155
- # Change the product_id on the device.
156
- # Use this carefully, it will impact what updates you receive, and
157
- # can only be used for products that have given their permission
158
- #
159
- # @param product_id [String] New product id
160
- # @param should_update [String] if the device should be
161
- # immediately updated after changing the product_id
162
- # @return [boolean] true on success
163
- def change_product(product_id, should_update = false)
164
- @client.change_device_product(self, product_id, should_update)
165
- end
166
-
167
- # Update the public key for a device you own
162
+ # Update the public key for this device
168
163
  #
169
164
  # @param public_key [String] The public key in PEM format (default
170
165
  # format generated by openssl)
@@ -202,6 +197,10 @@ module Particle
202
197
  def variable_path(name)
203
198
  path + "/#{name}"
204
199
  end
200
+
201
+ def ping_path
202
+ path + "/ping"
203
+ end
205
204
  end
206
205
  end
207
206
 
@@ -0,0 +1,15 @@
1
+ require 'particle/model'
2
+
3
+ module Particle
4
+
5
+ # Domain model for a firmware library
6
+ class Library < Model
7
+ def initialize(client, attributes)
8
+ super(client, attributes)
9
+ if attributes.is_a? String
10
+ @attributes = { name: attributes }
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,40 @@
1
+ require 'particle/model'
2
+ module Particle
3
+ # Domain model for one Particle OAuth client
4
+ class OAuthClient < Model
5
+ def initialize(client, attributes)
6
+ super(client, attributes)
7
+ end
8
+ attribute_reader :name, :id, :type, :redirect_uri, :secret
9
+
10
+ # OAuth clients can't be loaded. What you see is what you get...
11
+ def get_attributes
12
+ @loaded = true
13
+ @attributes
14
+ end
15
+
16
+ # Remove this OAuth client
17
+ #
18
+ # @example
19
+ # client = Particle.oauth_clients.first
20
+ # client.remove
21
+ #
22
+ # @return [boolean] true for success
23
+ def remove
24
+ @client.remove_oauth_client(self)
25
+ end
26
+
27
+ def self.list_path
28
+ "/v1/clients"
29
+ end
30
+
31
+ def self.create_path
32
+ "/v1/clients"
33
+ end
34
+
35
+ def path
36
+ "/v1/clients/#{id}"
37
+ end
38
+ end
39
+ end
40
+
@@ -1,3 +1,3 @@
1
1
  module Particle
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "1.4.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: particlerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Vanier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-26 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -222,6 +222,8 @@ files:
222
222
  - lib/particle/client/build_targets.rb
223
223
  - lib/particle/client/devices.rb
224
224
  - lib/particle/client/firmware.rb
225
+ - lib/particle/client/library.rb
226
+ - lib/particle/client/oauth_clients.rb
225
227
  - lib/particle/client/platforms.rb
226
228
  - lib/particle/client/publish.rb
227
229
  - lib/particle/client/tokens.rb
@@ -231,7 +233,9 @@ files:
231
233
  - lib/particle/default.rb
232
234
  - lib/particle/device.rb
233
235
  - lib/particle/error.rb
236
+ - lib/particle/library.rb
234
237
  - lib/particle/model.rb
238
+ - lib/particle/oauth_client.rb
235
239
  - lib/particle/platform.rb
236
240
  - lib/particle/response/parse_json_symbols.rb
237
241
  - lib/particle/response/raise_error.rb
@@ -260,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
264
  version: 1.3.5
261
265
  requirements: []
262
266
  rubyforge_project:
263
- rubygems_version: 2.5.1
267
+ rubygems_version: 2.6.13
264
268
  signing_key:
265
269
  specification_version: 4
266
270
  summary: Ruby client for the Particle.io Cloud API