wattsense-api-client 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1faff348377c3626f858fe12fa996a4f37401fdd818ed1167d713a65188d2fe
|
4
|
+
data.tar.gz: 34cedf857f72be6be95f5ec633f59b9d356cafd3ee02bfde93dd7515cc2c3ab3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5eee4d1a875ac73f8bd067846a4d1b35dfdf3331931d58251bfca1daea1aea230d9382ed3bedeae435e5c65e44f9a24de2c8a1f6e37bae5e5b7e1bf0571a29a0
|
7
|
+
data.tar.gz: f44cd1e4be3980e2f43783cba0a95c5fc8f74c9d1a8e2779a5ce558ffc0bd5f6a06c969dbb67c45067d84aaf86512c9e6f56fe383237142456058edadd73e586
|
@@ -5,6 +5,9 @@
|
|
5
5
|
#++
|
6
6
|
# frozen_string_literal: true
|
7
7
|
|
8
|
+
require 'openssl'
|
9
|
+
require 'base64'
|
10
|
+
|
8
11
|
module WattSenseApi
|
9
12
|
module V1
|
10
13
|
# This module gather all the necessary elements for ClientV1 ability to authenticate to the
|
@@ -19,8 +22,15 @@ module WattSenseApi
|
|
19
22
|
#
|
20
23
|
# @param api_key [String] The api's credential key
|
21
24
|
# @param api_secret [String] The api's credential secret
|
22
|
-
def api_key_authentication(
|
23
|
-
|
25
|
+
def api_key_authentication(api_key, api_secret)
|
26
|
+
@auth_block =
|
27
|
+
lambda do |request|
|
28
|
+
time = now_in_ms
|
29
|
+
to_sign = to_sign_from_request(request, time)
|
30
|
+
signed = ::OpenSSL::HMAC.digest('SHA512', api_secret, to_sign.join("\n"))
|
31
|
+
request['X-API-Auth'] = "#{api_key}:#{::Base64.strict_encode64(signed)}"
|
32
|
+
request['X-API-Timestamp'] = time.to_s
|
33
|
+
end
|
24
34
|
end
|
25
35
|
|
26
36
|
# This method allows to use username/password credentials with HTTP Basic user authentication
|
@@ -31,6 +41,21 @@ module WattSenseApi
|
|
31
41
|
def basic_user_authentication(username, password)
|
32
42
|
@auth_block = ->(request) { request.basic_auth(username, password) }
|
33
43
|
end
|
44
|
+
|
45
|
+
# @return [Integer] Time now in ms since Epoch
|
46
|
+
def now_in_ms
|
47
|
+
now = ::Time.now
|
48
|
+
now.tv_sec * 1000 + now.tv_usec / 1_000
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [String] Message to sign
|
52
|
+
def to_sign_from_request(request, time)
|
53
|
+
to_sign = [request.method, request.uri.path]
|
54
|
+
to_sign.push(request.uri.query) if request.uri.query
|
55
|
+
to_sign.push(request.body) if request.body
|
56
|
+
to_sign << time.to_s
|
57
|
+
to_sign
|
58
|
+
end
|
34
59
|
end
|
35
60
|
end
|
36
61
|
end
|
@@ -13,6 +13,7 @@ require 'watt_sense_api/v1/organization'
|
|
13
13
|
require 'watt_sense_api/v1/user_management'
|
14
14
|
require 'watt_sense_api/v1/device_information'
|
15
15
|
require 'watt_sense_api/v1/properties_measurements'
|
16
|
+
require 'watt_sense_api/v1/property_configuration'
|
16
17
|
|
17
18
|
module WattSenseApi
|
18
19
|
module V1
|
@@ -24,6 +25,7 @@ module WattSenseApi
|
|
24
25
|
include ::WattSenseApi::V1::UserManagement
|
25
26
|
include ::WattSenseApi::V1::DeviceInformation
|
26
27
|
include ::WattSenseApi::V1::PropertiesMeasurements
|
28
|
+
include ::WattSenseApi::V1::PropertyConfiguration
|
27
29
|
|
28
30
|
# You can create a client V1 with both user's credentials or api creddentials.
|
29
31
|
#
|
@@ -60,7 +60,7 @@ module WattSenseApi
|
|
60
60
|
# @raise [::WattSenseApi::HTTPError] when server response is not as expected (HTTPAccepted with a body)
|
61
61
|
def device_property_set(device_id, property_id, body)
|
62
62
|
response = put("devices/#{device_id}/properties/#{property_id}", body.to_json)
|
63
|
-
return ::JSON.parse(response.body) if response.is_a?(::Net::
|
63
|
+
return ::JSON.parse(response.body) if response.is_a?(::Net::HTTPOK)
|
64
64
|
|
65
65
|
raise(::WattSenseApi::HTTPError, response)
|
66
66
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2021 - Octopus Lab SAS
|
3
|
+
# All rights are described by the GPLv3 license present in the file /LICENSE available in the
|
4
|
+
# original repository of this file or [here](https://www.gnu.org/licenses/gpl-3.0.fr.html).
|
5
|
+
#++
|
6
|
+
# frozen_string_literal: true
|
7
|
+
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
module WattSenseApi
|
12
|
+
module V1
|
13
|
+
# This module gather all the methods to deal with [Property Configuration](https://api.wattsense.com/#tag/Property-Configuration)
|
14
|
+
module PropertyConfiguration
|
15
|
+
# List all properties present in a specific config revision.
|
16
|
+
#
|
17
|
+
# @see https://api.wattsense.com/#operation/listPropertyConfiguration API documentation
|
18
|
+
#
|
19
|
+
# @param device_id [String] The device id
|
20
|
+
# @param revision_id [String] The revision id of the configuration to get. Default: "current"
|
21
|
+
# Two special cases:
|
22
|
+
# - "current" will return the currently published config revision, i.e. status equal to CURRENT
|
23
|
+
# - "draft" will return the current draft i.e. status equal to DRAFT or SENT
|
24
|
+
#
|
25
|
+
# @return [Hash|NilClass] Hash of the property's latest value (nil if property is unreachable)
|
26
|
+
# @raise [::WattSenseApi::HTTPError] when server response is not as expected (HTTPAccepted with a body)
|
27
|
+
def device_config_properties(device_id, revision_id = 'current')
|
28
|
+
response = get("devices/#{device_id}/configs/#{revision_id}/properties")
|
29
|
+
return ::JSON.parse(response.body) if response.is_a?(::Net::HTTPOK)
|
30
|
+
|
31
|
+
return if response.is_a?(::Net::HTTPNoContent)
|
32
|
+
|
33
|
+
raise(::WattSenseApi::HTTPError, response)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wattsense-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roland Laurès
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0.14'
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.10'
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 1.20.0
|
48
|
-
type: :
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.4'
|
62
|
-
type: :
|
62
|
+
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.21.2
|
76
|
-
type: :
|
76
|
+
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.9'
|
90
|
-
type: :
|
90
|
+
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/watt_sense_api/v1/device_information.rb
|
111
111
|
- lib/watt_sense_api/v1/organization.rb
|
112
112
|
- lib/watt_sense_api/v1/properties_measurements.rb
|
113
|
+
- lib/watt_sense_api/v1/property_configuration.rb
|
113
114
|
- lib/watt_sense_api/v1/user_management.rb
|
114
115
|
- lib/watt_sense_api/version.rb
|
115
116
|
- lib/wattsense-api-client.rb
|
@@ -117,10 +118,10 @@ homepage: https://rubygems.org/gems/wattsense-api-client
|
|
117
118
|
licenses:
|
118
119
|
- GPL v3
|
119
120
|
metadata:
|
120
|
-
bug_tracker_uri: https://gitlab.com/octopuslab
|
121
|
-
changelog_uri: https://gitlab.com/octopuslab
|
122
|
-
documentation_uri: https://octopuslab
|
123
|
-
homepage_uri: https://gitlab.com/octopuslab
|
121
|
+
bug_tracker_uri: https://gitlab.com/fr-octopuslab/wattsense-api-client/-/issues
|
122
|
+
changelog_uri: https://gitlab.com/octopuslab/wattsense-api-client/-/blob/main/CHANGELOG.md
|
123
|
+
documentation_uri: https://fr-octopuslab.gitlab.io/wattsense-api-client/0.4.1
|
124
|
+
homepage_uri: https://gitlab.com/octopuslab/wattsense-api-client
|
124
125
|
post_install_message:
|
125
126
|
rdoc_options: []
|
126
127
|
require_paths:
|