wiot-sdk 0.1.2
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 +7 -0
- data/.gitignore +38 -0
- data/.travis.yml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +59 -0
- data/LICENSE +21 -0
- data/README.md +256 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/wiot-sdk/client.rb +28 -0
- data/lib/wiot-sdk/config/parser_json.rb +9 -0
- data/lib/wiot-sdk/config/parser_yml.rb +9 -0
- data/lib/wiot-sdk/data/error.rb +18 -0
- data/lib/wiot-sdk/data/errors.rb +23 -0
- data/lib/wiot-sdk/data/rate.rb +29 -0
- data/lib/wiot-sdk/metric.rb +17 -0
- data/lib/wiot-sdk/request.rb +37 -0
- data/lib/wiot-sdk/response.rb +42 -0
- data/lib/wiot-sdk/version.rb +3 -0
- data/lib/wiot-sdk.rb +18 -0
- data/wiot-sdk.gemspec +25 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d2eb71783d82d2813cf8909bf9f6ce4ac8f9591e
|
4
|
+
data.tar.gz: 6c9f22bcd220078cedd04bee1fa0ec2fef3a594f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e76ba9cd40b6272489993d3d4243fbf2003d08cd3a6b3c79c01cbe550355ccae900ef224bf2010c265cd7c9011482d1826ec08d367f965adffc7053263eb2464
|
7
|
+
data.tar.gz: 5ccb98d28134b8e1acd29fcbd2a12c7e232e262f97121d5accb9960053baa0f00ecdf23a3918559fba4b66f690749ecd8deb491505fd2b6d7f42bedb9c15370f
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
|
38
|
+
*.idea/*
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wiot-sdk (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
codeclimate-test-reporter (0.5.0)
|
10
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.5)
|
13
|
+
domain_name (0.5.20160310)
|
14
|
+
unf (>= 0.0.5, < 1.0.0)
|
15
|
+
http-cookie (1.0.2)
|
16
|
+
domain_name (~> 0.5)
|
17
|
+
json (1.8.3)
|
18
|
+
mime-types (2.99.1)
|
19
|
+
netrc (0.11.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rest-client (1.8.0)
|
22
|
+
http-cookie (>= 1.0.2, < 2.0)
|
23
|
+
mime-types (>= 1.16, < 3.0)
|
24
|
+
netrc (~> 0.7)
|
25
|
+
rspec (3.5.0)
|
26
|
+
rspec-core (~> 3.5.0)
|
27
|
+
rspec-expectations (~> 3.5.0)
|
28
|
+
rspec-mocks (~> 3.5.0)
|
29
|
+
rspec-core (3.5.4)
|
30
|
+
rspec-support (~> 3.5.0)
|
31
|
+
rspec-expectations (3.5.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.5.0)
|
34
|
+
rspec-mocks (3.5.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.5.0)
|
37
|
+
rspec-support (3.5.0)
|
38
|
+
simplecov (0.11.2)
|
39
|
+
docile (~> 1.1.0)
|
40
|
+
json (~> 1.8)
|
41
|
+
simplecov-html (~> 0.10.0)
|
42
|
+
simplecov-html (0.10.0)
|
43
|
+
unf (0.1.4)
|
44
|
+
unf_ext
|
45
|
+
unf_ext (0.0.7.2)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler (~> 1.11)
|
52
|
+
codeclimate-test-reporter
|
53
|
+
rake (~> 10.0)
|
54
|
+
rest-client (~> 1.8)
|
55
|
+
rspec (~> 3.0)
|
56
|
+
wiot-sdk!
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.13.7
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 watchiot
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,256 @@
|
|
1
|
+
[](https://waffle.io/watchiot/wiot-sdk-ruby)
|
2
|
+
[](https://travis-ci.org/watchiot/wiot-sdk-ruby) [](https://codeclimate.com/github/watchiot/wiot-sdk-ruby) [](https://codeclimate.com/github/watchiot/wiot-sdk-ruby/coverage) [](https://codeclimate.com/github/watchiot/wiot-sdk-ruby) [](https://badge.fury.io/rb/wiot_sdk)
|
3
|
+
|
4
|
+
# Watchiot SDK for Ruby
|
5
|
+
|
6
|
+
If you want to create an monitor agent in **Ruby** we suggest use this **gem**, it contains easy way to interact with our api.
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
```bash
|
11
|
+
$ gem install wiot-sdk
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
First you need to add the dependence in your *Gemfile* project
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'wiot-sdk', '~> 0.1'
|
20
|
+
```
|
21
|
+
|
22
|
+
Then you have to require the sdk where are you going to use it
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'wiot-sdk'
|
26
|
+
```
|
27
|
+
|
28
|
+
Now you have to initialice the **SDK** setting the mandatory configuration variables that always will be send in each request. This parameters are:
|
29
|
+
|
30
|
+
**api key**, **name space** and **name project**
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
def init_sdk
|
34
|
+
my_api_key = 'asd123asd-23asd-123sda-1231234saa'
|
35
|
+
my_namespace = 'my_space'
|
36
|
+
my_project = 'my_project'
|
37
|
+
|
38
|
+
client = WiotSdk.init my_api_key, my_namespace, my_project
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
The other way is put it into configuration file **yml** or **json** format and then set the path where this parameters are setting.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
def init_sdk
|
46
|
+
my_config_json = '/home/myhome/my_agent/my_agent.json'
|
47
|
+
|
48
|
+
client = WiotSdk.init my_config_json
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
def init_sdk
|
54
|
+
my_config_yml = '/home/myhome/my_agent/my_agent.yml'
|
55
|
+
|
56
|
+
client = WiotSdk.init my_config_yml
|
57
|
+
end
|
58
|
+
```
|
59
|
+
Example of config file
|
60
|
+
|
61
|
+
* json
|
62
|
+
```json
|
63
|
+
{
|
64
|
+
api_key: "asd123asd-23asd-123sda-1231234saa",
|
65
|
+
space : "my_space",
|
66
|
+
project: "my_project"
|
67
|
+
}
|
68
|
+
```
|
69
|
+
|
70
|
+
* yml
|
71
|
+
```yml
|
72
|
+
api_key: "asd123asd-23asd-123sda-1231234saa"
|
73
|
+
space : "my_space"
|
74
|
+
project: "my_project"
|
75
|
+
```
|
76
|
+
|
77
|
+
Now you are ready to send us a request with the metrics that you recollect.
|
78
|
+
|
79
|
+
To fill the **metric** we provide you a *Metric class*
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'wiot_sdk/metric'
|
83
|
+
|
84
|
+
def fill_metric
|
85
|
+
metric = Metric.new
|
86
|
+
|
87
|
+
metric.add('my_param1', 'my_malue1')
|
88
|
+
metric.add('my_param2', 'my_malue2')
|
89
|
+
metric.add('my_param3', 'my_malue3')
|
90
|
+
...
|
91
|
+
metric.add('my_paramN', 'my_malueN')
|
92
|
+
end
|
93
|
+
```
|
94
|
+
Whe you have the **metric** only you need send a **request** to us
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
|
98
|
+
def request
|
99
|
+
client = init_sdk
|
100
|
+
metric = fill_metric
|
101
|
+
|
102
|
+
response = client.send metric
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
* Response
|
107
|
+
|
108
|
+
If all was fine you are going to recive
|
109
|
+
|
110
|
+
```http
|
111
|
+
HTTP/1.1 200 OK
|
112
|
+
Server: nginx
|
113
|
+
Date: Fri, 16 Nov 2016 21:03:12 GMT
|
114
|
+
Content-Type: application/json; charset=utf-8
|
115
|
+
Connection: keep-alive
|
116
|
+
Status: 200 OK
|
117
|
+
Rate-Limit: 800
|
118
|
+
Rate-Remaining: 745
|
119
|
+
Rate-Reset: 2150085394
|
120
|
+
Content-Length: 5
|
121
|
+
```
|
122
|
+
```ruby
|
123
|
+
|
124
|
+
def request
|
125
|
+
client = init_sdk
|
126
|
+
metric = fill_metric
|
127
|
+
|
128
|
+
response = client.send metric
|
129
|
+
puts response.code
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
OUTPUT: 200
|
134
|
+
|
135
|
+
* Rate limit
|
136
|
+
|
137
|
+
Rate-Limit: 60 The maximum number of requests per hour.
|
138
|
+
Rate-Remaining: 56 The number of requests remaining in the current rate limit window.
|
139
|
+
Rate-Reset: 1372700873 The time at which the current rate limit window reset in miliseconds.
|
140
|
+
|
141
|
+
GET /rate_limit
|
142
|
+
|
143
|
+
Status: 200 OK
|
144
|
+
X-RateLimit-Limit: 5000
|
145
|
+
X-RateLimit-Remaining: 4999
|
146
|
+
X-RateLimit-Reset: 1372700873
|
147
|
+
|
148
|
+
{
|
149
|
+
"resources": {
|
150
|
+
"core": {
|
151
|
+
"limit": 5000,
|
152
|
+
"remaining": 4999,
|
153
|
+
"reset": 1372700873
|
154
|
+
},
|
155
|
+
"search": {
|
156
|
+
"limit": 30,
|
157
|
+
"remaining": 18,
|
158
|
+
"reset": 1372697452
|
159
|
+
}
|
160
|
+
},
|
161
|
+
"rate": {
|
162
|
+
"limit": 5000,
|
163
|
+
"remaining": 4999,
|
164
|
+
"reset": 1372700873
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
* Errors
|
170
|
+
|
171
|
+
Sending invalid JSON will result in a 400 Bad Request response.
|
172
|
+
|
173
|
+
HTTP/1.1 400 Bad Request
|
174
|
+
Content-Length: 35
|
175
|
+
|
176
|
+
{"message":"Problems parsing JSON"}
|
177
|
+
|
178
|
+
Sending the wrong type of JSON values will result in a 400 Bad Request response.
|
179
|
+
|
180
|
+
HTTP/1.1 400 Bad Request
|
181
|
+
Content-Length: 40
|
182
|
+
|
183
|
+
{"message":"Body should be a valid JSON"}
|
184
|
+
|
185
|
+
Sending invalid fields will result in a 422 Unprocessable Entity response.
|
186
|
+
|
187
|
+
HTTP/1.1 422 Unprocessable Entity
|
188
|
+
Content-Length: 149
|
189
|
+
|
190
|
+
{
|
191
|
+
"message": "Validation Failed",
|
192
|
+
"errors": [
|
193
|
+
{
|
194
|
+
"field": "title",
|
195
|
+
"code": "missing_field"
|
196
|
+
}
|
197
|
+
]
|
198
|
+
}
|
199
|
+
|
200
|
+
HTTP/1.1 401 Unauthorized
|
201
|
+
|
202
|
+
{
|
203
|
+
"message": "Bad credentials"
|
204
|
+
}
|
205
|
+
|
206
|
+
HTTP/1.1 403 Forbidden
|
207
|
+
Content-Type: application/json; charset=utf-8
|
208
|
+
Connection: close
|
209
|
+
|
210
|
+
{
|
211
|
+
"message": "You have been temporarily blocked for have an abuse behavior. Please retry your request more later."
|
212
|
+
}
|
213
|
+
|
214
|
+
HTTP/1.1 403 Forbidden
|
215
|
+
|
216
|
+
{
|
217
|
+
"message": "Maximum number of login attempts exceeded. Please try again later."
|
218
|
+
}
|
219
|
+
|
220
|
+
HTTP/1.1 403 Forbidden
|
221
|
+
Date: Tue, 20 Aug 2013 14:50:41 GMT
|
222
|
+
Status: 403 Forbidden
|
223
|
+
Rate-Limit: 800
|
224
|
+
Rate-Remaining: 0
|
225
|
+
Rate-Reset: 1377013266
|
226
|
+
|
227
|
+
{
|
228
|
+
"message": "API rate limit exceeded"
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
## License
|
233
|
+
|
234
|
+
(The MIT License)
|
235
|
+
|
236
|
+
Copyright (c) 2016 WatchIoT
|
237
|
+
|
238
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
239
|
+
a copy of this software and associated documentation files (the
|
240
|
+
'Software'), to deal in the Software without restriction, including
|
241
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
242
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
243
|
+
permit persons to whom the Software is furnished to do so, subject to
|
244
|
+
the following conditions:
|
245
|
+
|
246
|
+
The above copyright notice and this permission notice shall be
|
247
|
+
included in all copies or substantial portions of the Software.
|
248
|
+
|
249
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
250
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
251
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
252
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
253
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
254
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
255
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
256
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wiot-sdk"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'wiot-sdk/request'
|
2
|
+
require 'wiot-sdk/response'
|
3
|
+
|
4
|
+
require 'wiot-sdk/config/parser_yml'
|
5
|
+
require 'wiot-sdk/config/parser_json'
|
6
|
+
|
7
|
+
module WiotSdk
|
8
|
+
|
9
|
+
class Client
|
10
|
+
|
11
|
+
def self.init_yaml(file_path)
|
12
|
+
api_key, space, project = WiotSdk::Config::ParserYml.parser file_path
|
13
|
+
|
14
|
+
Request.new api_key, space, project
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.init_json(file_path)
|
18
|
+
api_key, space, project = WiotSdk::Config::ParserJson.parser file_path
|
19
|
+
|
20
|
+
Request.new api_key, space, project
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.init(api_key, space, project)
|
24
|
+
Request.new api_key, space, project
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module WiotSdk
|
2
|
+
module Data
|
3
|
+
class Errors
|
4
|
+
def initialize(body)
|
5
|
+
@errors = parser_errors body
|
6
|
+
end
|
7
|
+
|
8
|
+
def errors
|
9
|
+
@errors
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_errors?
|
13
|
+
!@errors.nil? && @errors.size > 0
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def parser_errors(body)
|
19
|
+
[]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WiotSdk
|
2
|
+
module Data
|
3
|
+
class Rate
|
4
|
+
def initialize(header)
|
5
|
+
parser_rate header
|
6
|
+
end
|
7
|
+
|
8
|
+
def rate_limit
|
9
|
+
@rate_limit
|
10
|
+
end
|
11
|
+
|
12
|
+
def rate_remaining
|
13
|
+
@rate_remaining
|
14
|
+
end
|
15
|
+
|
16
|
+
def rate_reset
|
17
|
+
@rate_reset
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parser_rate(header)
|
23
|
+
@rate_limit = ''
|
24
|
+
@rate_remaining = ''
|
25
|
+
@rate_reset = ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require_relative 'metric'
|
5
|
+
require_relative 'response'
|
6
|
+
|
7
|
+
module WiotSdk
|
8
|
+
|
9
|
+
class Request
|
10
|
+
|
11
|
+
BASE_URL = 'http://api.watchiot.org/'
|
12
|
+
|
13
|
+
def initialize(api_key, space, project)
|
14
|
+
@api_key = api_key
|
15
|
+
@space = space
|
16
|
+
@project = project
|
17
|
+
end
|
18
|
+
|
19
|
+
def send(metric)
|
20
|
+
uri = BASE_URL + @space + '/' + @project
|
21
|
+
payload = '{ api: ' + @api_key + ', data: { ' + JSON.generate(metric.values).to_s + '}'
|
22
|
+
|
23
|
+
req uri, payload
|
24
|
+
rescue => ex
|
25
|
+
Response.new nil, 500, ex.message
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def req(url, payload)
|
31
|
+
response = RestClient.post url, payload, content_type: 'json', accept: 'json'
|
32
|
+
|
33
|
+
Response.new response
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'wiot-sdk/data/errors'
|
2
|
+
require 'wiot-sdk/data/rate'
|
3
|
+
|
4
|
+
module WiotSdk
|
5
|
+
|
6
|
+
class Response
|
7
|
+
def initialize(response, code = nil, message = nil)
|
8
|
+
@code = code || response.code
|
9
|
+
@rate = Rate.new response.headers
|
10
|
+
|
11
|
+
@message = message || parser_message(response.body)
|
12
|
+
@errors = Errors.new response.body
|
13
|
+
end
|
14
|
+
|
15
|
+
def code
|
16
|
+
@code
|
17
|
+
end
|
18
|
+
|
19
|
+
def rate
|
20
|
+
@rate
|
21
|
+
end
|
22
|
+
|
23
|
+
def message
|
24
|
+
@message
|
25
|
+
end
|
26
|
+
|
27
|
+
def errors
|
28
|
+
@errors
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_errors?
|
32
|
+
!@errors.nil? && @errors.has_errors?
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def parser_message(body)
|
38
|
+
body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/wiot-sdk.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'wiot-sdk/client'
|
2
|
+
require 'wiot-sdk/metric'
|
3
|
+
|
4
|
+
module WiotSdk
|
5
|
+
|
6
|
+
def self.init(api_key, space, project)
|
7
|
+
Client.init api_key, space, project
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.init_yaml(file_path)
|
11
|
+
Client.init_yaml file_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.init_json(file_path)
|
15
|
+
Client.init_json file_path
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/wiot-sdk.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wiot-sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wiot-sdk'
|
8
|
+
spec.version = WiotSdk::VERSION
|
9
|
+
spec.authors = ['watchiot']
|
10
|
+
spec.email = ['dev@watchiot.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Watchiot SDK}
|
13
|
+
spec.description = %q{Watchiot SDK is for agent}
|
14
|
+
spec.homepage = 'http://www.watchiot.com'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wiot-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- watchiot
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Watchiot SDK is for agent
|
56
|
+
email:
|
57
|
+
- dev@watchiot.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/wiot-sdk.rb
|
72
|
+
- lib/wiot-sdk/client.rb
|
73
|
+
- lib/wiot-sdk/config/parser_json.rb
|
74
|
+
- lib/wiot-sdk/config/parser_yml.rb
|
75
|
+
- lib/wiot-sdk/data/error.rb
|
76
|
+
- lib/wiot-sdk/data/errors.rb
|
77
|
+
- lib/wiot-sdk/data/rate.rb
|
78
|
+
- lib/wiot-sdk/metric.rb
|
79
|
+
- lib/wiot-sdk/request.rb
|
80
|
+
- lib/wiot-sdk/response.rb
|
81
|
+
- lib/wiot-sdk/version.rb
|
82
|
+
- wiot-sdk.gemspec
|
83
|
+
homepage: http://www.watchiot.com
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.1
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Watchiot SDK
|
107
|
+
test_files: []
|