particlerb 2.0.1 → 2.1.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: 3e47a80d3ac0cf078c7ab6dbed9d51d43b358b86
4
- data.tar.gz: 0fc684e9ceab97b19963e6c37355118de83c3f8a
3
+ metadata.gz: c8d676bf83ca70ca5e701afb4eff415f1c768981
4
+ data.tar.gz: 4b8faa90e8b02f5936a3aed3fdeb227cc02cbfaa
5
5
  SHA512:
6
- metadata.gz: 1f42701237bd5892ad1dad5c7db4f49c08b8c674d853012ef66badb63772871a6a997cb5addd0b99ac59547c680167d5fbf17e563a36209c9af53421bb54741b
7
- data.tar.gz: 3db3e108fa95fb4907a5ba36882163d085f957ad8da4aba8f6de2105f03d6f85f1ff228dd91e7cadb6634747fad9d5eda57b7baa42856d1f87d95336e4fcf94c
6
+ metadata.gz: c4f1feafd07b21c8c13e8e0b2213a0c7566f65666ed2e100b5052967fce328ea94c94c094e763de23b6405a722ab65b0afd24805de0e519d3fc70d63d5a2efb5
7
+ data.tar.gz: d69ec8dc13460c18ed5daba6e311af0f749a879e36a6c3ee47a9b20758d92770614546df6303f473f173c28d847c72ae84ef242cae50947e475c6cd309fa7b71
@@ -33,8 +33,38 @@ module Particle
33
33
  def product_attributes(target)
34
34
  response_body = get(product(target).path)
35
35
 
36
- response_body[:product].first
36
+ # originally returned as an array, now seems to just return the 1 product as a hash;
37
+ # this will handle both cases
38
+ product = response_body[:product]
39
+ product = product.first if product.is_a?(Array)
40
+ product
41
+ end
42
+
43
+ # List all Particle product devices on the account
44
+ #
45
+ # @return [Array<Device>] List of Particle product devices to interact with
46
+ def get_devices(target)
47
+ response_body = get(product(target).devices_path)
48
+ (response_body[:devices]).map { |attributes| device(attributes) }
49
+ end
50
+
51
+ # Add device to Particle product on the account
52
+ #
53
+ # @param product [Product] A product to interact with
54
+ # @param device_id [String] A device id
55
+ # @return [Hash] JSON response as a hash
56
+ def add_device(product:, device_id:)
57
+ post(product.add_device_path, id: device_id)
58
+ end
59
+
60
+ # Remove device from a Particle product on the account
61
+ #
62
+ # @param product [Product] A product to interact with
63
+ # @param device_id [String] A device id
64
+ # @return [Hash] JSON response as a hash
65
+ def remove_product_device(product:, device_id:)
66
+ delete(product.remove_device_path(device_id))
37
67
  end
38
68
  end
39
69
  end
40
- end
70
+ end
@@ -25,13 +25,35 @@ module Particle
25
25
  end
26
26
 
27
27
  attribute_reader :name, :description, :platform_id, :type, :hardware_version,
28
- :config_id, :organization
28
+ :config_id,
29
+ # below here are new attributes that appeared with API change
30
+ :subscription_id, :mb_limit, :groups, :settings, :org
29
31
 
30
32
  def get_attributes
31
33
  @loaded = @fully_loaded = true
32
34
  @attributes = @client.product_attributes(self)
33
35
  end
34
36
 
37
+ def devices
38
+ @devices = @client.get_devices(id_or_slug)
39
+ end
40
+
41
+ # Add a Particle device to product on the account
42
+ #
43
+ # @example Add a device to Product
44
+ # product.add_device('12345')
45
+ def add_device(device_id)
46
+ @client.add_device(product: self, device_id: device_id)
47
+ end
48
+
49
+ # Remove a Particle device from a product on the account
50
+ #
51
+ # @example Remove a device from Product
52
+ # product.remove_device('12345')
53
+ def remove_device(device_id)
54
+ @client.remove_product_device(product: self, device_id: device_id)
55
+ end
56
+
35
57
  def firmware(target)
36
58
  @client.product_firmware(self, target)
37
59
  end
@@ -51,6 +73,11 @@ module Particle
51
73
  @attributes[:slug]
52
74
  end
53
75
 
76
+ def organization
77
+ get_attributes unless @attributes[:organization] || @attributes[:org]
78
+ @attributes[:organization] || @attributes[:org]
79
+ end
80
+
54
81
  def id_or_slug
55
82
  @attributes[:id] || @attributes[:slug]
56
83
  end
@@ -59,10 +86,22 @@ module Particle
59
86
  "v1/products"
60
87
  end
61
88
 
89
+ def add_device_path
90
+ "/v1/products/#{id_or_slug}/devices"
91
+ end
92
+
93
+ def remove_device_path(device_id)
94
+ "/v1/products/#{id_or_slug}/devices/#{device_id}"
95
+ end
96
+
62
97
  def path
63
98
  "/v1/products/#{id_or_slug}"
64
99
  end
65
100
 
101
+ def devices_path
102
+ "/v1/products/#{id_or_slug}/devices"
103
+ end
104
+
66
105
  def firmware_path(version)
67
106
  "/v1/products/#{id_or_slug}/firmware/#{version}"
68
107
  end
@@ -1,3 +1,3 @@
1
1
  module Particle
2
- VERSION = "2.0.1".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.version = Particle::VERSION.dup
20
20
  spec.add_dependency 'faraday', '>= 0.9.0'
21
21
  spec.add_dependency 'faraday_middleware', '>= 0.9.0'
22
- spec.add_development_dependency 'bundler', '~> 1.0'
22
+ spec.add_development_dependency 'bundler', '~> 2.0'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'guard-rspec', '~> 4.5.0'
25
25
  spec.add_development_dependency 'pry', '~> 0.10'
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: 2.0.1
4
+ version: 2.1.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: 2018-11-28 00:00:00.000000000 Z
11
+ date: 2019-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -268,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
268
  version: 1.3.5
269
269
  requirements: []
270
270
  rubyforge_project:
271
- rubygems_version: 2.5.1
271
+ rubygems_version: 2.6.13
272
272
  signing_key:
273
273
  specification_version: 4
274
274
  summary: Ruby client for the Particle.io Cloud API