Class: PostBin::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/postbin/post.rb

Overview

Represents header/body information of a HTTP POST request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers, body, received_at = nil) ⇒ Post

Returns a new instance of Post.



7
8
9
10
11
# File 'lib/postbin/post.rb', line 7

def initialize(headers, body, received_at = nil)
  @received_at = received_at || Time.now
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/postbin/post.rb', line 5

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/postbin/post.rb', line 5

def headers
  @headers
end

#received_atObject (readonly)

Returns the value of attribute received_at.



5
6
7
# File 'lib/postbin/post.rb', line 5

def received_at
  @received_at
end

Instance Method Details

#==(other) ⇒ Object

Returns true only if the two posts contain equal data.



14
15
16
17
18
19
# File 'lib/postbin/post.rb', line 14

def ==(other)
  return false unless Post === other
  return false unless received_at == other.received_at
  return false unless headers == other.headers
  body == other.body
end

#to_json(*options) ⇒ Object



21
22
23
# File 'lib/postbin/post.rb', line 21

def to_json(*options)
  MultiJson.encode({ :received_at => received_at, :headers => headers, :body => body })
end