Class: AliyunIot::Request::Json
- Inherits:
-
Object
- Object
- AliyunIot::Request::Json
- Defined in:
- lib/aliyun_iot/request/json.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(method: "post", params: {}) ⇒ Json
constructor
A new instance of Json.
Constructor Details
#initialize(method: "post", params: {}) ⇒ Json
Returns a new instance of Json.
21 22 23 24 25 |
# File 'lib/aliyun_iot/request/json.rb', line 21 def initialize(method: "post", params: {}) @params = params @method = method @client = HttpClient.new(base_url) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/aliyun_iot/request/json.rb', line 8 def body @body end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/aliyun_iot/request/json.rb', line 8 def client @client end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/aliyun_iot/request/json.rb', line 8 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/aliyun_iot/request/json.rb', line 8 def params @params end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/aliyun_iot/request/json.rb', line 8 def url @url end |
Instance Method Details
#execute ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/aliyun_iot/request/json.rb', line 27 def execute ts = Time.now.utc.strftime('%FT%TZ') base_params = { Format: 'JSON', Version: '2017-04-20', AccessKeyId: access_key_id, SignatureMethod: 'HMAC-SHA1', Timestamp: ts, SignatureVersion: '1.0', SignatureNonce: SecureRandom.uuid, RegionId: region_id, ServiceCode: 'iot', } exec_params = encode base_params.merge!(params) begin JSON.parse client.send(method, exec_params).body rescue => e logger = Logger.new(STDOUT) logger.error e. logger.error e.backtrace.join("\n") raise e end end |