class Endorser::Receipt

Constants

VERSION

Attributes

api_key[RW]
api_secret[RW]
body[RW]
content_type[RW]
headers[R]
host[RW]
request_method[R]
uri[RW]

Public Class Methods

new(params={}) click to toggle source
# File lib/endorser/receipt.rb, line 15
def initialize(params={})
  @headers = {}

  self.api_key      = params.fetch(:api_key, nil)
  self.api_secret   = params.fetch(:api_secret, nil)
  self.body         = params.fetch(:body, nil)
  self.content_type = params.fetch(:content_type, nil)
  self.uri          = params.fetch(:uri, nil)
  self.host         = params.fetch(:host, nil)
  request_method    = params.fetch(:request_method, '')
end

Public Instance Methods

body_length() click to toggle source
# File lib/endorser/receipt.rb, line 35
def body_length
  body.length
end
body_md5() click to toggle source
# File lib/endorser/receipt.rb, line 31
def body_md5
  Digest::MD5.hexdigest(body)
end
header_text() click to toggle source
# File lib/endorser/receipt.rb, line 55
def header_text
  text = ""
  headers.sort_by { |k,v| k.downcase }.each do |header, value|
    text << "%s:%s\n" % [header.downcase, value]
  end
  text
end
preamble() click to toggle source
# File lib/endorser/receipt.rb, line 43
def preamble
  text = ""
  text << "%s\n" % request_method
  text << "%s\n" % host
  text << "%s\n" % uri
  text << "%s\n" % api_key
  text << "%s\n" % content_type
  text << "%s\n" % body_length
  text << "%s\n" % body_md5
  text
end
request_method=(s) click to toggle source
# File lib/endorser/receipt.rb, line 27
def request_method=(s)
  @request_method = s.upcase
end
to_s() click to toggle source
# File lib/endorser/receipt.rb, line 39
def to_s
  preamble + header_text
end