Class: Endorser::Receipt
- Inherits:
-
Object
- Object
- Endorser::Receipt
- Defined in:
- lib/endorser/receipt.rb,
lib/endorser/receipt/version.rb
Constant Summary collapse
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#body ⇒ Object
Returns the value of attribute body.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#host ⇒ Object
Returns the value of attribute host.
-
#request_method ⇒ Object
Returns the value of attribute request_method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #body_length ⇒ Object
- #body_md5 ⇒ Object
- #header_text ⇒ Object
-
#initialize(params = {}) ⇒ Receipt
constructor
A new instance of Receipt.
- #preamble ⇒ Object
- #to_s ⇒ Object
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_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/endorser/receipt.rb', line 8 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
9 10 11 |
# File 'lib/endorser/receipt.rb', line 9 def api_secret @api_secret end |
#body ⇒ Object
Returns the value of attribute body.
10 11 12 |
# File 'lib/endorser/receipt.rb', line 10 def body @body end |
#content_type ⇒ Object
Returns the value of attribute content_type.
11 12 13 |
# File 'lib/endorser/receipt.rb', line 11 def content_type @content_type end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/endorser/receipt.rb', line 6 def headers @headers end |
#host ⇒ Object
Returns the value of attribute host.
13 14 15 |
# File 'lib/endorser/receipt.rb', line 13 def host @host end |
#request_method ⇒ Object
Returns the value of attribute request_method.
5 6 7 |
# File 'lib/endorser/receipt.rb', line 5 def request_method @request_method end |
#uri ⇒ Object
Returns the value of attribute uri.
12 13 14 |
# File 'lib/endorser/receipt.rb', line 12 def uri @uri end |
Instance Method Details
#body_length ⇒ Object
35 36 37 |
# File 'lib/endorser/receipt.rb', line 35 def body_length body.length end |
#body_md5 ⇒ Object
31 32 33 |
# File 'lib/endorser/receipt.rb', line 31 def body_md5 Digest::MD5.hexdigest(body) end |
#header_text ⇒ Object
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 |
#preamble ⇒ Object
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_s ⇒ Object
39 40 41 |
# File 'lib/endorser/receipt.rb', line 39 def to_s preamble + header_text end |