Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit bf6ad0e

Browse files
committed
Imported Debian patch 1.3.0-1
2 parents fa08c58 + 08a6134 commit bf6ad0e

File tree

9 files changed

+68
-177
lines changed

9 files changed

+68
-177
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ Signal a device to start blinking the RGB LED in rainbow patterns. Returns wheth
145145
Particle.device('nyan_cat').signal(true)
146146
```
147147

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+
148156
Change the product id. The meaning of the product id is specific to your application and account.
149157

150158
```ruby

debian/changelog

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
ruby-particlerb (1.2.0-1) unstable; urgency=medium
1+
ruby-particlerb (1.3.0-1) unstable; urgency=medium
22

3-
* RubyGems release 1.2.0
3+
* Add device provisioning
44

5-
-- Julien Vanier <[email protected]> Thu, 27 Oct 2016 16:15:37 -0400
5+
-- Julien Vanier <[email protected]> Tue, 08 Nov 2016 11:49:27 -0500

debian/copyright

Lines changed: 17 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -11,167 +11,20 @@ Copyright: 2016 Particle <[email protected]>
1111
License: LGPL-3
1212
Comment: the Debian packaging is licensed under the same terms as the original package.
1313

14-
License: GPL-3
15-
16-
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
17-
Everyone is permitted to copy and distribute verbatim copies
18-
of this license document, but changing it is not allowed.
19-
20-
21-
This version of the GNU Lesser General Public License incorporates
22-
the terms and conditions of version 3 of the GNU General Public
23-
License, supplemented by the additional permissions listed below.
24-
25-
0. Additional Definitions.
26-
27-
As used herein, "this License" refers to version 3 of the GNU Lesser
28-
General Public License, and the "GNU GPL" refers to version 3 of the GNU
29-
General Public License.
30-
31-
"The Library" refers to a covered work governed by this License,
32-
other than an Application or a Combined Work as defined below.
33-
34-
An "Application" is any work that makes use of an interface provided
35-
by the Library, but which is not otherwise based on the Library.
36-
Defining a subclass of a class defined by the Library is deemed a mode
37-
of using an interface provided by the Library.
38-
39-
A "Combined Work" is a work produced by combining or linking an
40-
Application with the Library. The particular version of the Library
41-
with which the Combined Work was made is also called the "Linked
42-
Version".
43-
44-
The "Minimal Corresponding Source" for a Combined Work means the
45-
Corresponding Source for the Combined Work, excluding any source code
46-
for portions of the Combined Work that, considered in isolation, are
47-
based on the Application, and not on the Linked Version.
48-
49-
The "Corresponding Application Code" for a Combined Work means the
50-
object code and/or source code for the Application, including any data
51-
and utility programs needed for reproducing the Combined Work from the
52-
Application, but excluding the System Libraries of the Combined Work.
53-
54-
1. Exception to Section 3 of the GNU GPL.
55-
56-
You may convey a covered work under sections 3 and 4 of this License
57-
without being bound by section 3 of the GNU GPL.
58-
59-
2. Conveying Modified Versions.
60-
61-
If you modify a copy of the Library, and, in your modifications, a
62-
facility refers to a function or data to be supplied by an Application
63-
that uses the facility (other than as an argument passed when the
64-
facility is invoked), then you may convey a copy of the modified
65-
version:
66-
67-
a) under this License, provided that you make a good faith effort to
68-
ensure that, in the event an Application does not supply the
69-
function or data, the facility still operates, and performs
70-
whatever part of its purpose remains meaningful, or
71-
72-
b) under the GNU GPL, with none of the additional permissions of
73-
this License applicable to that copy.
74-
75-
3. Object Code Incorporating Material from Library Header Files.
76-
77-
The object code form of an Application may incorporate material from
78-
a header file that is part of the Library. You may convey such object
79-
code under terms of your choice, provided that, if the incorporated
80-
material is not limited to numerical parameters, data structure
81-
layouts and accessors, or small macros, inline functions and templates
82-
(ten or fewer lines in length), you do both of the following:
83-
84-
a) Give prominent notice with each copy of the object code that the
85-
Library is used in it and that the Library and its use are
86-
covered by this License.
87-
88-
b) Accompany the object code with a copy of the GNU GPL and this license
89-
document.
90-
91-
4. Combined Works.
92-
93-
You may convey a Combined Work under terms of your choice that,
94-
taken together, effectively do not restrict modification of the
95-
portions of the Library contained in the Combined Work and reverse
96-
engineering for debugging such modifications, if you also do each of
97-
the following:
98-
99-
a) Give prominent notice with each copy of the Combined Work that
100-
the Library is used in it and that the Library and its use are
101-
covered by this License.
102-
103-
b) Accompany the Combined Work with a copy of the GNU GPL and this license
104-
document.
105-
106-
c) For a Combined Work that displays copyright notices during
107-
execution, include the copyright notice for the Library among
108-
these notices, as well as a reference directing the user to the
109-
copies of the GNU GPL and this license document.
110-
111-
d) Do one of the following:
112-
113-
0) Convey the Minimal Corresponding Source under the terms of this
114-
License, and the Corresponding Application Code in a form
115-
suitable for, and under terms that permit, the user to
116-
recombine or relink the Application with a modified version of
117-
the Linked Version to produce a modified Combined Work, in the
118-
manner specified by section 6 of the GNU GPL for conveying
119-
Corresponding Source.
120-
121-
1) Use a suitable shared library mechanism for linking with the
122-
Library. A suitable mechanism is one that (a) uses at run time
123-
a copy of the Library already present on the user's computer
124-
system, and (b) will operate properly with a modified version
125-
of the Library that is interface-compatible with the Linked
126-
Version.
127-
128-
e) Provide Installation Information, but only if you would otherwise
129-
be required to provide such information under section 6 of the
130-
GNU GPL, and only to the extent that such information is
131-
necessary to install and execute a modified version of the
132-
Combined Work produced by recombining or relinking the
133-
Application with a modified version of the Linked Version. (If
134-
you use option 4d0, the Installation Information must accompany
135-
the Minimal Corresponding Source and Corresponding Application
136-
Code. If you use option 4d1, you must provide the Installation
137-
Information in the manner specified by section 6 of the GNU GPL
138-
for conveying Corresponding Source.)
139-
140-
5. Combined Libraries.
141-
142-
You may place library facilities that are a work based on the
143-
Library side by side in a single library together with other library
144-
facilities that are not Applications and are not covered by this
145-
License, and convey such a combined library under terms of your
146-
choice, if you do both of the following:
147-
148-
a) Accompany the combined library with a copy of the same work based
149-
on the Library, uncombined with any other library facilities,
150-
conveyed under the terms of this License.
151-
152-
b) Give prominent notice with the combined library that part of it
153-
is a work based on the Library, and explaining where to find the
154-
accompanying uncombined form of the same work.
155-
156-
6. Revised Versions of the GNU Lesser General Public License.
157-
158-
The Free Software Foundation may publish revised and/or new versions
159-
of the GNU Lesser General Public License from time to time. Such new
160-
versions will be similar in spirit to the present version, but may
161-
differ in detail to address new problems or concerns.
162-
163-
Each version is given a distinguishing version number. If the
164-
Library as you received it specifies that a certain numbered version
165-
of the GNU Lesser General Public License "or any later version"
166-
applies to it, you have the option of following the terms and
167-
conditions either of that published version or of any later version
168-
published by the Free Software Foundation. If the Library as you
169-
received it does not specify a version number of the GNU Lesser
170-
General Public License, you may choose any version of the GNU Lesser
171-
General Public License ever published by the Free Software Foundation.
172-
173-
If the Library as you received it specifies that a proxy can decide
174-
whether future versions of the GNU Lesser General Public License shall
175-
apply, that proxy's public statement of acceptance of any version is
176-
permanent authorization for you to choose that version for the
177-
Library.
14+
License: LGPL-3
15+
/usr/share/common-licenses/LGPL-3
16+
17+
Licensed under the GNU Lesser General Public License, Version 3 (the "License");
18+
you may not use this file except in compliance with the License.
19+
You may obtain a copy of the License at
20+
.
21+
https://www.gnu.org/licenses/lgpl-3.0.en.html
22+
.
23+
Unless required by applicable law or agreed to in writing, software
24+
distributed under the License is distributed on an "AS IS" BASIS,
25+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
See the License for the specific language governing permissions and
27+
limitations under the License.
28+
.
29+
On Debian systems, the GNU Lesser General Public License, Version 3, can be found at
30+
/usr/share/common-licenses/LGPL-3

debian/watch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=3
2+
http://pkg-ruby-extras.alioth.debian.org/cgi-bin/gemwatch/particlerb .*/particlerb-(.*).tar.gz

lib/particle/client/devices.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ def claim_device(target)
4747
device(result[:id])
4848
end
4949

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+
5060
# Remove a Particle device from your account
5161
#
5262
# @param target [String, Device] A device id, name or {Device} object
@@ -128,7 +138,7 @@ def change_device_product(target, product_id, should_update = false)
128138
# (default rsa)
129139
# @return [boolean] true when successful
130140
def update_device_public_key(target, public_key, algorithm = 'rsa')
131-
result = post(Device.provision_path,
141+
result = post(Device.update_keys_path,
132142
deviceID: device(target).id,
133143
publicKey: public_key,
134144
algorithm: algorithm)

lib/particle/device.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ module Particle
44

55
# Domain model for one Particle device
66
class Device < Model
7-
ID_REGEX = /\h{24}/
7+
ID_REGEX = /^\h{24}$/
88
PRODUCT_IDS = {
99
0 => "Core".freeze,
1010
6 => "Photon".freeze,
1111
8 => "P1".freeze,
12-
10 => "Electron".freeze
12+
10 => "Electron".freeze,
13+
31 => "Raspberry Pi".freeze
1314
}
1415

1516
def initialize(client, attributes)
@@ -183,7 +184,11 @@ def self.claim_path
183184
end
184185

185186
def self.provision_path
186-
"v1/provisioning/x"
187+
"v1/devices"
188+
end
189+
190+
def self.update_keys_path
191+
"/v1/provisioning/x"
187192
end
188193

189194
def path

lib/particle/error.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ def self.from_response(response)
2727

2828
def initialize(response=nil)
2929
@response = response
30+
@short_message = build_short_message
3031
super(build_error_message)
3132
end
3233

3334
attr_reader :response
35+
attr_reader :short_message
3436

3537
private
3638

@@ -42,13 +44,23 @@ def self.bad_request_error(body)
4244
end
4345
end
4446

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+
4557
def build_error_message
46-
return nil if @response.nil?
58+
return nil if response.nil?
4759

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]}"
5264
message
5365
end
5466

lib/particle/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Particle
2-
VERSION = "1.2.0".freeze
2+
VERSION = "1.3.0".freeze
33
end

particlerb.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
2828
spec.add_development_dependency 'listen', '~> 3.0.8'
2929
spec.add_development_dependency 'vcr', '~> 2.9'
3030
spec.add_development_dependency 'webmock', '~> 1.21'
31+
spec.add_development_dependency 'addressable', '~> 2.4.0'
3132
spec.add_development_dependency 'multi_json', '~> 1.11'
3233
spec.add_development_dependency 'highline', '~> 1.7'
3334
end

0 commit comments

Comments
 (0)