mind_meld 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mind_meld.rb +21 -4
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13ae17c7093f501ad16fa54a99df2dcd562c4ab0
4
- data.tar.gz: 80bd36c4a5bff8c6ea9b2b989877a81463b2453e
3
+ metadata.gz: 0fe211ad4268bb53b8a771ed82114bc972271c98
4
+ data.tar.gz: b7327391f6e01965d041c19640f4ff684c9170d5
5
5
  SHA512:
6
- metadata.gz: 6b668822f7c8ddf8f8771bfc61776b4f8b10863d595db9ae609d8863693d447d027fa58853f73dc5f86100eca7da3a31f2dca314db1cfeaee42944db51af72f0
7
- data.tar.gz: 67369ec7b26d29366670b1311905f83f3899672465f5566b41ef5a0a1f8e7cdee3c08651e270c326dd8daf90b7f94af4ddf4684aea7cac0f79c9c5d9f9efae6f
6
+ metadata.gz: 1eba3450bd2aa1df39a956750af398fd9f495390ec6599dbfa368935ea6f5c7e698368f475197601fbc3a879d3fa323dcc4274eebd29c1318047c08243be3735
7
+ data.tar.gz: 77921f3f2c0613233de2e2c5b2e45d937bf1e5922e7fa1ae7981e37beb49e16453ec145983986fa647880b7f5e4a68e78dd01ab808e435d6efe85eb929a08b1d
data/lib/mind_meld.rb CHANGED
@@ -7,19 +7,36 @@ class MindMeld
7
7
  if options[:url]
8
8
  uri = URI.parse(options[:url])
9
9
  @http = Net::HTTP.new(uri.host, uri.port)
10
+
11
+ @device = options[:device]
12
+
13
+ # To initialize @id (is this needed?)
14
+ self.id
10
15
  end
11
16
  end
12
17
 
18
+ def id
19
+ @id ||= register(@device)['id']
20
+ end
21
+
13
22
  def register options
14
- post 'devices/register', { device: options }
23
+ request :post, 'devices/register', { device: options }
24
+ end
25
+
26
+ def poll *dev_ids
27
+ args = {
28
+ poll: dev_ids.length > 0 ? { id: self.id, devices: dev_ids } : { id: self.id }
29
+ }
30
+ puts args
31
+ request :put, 'devices/poll', args
15
32
  end
16
33
 
17
34
  private
18
- def post call, params = {}
35
+ def request type, call, params = {}
19
36
  if @http
20
37
  begin
21
- JSON.parse(@http.request_post("/api/#{call}.json", params.to_query).body)
22
- rescue StandardError => e
38
+ JSON.parse(@http.send("request_#{type}", "/api/#{call}.json", params.to_query).body)
39
+ rescue => e
23
40
  puts e.message
24
41
  { error: e.message }
25
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mind_meld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Haig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport