Class: Endorser::Receipt

Inherits:
Object
  • Object
show all
Defined in:
lib/endorser/receipt.rb,
lib/endorser/receipt/version.rb

Constant Summary collapse

VERSION =
"1.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Receipt

Returns a new instance of Receipt.



15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/endorser/receipt.rb', line 8

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



9
10
11
# File 'lib/endorser/receipt.rb', line 9

def api_secret
  @api_secret
end

#bodyObject

Returns the value of attribute body.



10
11
12
# File 'lib/endorser/receipt.rb', line 10

def body
  @body
end

#content_typeObject

Returns the value of attribute content_type.



11
12
13
# File 'lib/endorser/receipt.rb', line 11

def content_type
  @content_type
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/endorser/receipt.rb', line 6

def headers
  @headers
end

#hostObject

Returns the value of attribute host.



13
14
15
# File 'lib/endorser/receipt.rb', line 13

def host
  @host
end

#request_methodObject

Returns the value of attribute request_method.



5
6
7
# File 'lib/endorser/receipt.rb', line 5

def request_method
  @request_method
end

#uriObject

Returns the value of attribute uri.



12
13
14
# File 'lib/endorser/receipt.rb', line 12

def uri
  @uri
end

Instance Method Details

#body_lengthObject



35
36
37
# File 'lib/endorser/receipt.rb', line 35

def body_length
  body.length
end

#body_md5Object



31
32
33
# File 'lib/endorser/receipt.rb', line 31

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

#header_textObject



55
56
57
58
59
60
61
# 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

#preambleObject



43
44
45
46
47
48
49
50
51
52
53
# 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

#to_sObject



39
40
41
# File 'lib/endorser/receipt.rb', line 39

def to_s
  preamble + header_text
end