Class: AliyunIot::Request::Xml
- Inherits:
-
Object
- Object
- AliyunIot::Request::Xml
- Defined in:
- lib/aliyun_iot/request/xml.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#content_md5 ⇒ Object
readonly
Returns the value of attribute content_md5.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#mqs_headers ⇒ Object
readonly
Returns the value of attribute mqs_headers.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #content(type, values = {}) ⇒ Object
- #execute ⇒ Object
-
#initialize(method: "get", path: "/", mqs_headers: {}, query: {}) ⇒ Xml
constructor
A new instance of Xml.
Constructor Details
#initialize(method: "get", path: "/", mqs_headers: {}, query: {}) ⇒ Xml
Returns a new instance of Xml.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aliyun_iot/request/xml.rb', line 33 def initialize(method: "get", path: "/", mqs_headers: {}, query: {}) conf = { host: end_point, path: path } conf.merge!(query: query.to_query) unless query.empty? @uri = URI::HTTP.build(conf) @method = method @client = HttpClient.new(@uri.to_s) @mqs_headers = mqs_headers.merge("x-mns-version" => "2015-06-06") end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def body @body end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def client @client end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def content_length @content_length end |
#content_md5 ⇒ Object (readonly)
Returns the value of attribute content_md5.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def content_md5 @content_md5 end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def content_type @content_type end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def method @method end |
#mqs_headers ⇒ Object (readonly)
Returns the value of attribute mqs_headers.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def mqs_headers @mqs_headers end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
18 19 20 |
# File 'lib/aliyun_iot/request/xml.rb', line 18 def uri @uri end |
Instance Method Details
#content(type, values = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aliyun_iot/request/xml.rb', line 45 def content(type, values={}) ns = "http://mns.aliyuncs.com/doc/v1/" builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.send(type.to_sym, xmlns: ns) do |b| values.each { |k, v| b.send k.to_sym, v } end end @body = builder.to_xml @content_md5 = Base64::encode64(Digest::MD5.hexdigest(body)).chop @content_length = body.size @content_type = "text/xml;charset=utf-8" end |
#execute ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/aliyun_iot/request/xml.rb', line 58 def execute date = DateTime.now.httpdate headers = { "Authorization" => (date), "Content-Length" => content_length || 0, "Content-Type" => content_type, "Content-MD5" => content_md5, "Date" => date, "Host" => uri.host }.merge(mqs_headers).reject { |k, v| v.nil? } client.send *[method, body, headers].compact end |