class HTTPClient
Public Class Methods
new(params)
click to toggle source
# File lib/neixin.rb, line 8 def initialize(params) @appkey = params[:appkey] @secret = params[:secret] end
Public Instance Methods
request(path, body)
click to toggle source
# File lib/neixin.rb, line 12 def request(path, body) headers = self.sign(path) http = Net::HTTP.new("dxw-in.sankuai.com") http.request_put(path, body.to_json, headers) end
sign(path)
click to toggle source
# File lib/neixin.rb, line 17 def sign(path) timestamp = Time.now.gmtime.strftime('%a, %d %b %Y %H:%M:%S GMT') req = "PUT #{path}\n#{timestamp}" hash = OpenSSL::HMAC.digest('sha1', @secret, req) auth = Base64.encode64 hash { "Date": timestamp, "Authorization": "MWS #{@appkey}:#{auth}", "Content-Type": "application/json" } end