particlerb 1.1.0 → 1.2.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 +4 -4
- data/README.md +8 -1
- data/Rakefile +1 -1
- data/lib/particle/build_target.rb +27 -0
- data/lib/particle/client/build_targets.rb +26 -0
- data/lib/particle/client/devices.rb +16 -0
- data/lib/particle/client/firmware.rb +2 -1
- data/lib/particle/client/platforms.rb +28 -0
- data/lib/particle/client.rb +4 -0
- data/lib/particle/device.rb +18 -1
- data/lib/particle/platform.rb +16 -0
- data/lib/particle/response/parse_json_symbols.rb +4 -1
- data/lib/particle/version.rb +1 -1
- data/particlerb.gemspec +2 -1
- metadata +23 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3cd7821e357f56784da61e8a4153386b1dc37f8
|
4
|
+
data.tar.gz: 187b03c7a9f20f73f82bcf11c42ad41c0b0b20ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e186ccf65aaca73843e27aa03b71784577db8fb58bc6e330ca056eb6c710f72f1ac53a5a663e153b4f9e1b0c81b803520c266f11b896b2aea916f6fffe74b38
|
7
|
+
data.tar.gz: a932cd5ff45d59b23994ad3afd50e700dc5ff21c7881d9b61739063ad0efe5eeda826e914e92d590593dc5eec806d693c6cbd735ba77cf3e62e63ec02847153d
|
data/README.md
CHANGED
@@ -67,7 +67,7 @@ When using this gem in a multi-threaded program like a Rails application running
|
|
67
67
|
|
68
68
|
## Interacting with devices
|
69
69
|
|
70
|
-
List all devices.
|
70
|
+
List all devices. Returns an `Array` of `Particle::Device`.
|
71
71
|
|
72
72
|
```ruby
|
73
73
|
devices = Particle.devices
|
@@ -151,6 +151,13 @@ Change the product id. The meaning of the product id is specific to your applica
|
|
151
151
|
Particle.device('f8bbe1e6e69e05c9c405ba1ca504d438061f1b0d').change_product(3)
|
152
152
|
```
|
153
153
|
|
154
|
+
Update the public key for a device. The public key must be in PEM format. See <spec/fixtures/device.pub.pem> for an example.
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
public_key = IO.read('device.pub.pem')
|
158
|
+
Particle.device('f8bbe1e6e69e05c9c405ba1ca504d438061f1b0d').update_public_key(public_key, algorithm: 'rsa')
|
159
|
+
```
|
160
|
+
|
154
161
|
See the [Particle Cloud API documentation about devices][device docs] for more details.
|
155
162
|
|
156
163
|
[device docs]: http://docs.particle.io/core/api/#introduction-device-information
|
data/Rakefile
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'particle/model'
|
2
|
+
module Particle
|
3
|
+
# Domain model for one Particle Build Target, underlying http api json looks like
|
4
|
+
# {
|
5
|
+
# "platforms": [
|
6
|
+
# 0,
|
7
|
+
# 8,
|
8
|
+
# 6,
|
9
|
+
# 10
|
10
|
+
# ],
|
11
|
+
# "prereleases": [
|
12
|
+
# 0,
|
13
|
+
# 8,
|
14
|
+
# 6,
|
15
|
+
# 10
|
16
|
+
# ],
|
17
|
+
# "firmware_vendor": "Particle",
|
18
|
+
# "version": "0.6.0-rc.2"
|
19
|
+
# },
|
20
|
+
class BuildTarget < Model
|
21
|
+
def initialize(client, attributes)
|
22
|
+
super(client, attributes)
|
23
|
+
end
|
24
|
+
attribute_reader :platforms, :prereleases, :firmware_vendor, :version
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'particle/build_target'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Particle
|
5
|
+
class Client
|
6
|
+
module BuildTargets
|
7
|
+
HTTP_PATH = "v1/build_targets"
|
8
|
+
# List all available Particle cloud compile build targets
|
9
|
+
#
|
10
|
+
# @return [Array<BuildTarget>] List of Particle Build Targets you can compile sources with
|
11
|
+
def build_targets
|
12
|
+
get(HTTP_PATH)[:targets].map do |target_h|
|
13
|
+
BuildTarget.new(self, target_h)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def build_target(attributes)
|
18
|
+
if attributes.is_a? BuildTarget
|
19
|
+
attributes
|
20
|
+
else
|
21
|
+
BuildTarget.new(self, attributes)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -118,6 +118,22 @@ module Particle
|
|
118
118
|
end
|
119
119
|
result[:ok]
|
120
120
|
end
|
121
|
+
|
122
|
+
# Update the public key for a device you own
|
123
|
+
#
|
124
|
+
# @param target [String, Device] A device id, name or {Device} object
|
125
|
+
# @param public_key [String] The public key in PEM format (default
|
126
|
+
# format generated by openssl)
|
127
|
+
# @param algorithm [String] The encryption algorithm for the key
|
128
|
+
# (default rsa)
|
129
|
+
# @return [boolean] true when successful
|
130
|
+
def update_device_public_key(target, public_key, algorithm = 'rsa')
|
131
|
+
result = post(Device.provision_path,
|
132
|
+
deviceID: device(target).id,
|
133
|
+
publicKey: public_key,
|
134
|
+
algorithm: algorithm)
|
135
|
+
!result.empty?
|
136
|
+
end
|
121
137
|
end
|
122
138
|
end
|
123
139
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'particle/platform'
|
2
|
+
require 'particle/client/build_targets'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Particle
|
6
|
+
class Client
|
7
|
+
module Platforms
|
8
|
+
# List all available Particle Hardware platforms that you can use the cloud compiler with
|
9
|
+
#
|
10
|
+
# @return [Array<Platform>] List of Particle Hardware platforms that have build targets you can compile sources with
|
11
|
+
def platforms
|
12
|
+
@platforms = []
|
13
|
+
get(Particle::Client::BuildTargets::HTTP_PATH)[:platforms].each_pair do |platform_name, platform_id|
|
14
|
+
@platforms << Platform.new(self, {name: platform_name, id: platform_id})
|
15
|
+
end
|
16
|
+
@platforms
|
17
|
+
end
|
18
|
+
|
19
|
+
def platform(attributes)
|
20
|
+
if attributes.is_a? Platform
|
21
|
+
attributes
|
22
|
+
else
|
23
|
+
Platform.new(self, attributes)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/particle/client.rb
CHANGED
@@ -4,6 +4,8 @@ require 'particle/client/publish'
|
|
4
4
|
require 'particle/client/webhooks'
|
5
5
|
require 'particle/client/tokens'
|
6
6
|
require 'particle/client/firmware'
|
7
|
+
require 'particle/client/build_targets'
|
8
|
+
require 'particle/client/platforms'
|
7
9
|
|
8
10
|
module Particle
|
9
11
|
|
@@ -18,6 +20,8 @@ module Particle
|
|
18
20
|
include Particle::Client::Webhooks
|
19
21
|
include Particle::Client::Tokens
|
20
22
|
include Particle::Client::Firmware
|
23
|
+
include Particle::Client::BuildTargets
|
24
|
+
include Particle::Client::Platforms
|
21
25
|
|
22
26
|
def initialize(options = {})
|
23
27
|
# Use options passed in, but fall back to module defaults
|
data/lib/particle/device.rb
CHANGED
@@ -7,7 +7,9 @@ module Particle
|
|
7
7
|
ID_REGEX = /\h{24}/
|
8
8
|
PRODUCT_IDS = {
|
9
9
|
0 => "Core".freeze,
|
10
|
-
6 => "Photon".freeze
|
10
|
+
6 => "Photon".freeze,
|
11
|
+
8 => "P1".freeze,
|
12
|
+
10 => "Electron".freeze
|
11
13
|
}
|
12
14
|
|
13
15
|
def initialize(client, attributes)
|
@@ -161,6 +163,17 @@ module Particle
|
|
161
163
|
@client.change_device_product(self, product_id, should_update)
|
162
164
|
end
|
163
165
|
|
166
|
+
# Update the public key for a device you own
|
167
|
+
#
|
168
|
+
# @param public_key [String] The public key in PEM format (default
|
169
|
+
# format generated by openssl)
|
170
|
+
# @param algorithm [String] The encryption algorithm for the key
|
171
|
+
# (default rsa)
|
172
|
+
# @return [boolean] true when successful
|
173
|
+
def update_public_key(public_key, algorithm = 'rsa')
|
174
|
+
@client.update_device_public_key(self, public_key, algorithm)
|
175
|
+
end
|
176
|
+
|
164
177
|
def self.list_path
|
165
178
|
"v1/devices"
|
166
179
|
end
|
@@ -169,6 +182,10 @@ module Particle
|
|
169
182
|
"v1/devices"
|
170
183
|
end
|
171
184
|
|
185
|
+
def self.provision_path
|
186
|
+
"v1/provisioning/x"
|
187
|
+
end
|
188
|
+
|
172
189
|
def path
|
173
190
|
"/v1/devices/#{id_or_name}"
|
174
191
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'particle/model'
|
2
|
+
module Particle
|
3
|
+
# Domain model for one Particle Platform from the /v1/build_targets endpoint
|
4
|
+
class Platform < Model
|
5
|
+
def initialize(client, attributes)
|
6
|
+
super(client, attributes)
|
7
|
+
end
|
8
|
+
attribute_reader :name, :id
|
9
|
+
|
10
|
+
# This avoids upstream magic from making .name a Symbol--keep it a string yo
|
11
|
+
def name
|
12
|
+
@attributes[:name].to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -11,7 +11,10 @@ module Particle
|
|
11
11
|
end
|
12
12
|
|
13
13
|
define_parser do |body|
|
14
|
-
|
14
|
+
body = body.strip
|
15
|
+
# Workaround for body returned as a quoted string
|
16
|
+
body = "[#{body}]" if body.match(/^".*"$/)
|
17
|
+
::JSON.parse(body, symbolize_names: true) unless body.empty?
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
data/lib/particle/version.rb
CHANGED
data/particlerb.gemspec
CHANGED
@@ -21,10 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'faraday_middleware', '>= 0.9.0'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'guard-rspec', '~> 4.5'
|
24
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.5.0'
|
25
25
|
spec.add_development_dependency 'pry', '~> 0.10'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
27
|
spec.add_development_dependency 'rspec-pride', '~> 3.1'
|
28
|
+
spec.add_development_dependency 'listen', '~> 3.0.8'
|
28
29
|
spec.add_development_dependency 'vcr', '~> 2.9'
|
29
30
|
spec.add_development_dependency 'webmock', '~> 1.21'
|
30
31
|
spec.add_development_dependency 'multi_json', '~> 1.11'
|
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.
|
4
|
+
version: 1.2.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:
|
11
|
+
date: 2016-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 4.5.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 4.5.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: listen
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.8
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.0.8
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: vcr
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,9 +203,12 @@ files:
|
|
189
203
|
- README.md
|
190
204
|
- Rakefile
|
191
205
|
- lib/particle.rb
|
206
|
+
- lib/particle/build_target.rb
|
192
207
|
- lib/particle/client.rb
|
208
|
+
- lib/particle/client/build_targets.rb
|
193
209
|
- lib/particle/client/devices.rb
|
194
210
|
- lib/particle/client/firmware.rb
|
211
|
+
- lib/particle/client/platforms.rb
|
195
212
|
- lib/particle/client/publish.rb
|
196
213
|
- lib/particle/client/tokens.rb
|
197
214
|
- lib/particle/client/webhooks.rb
|
@@ -201,6 +218,7 @@ files:
|
|
201
218
|
- lib/particle/device.rb
|
202
219
|
- lib/particle/error.rb
|
203
220
|
- lib/particle/model.rb
|
221
|
+
- lib/particle/platform.rb
|
204
222
|
- lib/particle/response/parse_json_symbols.rb
|
205
223
|
- lib/particle/response/raise_error.rb
|
206
224
|
- lib/particle/token.rb
|
@@ -228,9 +246,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
246
|
version: 1.3.5
|
229
247
|
requirements: []
|
230
248
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.
|
249
|
+
rubygems_version: 2.2.5
|
232
250
|
signing_key:
|
233
251
|
specification_version: 4
|
234
252
|
summary: Ruby client for the Particle.io Cloud API
|
235
253
|
test_files: []
|
236
|
-
has_rdoc:
|