Class: Quaff::SipMessage
- Inherits:
-
Object
- Object
- Quaff::SipMessage
- Defined in:
- lib/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#reason ⇒ Object
Returns the value of attribute reason.
-
#requri ⇒ Object
Returns the value of attribute requri.
-
#source ⇒ Object
Returns the value of attribute source.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #all_headers(hdr) ⇒ Object
- #header(hdr) ⇒ Object (also: #first_header)
-
#initialize(method = nil, status_code = nil, reason = nil, req_uri = nil, body = "", headers = {}) ⇒ SipMessage
constructor
A new instance of SipMessage.
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(method = nil, status_code = nil, reason = nil, req_uri = nil, body = "", headers = {}) ⇒ SipMessage
Returns a new instance of SipMessage.
6 7 8 9 10 11 12 |
# File 'lib/message.rb', line 6 def initialize method=nil, status_code=nil, reason=nil, req_uri=nil, body="", headers={} @headers = headers @method, @status_code, @reason, @req_uri = method, status_code, reason, req_uri @body = body @headers['Content-Length'] = [body.length] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
4 5 6 |
# File 'lib/message.rb', line 4 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/message.rb', line 3 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/message.rb', line 3 def method @method end |
#reason ⇒ Object
Returns the value of attribute reason.
3 4 5 |
# File 'lib/message.rb', line 3 def reason @reason end |
#requri ⇒ Object
Returns the value of attribute requri.
3 4 5 |
# File 'lib/message.rb', line 3 def requri @requri end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/message.rb', line 3 def source @source end |
#status_code ⇒ Object
Returns the value of attribute status_code.
3 4 5 |
# File 'lib/message.rb', line 3 def status_code @status_code end |
Instance Method Details
#[](key) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/message.rb', line 14 def [] key if key == "message" self elsif key == "source" @source end end |
#all_headers(hdr) ⇒ Object
32 33 34 |
# File 'lib/message.rb', line 32 def all_headers hdr return @headers[hdr] end |
#header(hdr) ⇒ Object Also known as: first_header
36 37 38 |
# File 'lib/message.rb', line 36 def header hdr return @headers[hdr][0] unless @headers[hdr].nil? end |
#to_s ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/message.rb', line 47 def to_s msg = "" if type == :request msg << "#{@method} #{@req_uri} SIP/2.0\r\n" else msg << "SIP/2.0 #{@status_code} #{@reason}\r\n" end @headers.each do |key, value| if value.nil? elsif not value.kind_of? Array msg << "#{key}: #{value}\r\n" else value.each do |subvalue| msg << "#{key}: #{subvalue}\r\n" end end end if body and body != "" msg << "\r\n" msg << body else msg << "\r\n" end msg end |
#type ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/message.rb', line 22 def type if @method :request elsif @status_code :response else :nil end end |