ninja_blocks 0.0.4 → 0.0.5
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.
data/lib/ninja_blocks.rb
CHANGED
@@ -8,11 +8,11 @@ require 'chronic'
|
|
8
8
|
|
9
9
|
require "ninja_blocks/version"
|
10
10
|
module NinjaBlocks
|
11
|
-
require 'ninja_blocks/
|
11
|
+
require 'ninja_blocks/base'
|
12
12
|
require 'ninja_blocks/device'
|
13
13
|
require 'ninja_blocks/user'
|
14
14
|
require 'ninja_blocks/rule'
|
15
|
-
|
15
|
+
|
16
16
|
def self.token
|
17
17
|
@token
|
18
18
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module NinjaBlocks
|
2
|
-
class
|
2
|
+
class Base
|
3
3
|
def get(url)
|
4
4
|
execute(:get,url)
|
5
5
|
end
|
@@ -29,6 +29,7 @@ module NinjaBlocks
|
|
29
29
|
response = connection.send(method,"#{url}?user_access_token=#{self.token}")
|
30
30
|
JSON.parse(response.body)
|
31
31
|
end
|
32
|
+
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
data/lib/ninja_blocks/device.rb
CHANGED
@@ -1,20 +1,71 @@
|
|
1
1
|
module NinjaBlocks
|
2
|
-
class Device <
|
2
|
+
class Device < Base
|
3
3
|
|
4
|
-
def list
|
4
|
+
def list(*filter_by)
|
5
|
+
|
5
6
|
hash_of_response = get("https://api.ninja.is/rest/v0/devices")
|
6
7
|
|
7
8
|
devices = []
|
9
|
+
|
10
|
+
unless filter_by.nil?
|
8
11
|
|
12
|
+
hash_of_response["data"].each do |d|
|
13
|
+
device_hash = {}
|
14
|
+
device_hash["guid"] = d[0]
|
15
|
+
device_hash = device_hash.merge(d[1])
|
16
|
+
devices << device_hash
|
17
|
+
devices = devices.reject { |d| d['device_type'] != filter_by[:device_type] }
|
18
|
+
end
|
19
|
+
|
20
|
+
else
|
21
|
+
hash_of_response["data"].each do |d|
|
22
|
+
device_hash = {}
|
23
|
+
device_hash["guid"] = d[0]
|
24
|
+
device_hash = device_hash.merge(d[1])
|
25
|
+
devices << device_hash
|
26
|
+
devices = devices.sort_by { |k| k["device_type"] }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
devices
|
32
|
+
end
|
33
|
+
|
34
|
+
def available_types
|
35
|
+
hash_of_response = get("https://api.ninja.is/rest/v0/devices")
|
36
|
+
|
37
|
+
devices_types = []
|
38
|
+
|
9
39
|
hash_of_response["data"].each do |d|
|
10
40
|
device_hash = {}
|
11
41
|
device_hash["guid"] = d[0]
|
12
42
|
device_hash = device_hash.merge(d[1])
|
13
|
-
|
43
|
+
devices_types << device_hash['device_type'] unless device_hash['device_type'].nil?
|
44
|
+
devices_types = devices_types.uniq
|
45
|
+
end
|
46
|
+
|
47
|
+
devices_types.each do |t|
|
48
|
+
puts t
|
14
49
|
end
|
15
|
-
|
16
|
-
devices
|
17
50
|
end
|
51
|
+
|
52
|
+
def available_devices
|
53
|
+
hash_of_response = get("https://api.ninja.is/rest/v0/devices")
|
54
|
+
|
55
|
+
devices_types = []
|
56
|
+
|
57
|
+
hash_of_response["data"].each do |d|
|
58
|
+
device_hash = {}
|
59
|
+
device_hash["guid"] = d[0]
|
60
|
+
device_hash = device_hash.merge(d[1])
|
61
|
+
devices_types << device_hash['device_type'] unless device_hash['device_type'].nil?
|
62
|
+
devices_types = devices_types.uniq
|
63
|
+
end
|
64
|
+
|
65
|
+
devices_types.each do |t|
|
66
|
+
puts t
|
67
|
+
end
|
68
|
+
end
|
18
69
|
|
19
70
|
def actuate(guid, da)
|
20
71
|
json = JSON.dump('DA'=> dsa)
|
@@ -31,6 +82,8 @@ module NinjaBlocks
|
|
31
82
|
end
|
32
83
|
|
33
84
|
def data(guid, from, to)
|
85
|
+
from = Chronic.parse(from).to_i
|
86
|
+
to = Chronic.parse(to).to_i
|
34
87
|
get("https://api.ninja.is/rest/v0/device/#{guid}/data?from=#{from}&to=#{to}")
|
35
88
|
end
|
36
89
|
|
data/lib/ninja_blocks/rule.rb
CHANGED
data/lib/ninja_blocks/user.rb
CHANGED
data/lib/ninja_blocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ninja_blocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -85,7 +85,7 @@ files:
|
|
85
85
|
- README.md
|
86
86
|
- example/app.rb
|
87
87
|
- lib/ninja_blocks.rb
|
88
|
-
- lib/ninja_blocks/
|
88
|
+
- lib/ninja_blocks/base.rb
|
89
89
|
- lib/ninja_blocks/device.rb
|
90
90
|
- lib/ninja_blocks/rule.rb
|
91
91
|
- lib/ninja_blocks/user.rb
|