huawei_cloud_store_gateway_sdk 0.1.0 → 0.2.0
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/README.md +36 -19
- data/lib/huawei_cloud_store_gateway_sdk/version.rb +1 -1
- data/lib/huawei_cloud_store_gateway_sdk.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1584e792fa12eee9f63d8d04ee815ae6e714f878424180470765d00f77665b1c
|
4
|
+
data.tar.gz: 975d82e953d2ecc6563031256918d32e762b02c84f6f0070a77137fe4af145c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25e1f5fe8b16f714cab177f1fb4f4d84bc6eb4ded9ba00ba835b69bc98615096a2ed3203496726d61871beb19afd18fb8948c46ede9f82a06a49fae373533c9d
|
7
|
+
data.tar.gz: deca024cabacfb3895ddb8722335a30bf414a31a9ab7d911bb51f22989544da861527de46bf048ed2338bd979fe97e71f9d8e3afc0bef094e63a032b327ea3f3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,56 @@
|
|
1
1
|
# HuaweiCloudStoreGatewaySdk
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/huawei_cloud_store_gateway_sdk`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
A Ruby SDK for interacting with Huawei Cloud's Store Gateway API. This SDK helps in generating request signatures and provides methods for configuring the SDK with your API key and secret to authenticate API requests.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
Add the following to your Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'huawei_cloud_store_gateway_sdk'
|
11
|
+
|
12
|
+
Then run bundle install:
|
10
13
|
|
11
|
-
|
14
|
+
bundle install
|
12
15
|
|
13
|
-
|
16
|
+
Alternatively, you can install it directly via the terminal:
|
14
17
|
|
15
|
-
|
18
|
+
gem install huawei_cloud_store_gateway_sdk
|
16
19
|
|
17
|
-
|
20
|
+
Configuration
|
18
21
|
|
19
|
-
|
22
|
+
Before making requests with the SDK, you need to configure it with your app_key and app_secret. You can do this as follows:
|
20
23
|
|
21
|
-
|
24
|
+
HuaweiCloudStoreGatewaySdk.configure do |config|
|
25
|
+
config.app_key = 'your_app_key'
|
26
|
+
config.app_secret = 'your_app_secret'
|
27
|
+
end
|
22
28
|
|
23
|
-
|
29
|
+
Once the SDK is configured, you can access the configuration like this:
|
24
30
|
|
25
|
-
|
31
|
+
configuration = HuaweiCloudStoreGatewaySdk.configuration
|
32
|
+
puts configuration.app_key # => 'your_app_key'
|
33
|
+
puts configuration.app_secret # => 'your_app_secret'
|
26
34
|
|
27
|
-
|
35
|
+
Usage
|
28
36
|
|
29
|
-
|
37
|
+
Signing Requests
|
30
38
|
|
31
|
-
|
39
|
+
The sign_request method signs the request with the provided HTTP method, URL, headers, app_key, and app_secret. It generates the required signature and includes it in the Authorization header.
|
32
40
|
|
33
|
-
|
41
|
+
Example usage:
|
34
42
|
|
35
|
-
|
43
|
+
url = "https://mkt.myhuaweicloud.com/api/mkp-openapi-public/global/v1/license/activate"
|
44
|
+
headers = {
|
45
|
+
"x-stage" => "RELEASE",
|
46
|
+
"X-Sdk-Date" => "20240317T144237Z",
|
47
|
+
"Content-Type" => "application/json"
|
48
|
+
}
|
49
|
+
app_key = 'your_app_key'
|
50
|
+
app_secret = 'your_app_secret'
|
36
51
|
|
37
|
-
|
52
|
+
result = HuaweiCloudStoreGatewaySdk.sign_request("POST", url, headers, "")
|
53
|
+
puts result[:headers]["Authorization"]
|
38
54
|
|
39
|
-
|
55
|
+
This will output the Authorization header with the correct signature.
|
56
|
+
|
@@ -27,14 +27,14 @@ module HuaweiCloudStoreGatewaySdk
|
|
27
27
|
class HwStoreSDK
|
28
28
|
attr_accessor :method, :uri, :headers, :body, :query, :app_key, :app_secret
|
29
29
|
|
30
|
-
def initialize(method, uri, headers,
|
30
|
+
def initialize(method, uri, headers, body)
|
31
31
|
@method = method
|
32
32
|
@uri = URI(uri)
|
33
33
|
@headers = headers.transform_keys(&:to_s)
|
34
34
|
@body = body
|
35
35
|
@query = @uri.query ? URI.decode_www_form(@uri.query).to_h : {}
|
36
|
-
@app_key = app_key
|
37
|
-
@app_secret = app_secret
|
36
|
+
@app_key = HuaweiCloudStoreGatewaySdk.configuration.app_key
|
37
|
+
@app_secret = HuaweiCloudStoreGatewaySdk.configuration.app_secret
|
38
38
|
end
|
39
39
|
|
40
40
|
def full_path
|
@@ -44,8 +44,8 @@ module HuaweiCloudStoreGatewaySdk
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def sign_request(method, uri, headers,
|
48
|
-
request = HwStoreSDK.new(method, uri, headers,
|
47
|
+
def sign_request(method, uri, headers, body)
|
48
|
+
request = HwStoreSDK.new(method, uri, headers, body)
|
49
49
|
sign_headers(request)
|
50
50
|
{
|
51
51
|
url: request.full_path,
|