xively_api_client 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xively_api_client.rb +27 -13
- data/lib/xively_api_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b46ad248025242802ead6faf3877446d12da3418
|
4
|
+
data.tar.gz: 3f4fc2793a0be9164b2ea518e8d10a8e51a41109
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db64196b09aa3c90aa5e2a967997ee072496355ac993f4016d88797c9c7feb5e0fb21b8a70abd9bb11b53212f2033c8f22bacc20d223ee3f0de654e83e02b615
|
7
|
+
data.tar.gz: 51462e317806b71a2240e40dc8fff8c00da3f0ee59545ac4eca90427928b614f9e50616578737298eb85b038f18a23a50a3a00f438790d64d95eb800473c474a
|
data/lib/xively_api_client.rb
CHANGED
@@ -13,18 +13,35 @@ module XivelyApiClient
|
|
13
13
|
@pass = args[:pass] || ENV['XIVELY_PASS']
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
json_parse(
|
16
|
+
def index_devices
|
17
|
+
json_parse(get device_url)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
|
20
|
+
def show_device serial_id
|
21
|
+
response = get device_url serial_id
|
22
|
+
json_parse(response).first
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
json_parse(
|
25
|
+
def create_device serial_id, options = {}
|
26
|
+
json_parse(post(build_json serial_id, options)).first
|
26
27
|
end
|
27
28
|
|
29
|
+
# Not implemented in API? Or only can change "batch_id": and "device_secret":
|
30
|
+
|
31
|
+
# def update_device serial_id, options = {}
|
32
|
+
# device = show_device serial_id
|
33
|
+
# unless (device)
|
34
|
+
# json_parse put(device.to_json).first
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
|
38
|
+
# def put body
|
39
|
+
# HTTParty.put device_url,
|
40
|
+
# :body => body,
|
41
|
+
# :basic_auth => credentials,
|
42
|
+
# :headers => {'Content-Type' => 'application/json'}
|
43
|
+
# end
|
44
|
+
|
28
45
|
def destroy_device serial
|
29
46
|
delete device_url(serial)
|
30
47
|
end
|
@@ -32,7 +49,7 @@ module XivelyApiClient
|
|
32
49
|
private
|
33
50
|
|
34
51
|
def json_parse response
|
35
|
-
JSON.parse(response.body)["devices"]
|
52
|
+
JSON.parse(response.body)["devices"] || []
|
36
53
|
end
|
37
54
|
|
38
55
|
def get url
|
@@ -47,21 +64,18 @@ module XivelyApiClient
|
|
47
64
|
end
|
48
65
|
|
49
66
|
def delete url
|
50
|
-
HTTParty.delete url,
|
51
|
-
:basic_auth => credentials
|
67
|
+
HTTParty.delete url, :basic_auth => credentials
|
52
68
|
end
|
53
69
|
|
54
70
|
def device_url serial = nil
|
55
|
-
url = "https://v3api.xively.com/v3/service_instances/#{ instance }/domains/#{ domain }/devices"
|
56
|
-
url += "/#{ serial }" if serial
|
57
|
-
url
|
71
|
+
url = "https://v3api.xively.com/v3/service_instances/#{ instance }/domains/#{ domain }/devices/#{serial}"
|
58
72
|
end
|
59
73
|
|
60
74
|
def credentials
|
61
75
|
{ username: @user, password: @pass }
|
62
76
|
end
|
63
77
|
|
64
|
-
def
|
78
|
+
def build_json serial_id, options = {}
|
65
79
|
queues = options[:queues] || []
|
66
80
|
batch_id = options[:batch_id] || "2ndnozefwvbsi"
|
67
81
|
{ devices:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xively_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Piccioni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|