particlerb 1.2.0 → 1.3.0

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: b3cd7821e357f56784da61e8a4153386b1dc37f8
4
- data.tar.gz: 187b03c7a9f20f73f82bcf11c42ad41c0b0b20ee
3
+ metadata.gz: 37bc075ad379696171285775ffe5459576911a3a
4
+ data.tar.gz: 106fc46626db184c125f1c58b7ed401db52d5538
5
5
  SHA512:
6
- metadata.gz: 7e186ccf65aaca73843e27aa03b71784577db8fb58bc6e330ca056eb6c710f72f1ac53a5a663e153b4f9e1b0c81b803520c266f11b896b2aea916f6fffe74b38
7
- data.tar.gz: a932cd5ff45d59b23994ad3afd50e700dc5ff21c7881d9b61739063ad0efe5eeda826e914e92d590593dc5eec806d693c6cbd735ba77cf3e62e63ec02847153d
6
+ metadata.gz: 62251040926a8069a2323eaa8b430ee751b0e6de00825d0b70fa13a29939133d91664f810c376bf14d703f2b62ecc819c30be297ca7bc91f5798551e16191a77
7
+ data.tar.gz: cc6982a03d9bd6861bf03d37b3fe8684ce8d7f236fb9f298d5a093afa6b847c2d0203149797eab98f64fe8ed4d11e065e32c93aa005102f650d486ceb7581044
data/README.md CHANGED
@@ -145,6 +145,14 @@ Signal a device to start blinking the RGB LED in rainbow patterns. Returns wheth
145
145
  Particle.device('nyan_cat').signal(true)
146
146
  ```
147
147
 
148
+ Create a new device for a product that allows self-provisioning. Currently only the Raspberry Pi (product id 31) allows this. Returns the new device. You can then claim the device when it is online.
149
+
150
+ ```ruby
151
+ device = Particle.provision_device(product_id: 31)
152
+ # Wait for device to be online
153
+ device.claim
154
+ ```
155
+
148
156
  Change the product id. The meaning of the product id is specific to your application and account.
149
157
 
150
158
  ```ruby
@@ -47,6 +47,16 @@ module Particle
47
47
  device(result[:id])
48
48
  end
49
49
 
50
+ # Create a new Particle device
51
+ #
52
+ # @param product [String] A product id
53
+ # @return [Device] A device object to interact with
54
+ def provision_device(params)
55
+ product_id = params[:product_id] or raise ArgumentError.new("product_id parameter is required")
56
+ result = post(Device.provision_path, product_id: product_id)
57
+ device(result[:device_id])
58
+ end
59
+
50
60
  # Remove a Particle device from your account
51
61
  #
52
62
  # @param target [String, Device] A device id, name or {Device} object
@@ -128,7 +138,7 @@ module Particle
128
138
  # (default rsa)
129
139
  # @return [boolean] true when successful
130
140
  def update_device_public_key(target, public_key, algorithm = 'rsa')
131
- result = post(Device.provision_path,
141
+ result = post(Device.update_keys_path,
132
142
  deviceID: device(target).id,
133
143
  publicKey: public_key,
134
144
  algorithm: algorithm)
@@ -4,12 +4,13 @@ module Particle
4
4
 
5
5
  # Domain model for one Particle device
6
6
  class Device < Model
7
- ID_REGEX = /\h{24}/
7
+ ID_REGEX = /^\h{24}$/
8
8
  PRODUCT_IDS = {
9
9
  0 => "Core".freeze,
10
10
  6 => "Photon".freeze,
11
11
  8 => "P1".freeze,
12
- 10 => "Electron".freeze
12
+ 10 => "Electron".freeze,
13
+ 31 => "Raspberry Pi".freeze
13
14
  }
14
15
 
15
16
  def initialize(client, attributes)
@@ -183,7 +184,11 @@ module Particle
183
184
  end
184
185
 
185
186
  def self.provision_path
186
- "v1/provisioning/x"
187
+ "v1/devices"
188
+ end
189
+
190
+ def self.update_keys_path
191
+ "/v1/provisioning/x"
187
192
  end
188
193
 
189
194
  def path
@@ -27,10 +27,12 @@ module Particle
27
27
 
28
28
  def initialize(response=nil)
29
29
  @response = response
30
+ @short_message = build_short_message
30
31
  super(build_error_message)
31
32
  end
32
33
 
33
34
  attr_reader :response
35
+ attr_reader :short_message
34
36
 
35
37
  private
36
38
 
@@ -42,13 +44,23 @@ module Particle
42
44
  end
43
45
  end
44
46
 
47
+ def build_short_message
48
+ if response && response[:body] && response[:body][:error]
49
+ response[:body][:error]
50
+ elsif response && response[:body] && response[:body][:errors]
51
+ response[:body][:errors].join ", "
52
+ else
53
+ self.class.name
54
+ end
55
+ end
56
+
45
57
  def build_error_message
46
- return nil if @response.nil?
58
+ return nil if response.nil?
47
59
 
48
- message = "#{@response[:method].to_s.upcase} "
49
- message << redact_url(@response[:url].to_s) + ": "
50
- message << "#{@response[:status]} - "
51
- message << "#{@response[:body]}"
60
+ message = "#{response[:method].to_s.upcase} "
61
+ message << redact_url(response[:url].to_s) + ": "
62
+ message << "#{response[:status]} - "
63
+ message << "#{response[:body]}"
52
64
  message
53
65
  end
54
66
 
@@ -1,3 +1,3 @@
1
1
  module Particle
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
data/particlerb.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'listen', '~> 3.0.8'
29
29
  spec.add_development_dependency 'vcr', '~> 2.9'
30
30
  spec.add_development_dependency 'webmock', '~> 1.21'
31
+ spec.add_development_dependency 'addressable', '~> 2.4.0'
31
32
  spec.add_development_dependency 'multi_json', '~> 1.11'
32
33
  spec.add_development_dependency 'highline', '~> 1.7'
33
34
  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.2.0
4
+ version: 1.3.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: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: '1.21'
167
+ - !ruby/object:Gem::Dependency
168
+ name: addressable
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 2.4.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.4.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: multi_json
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -246,7 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
260
  version: 1.3.5
247
261
  requirements: []
248
262
  rubyforge_project:
249
- rubygems_version: 2.2.5
263
+ rubygems_version: 2.4.5.1
250
264
  signing_key:
251
265
  specification_version: 4
252
266
  summary: Ruby client for the Particle.io Cloud API