Sha256: 085bcd5f2b5aba51b90fe7fe9af0b5a98fb770509e7bd8cd699c5ae4e6a62ebf
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
module PAS class Connection < ActiveResource::Connection def get(path, headers = {}) super(merge_signature_to_path(:get, path), headers) end def delete(path, headers = {}) super(merge_signature_to_path(:delete, path), headers) end def put(path, body = '', headers = {}) super(merge_signature_to_path(:put, path), body, headers) end def post(path, body = '', headers = {}) super(merge_signature_to_path(:post, path), body, headers) end private def merge_signature_to_path(request_method, path) path, query = path.split("?") timestamp = Time.now.to_i.to_s signature = CGI::escape(generate_signature(request_method, path, timestamp)) params = "?#{query.blank? ? "" : "#{query}&" }api_token=#{PAS.config[:api_token].to_s}×tamp=#{timestamp}&signature=#{signature}" path + params end def generate_signature(request_method, path, timestamp) data = PAS.config[:api_token].to_s + request_method.to_s.upcase + path + timestamp signature = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, PAS.config[:api_access_key].to_s, data) Base64.encode64(signature).chomp end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pas-0.0.2 | lib/pas/connection.rb |