wiot-sdk 0.1.2 → 0.1.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/wiot-sdk/client.rb +8 -8
- data/lib/wiot-sdk/payload.rb +20 -0
- data/lib/wiot-sdk/request.rb +12 -10
- data/lib/wiot-sdk/response.rb +21 -19
- data/lib/wiot-sdk/version.rb +1 -1
- data/lib/wiot-sdk.rb +10 -7
- metadata +3 -6
- data/lib/wiot-sdk/data/error.rb +0 -18
- data/lib/wiot-sdk/data/errors.rb +0 -23
- data/lib/wiot-sdk/data/rate.rb +0 -29
- data/lib/wiot-sdk/metric.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64f41d47a05c9fac883320334b45cb4a006c5195
|
4
|
+
data.tar.gz: 02dec3deb466eb2e3fbfc4b0e9f43eb1ffedfdae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78bc57cbb137ecaced9a56466c14db04fd4b58dbc9e6f26fc99757fb5be8bd33c00be0bea5040e6ef059372d3efb70f09956acd7674cf8aa7372ecd5c5f7b6b9
|
7
|
+
data.tar.gz: bb3fa4ed3086ab801085371de0645a45d6ccfdaaccdf221b53aa32e191ed76cc63b0526b6c1f23586055fd6c28ca494e7c001185b229ceb41f953c0f497a658c
|
data/Gemfile.lock
CHANGED
data/lib/wiot-sdk/client.rb
CHANGED
@@ -8,20 +8,20 @@ module WiotSdk
|
|
8
8
|
|
9
9
|
class Client
|
10
10
|
|
11
|
-
def self.init_yaml(file_path)
|
12
|
-
api_key, space, project = WiotSdk::Config::ParserYml.parser file_path
|
11
|
+
def self.init_yaml(file_path, base_url)
|
12
|
+
username, api_key, space, project = WiotSdk::Config::ParserYml.parser file_path
|
13
13
|
|
14
|
-
Request.new api_key, space, project
|
14
|
+
Request.new username, api_key, space, project, base_url
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.init_json(file_path)
|
18
|
-
api_key, space, project = WiotSdk::Config::ParserJson.parser file_path
|
17
|
+
def self.init_json(file_path, base_url)
|
18
|
+
username, api_key, space, project = WiotSdk::Config::ParserJson.parser file_path
|
19
19
|
|
20
|
-
Request.new api_key, space, project
|
20
|
+
Request.new username, api_key, space, project, base_url
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.init(api_key, space, project)
|
24
|
-
Request.new api_key, space, project
|
23
|
+
def self.init(username, api_key, space, project, base_url)
|
24
|
+
Request.new username, api_key, space, project, base_url
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module WiotSdk
|
4
|
+
|
5
|
+
class Payload
|
6
|
+
def initialize
|
7
|
+
@metric = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def addMetric(key, value)
|
11
|
+
@metric[key] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
payload = { metrics: @metric }
|
16
|
+
payload.to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/wiot-sdk/request.rb
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
require_relative 'payload'
|
5
5
|
require_relative 'response'
|
6
6
|
|
7
7
|
module WiotSdk
|
8
8
|
|
9
9
|
class Request
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
def initialize(api_key, space, project)
|
11
|
+
def initialize(username, api_key, space, project, base_url)
|
12
|
+
@username = username
|
14
13
|
@api_key = api_key
|
15
14
|
@space = space
|
16
15
|
@project = project
|
16
|
+
@base_url = base_url
|
17
17
|
end
|
18
18
|
|
19
|
-
def send(
|
20
|
-
uri =
|
21
|
-
payload = '{ api: ' + @api_key + ', data: { ' + JSON.generate(metric.values).to_s + '}'
|
19
|
+
def send(payload)
|
20
|
+
uri = @base_url + '/' + @space + '/' + @project
|
22
21
|
|
23
|
-
req uri, payload
|
22
|
+
req uri, payload.to_s
|
24
23
|
rescue => ex
|
25
|
-
Response.new
|
24
|
+
Response.new ex.response
|
26
25
|
end
|
27
26
|
|
28
27
|
private
|
29
28
|
|
30
29
|
def req(url, payload)
|
31
|
-
response = RestClient.post url, payload,
|
30
|
+
response = RestClient.post url, payload,
|
31
|
+
Authorization: "#{@username} #{@api_key}",
|
32
|
+
content_type: 'json',
|
33
|
+
accept: 'json'
|
32
34
|
|
33
35
|
Response.new response
|
34
36
|
end
|
data/lib/wiot-sdk/response.rb
CHANGED
@@ -1,41 +1,43 @@
|
|
1
|
-
require '
|
2
|
-
require 'wiot-sdk/data/rate'
|
1
|
+
require 'json'
|
3
2
|
|
4
3
|
module WiotSdk
|
5
4
|
|
6
5
|
class Response
|
7
|
-
def initialize(response
|
8
|
-
@
|
9
|
-
@rate = Rate.new response.headers
|
6
|
+
def initialize(response)
|
7
|
+
@rate_limit = parse_rate response.headers
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
response = JSON.parse(JSON.parse(response, :quirks_mode => true))
|
10
|
+
|
11
|
+
@code = response['code']
|
12
|
+
@msg = response['msg']
|
13
|
+
@error = response['error'] || nil
|
13
14
|
end
|
14
15
|
|
15
16
|
def code
|
16
17
|
@code
|
17
18
|
end
|
18
19
|
|
19
|
-
def
|
20
|
-
@
|
21
|
-
end
|
22
|
-
|
23
|
-
def message
|
24
|
-
@message
|
20
|
+
def rate_limit
|
21
|
+
@rate_limit
|
25
22
|
end
|
26
23
|
|
27
|
-
def
|
28
|
-
@
|
24
|
+
def msg
|
25
|
+
@msg
|
29
26
|
end
|
30
27
|
|
31
|
-
def
|
32
|
-
|
28
|
+
def error
|
29
|
+
@error
|
33
30
|
end
|
34
31
|
|
35
32
|
private
|
36
33
|
|
37
|
-
def
|
38
|
-
|
34
|
+
def parse_rate(headers)
|
35
|
+
{
|
36
|
+
limit: headers[:x_ratelimit_limit],
|
37
|
+
remaining: headers[:x_ratelimit_remaining],
|
38
|
+
reset: headers[:x_ratelimit_reset],
|
39
|
+
retry_after: headers[:x_retry_after] || nil
|
40
|
+
}
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
data/lib/wiot-sdk/version.rb
CHANGED
data/lib/wiot-sdk.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
require 'wiot-sdk/client'
|
2
|
-
require 'wiot-sdk/
|
2
|
+
require 'wiot-sdk/payload'
|
3
|
+
require 'wiot-sdk/version'
|
3
4
|
|
4
5
|
module WiotSdk
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
DEFAULT_BASE_URL = 'http://api.watchiot.com'
|
8
|
+
|
9
|
+
def self.init(username:, api_key:, space:, project:, base_url: DEFAULT_BASE_URL)
|
10
|
+
Client.init username, api_key, space, project, base_url
|
8
11
|
end
|
9
12
|
|
10
|
-
def self.init_yaml(file_path)
|
11
|
-
Client.init_yaml file_path
|
13
|
+
def self.init_yaml(file_path:, base_url: DEFAULT_BASE_URL)
|
14
|
+
Client.init_yaml file_path, base_url
|
12
15
|
end
|
13
16
|
|
14
|
-
def self.init_json(file_path)
|
15
|
-
Client.init_json file_path
|
17
|
+
def self.init_json(file_path:, base_url: DEFAULT_BASE_URL)
|
18
|
+
Client.init_json file_path, base_url
|
16
19
|
end
|
17
20
|
|
18
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wiot-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- watchiot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,10 +72,7 @@ files:
|
|
72
72
|
- lib/wiot-sdk/client.rb
|
73
73
|
- lib/wiot-sdk/config/parser_json.rb
|
74
74
|
- lib/wiot-sdk/config/parser_yml.rb
|
75
|
-
- lib/wiot-sdk/
|
76
|
-
- lib/wiot-sdk/data/errors.rb
|
77
|
-
- lib/wiot-sdk/data/rate.rb
|
78
|
-
- lib/wiot-sdk/metric.rb
|
75
|
+
- lib/wiot-sdk/payload.rb
|
79
76
|
- lib/wiot-sdk/request.rb
|
80
77
|
- lib/wiot-sdk/response.rb
|
81
78
|
- lib/wiot-sdk/version.rb
|
data/lib/wiot-sdk/data/error.rb
DELETED
data/lib/wiot-sdk/data/errors.rb
DELETED
@@ -1,23 +0,0 @@
|
|
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
|
data/lib/wiot-sdk/data/rate.rb
DELETED
@@ -1,29 +0,0 @@
|
|
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
|