Class: Rack::Contrib::Sign::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/contrib/sign/receipt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReceipt

Returns a new instance of Receipt.



15
16
17
# File 'lib/rack/contrib/sign/receipt.rb', line 15

def initialize
  @headers = {}
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/rack/contrib/sign/receipt.rb', line 8

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



9
10
11
# File 'lib/rack/contrib/sign/receipt.rb', line 9

def api_secret
  @api_secret
end

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/rack/contrib/sign/receipt.rb', line 10

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type.



11
12
13
# File 'lib/rack/contrib/sign/receipt.rb', line 11

def content_type
  @content_type
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/rack/contrib/sign/receipt.rb', line 7

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



13
14
15
# File 'lib/rack/contrib/sign/receipt.rb', line 13

def host
  @host
end

#request_methodObject

Returns the value of attribute request_method.



6
7
8
# File 'lib/rack/contrib/sign/receipt.rb', line 6

def request_method
  @request_method
end

#uriObject

Returns the value of attribute uri.



12
13
14
# File 'lib/rack/contrib/sign/receipt.rb', line 12

def uri
  @uri
end

Instance Method Details

#body_lengthObject



27
28
29
# File 'lib/rack/contrib/sign/receipt.rb', line 27

def body_length
  body.length
end

#body_md5Object



23
24
25
# File 'lib/rack/contrib/sign/receipt.rb', line 23

def body_md5
  Digest::MD5.hexdigest(body)
end

#header_textObject



47
48
49
50
51
52
53
54
55
# File 'lib/rack/contrib/sign/receipt.rb', line 47

def header_text
  s = ""

  headers.sort_by { |k,v| k.downcase }.each do |header, value|
    s << "%s:%s\n" % [header.downcase, value]
  end

  s
end

#preambleObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rack/contrib/sign/receipt.rb', line 35

def preamble
  s = ""
  s << "%s\n" % request_method
  s << "%s\n" % host
  s << "%s\n" % uri
  s << "%s\n" % api_key
  s << "%s\n" % content_type
  s << "%s\n" % body_length
  s << "%s\n" % body_md5
  s
end

#to_sObject



31
32
33
# File 'lib/rack/contrib/sign/receipt.rb', line 31

def to_s
  preamble + header_text
end