Class: KirinHttp::Message
- Inherits:
-
Object
- Object
- KirinHttp::Message
- Defined in:
- lib/kirin_http/http_message.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#header ⇒ Object
Returns the value of attribute header.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(url, method = :get, content = nil, header = {}) ⇒ Message
constructor
Constructor.
-
#url=(value) ⇒ Object
Endpoint of the Http Message.
Constructor Details
#initialize(url, method = :get, content = nil, header = {}) ⇒ Message
Constructor
endpoint = “host.com/post/1?id=5” data = “name”:“John”, “country”: “singapore” headers = “application/json”, “Accept”: “text/plain” message = KirinHttpClient::HttpMessage.new(endpoint, :post, data.to_json, headers) # Use HttpClient to send the message
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kirin_http/http_message.rb', line 18 def initialize(url, method = :get, content = nil, header = {}) uri = URI.parse(url) @host = uri.host @port = uri.port @path = uri.request_uri @ssl = uri.scheme == "https" @header = header @header["Host"] = uri.host @method = method @content = content @uri = url end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/kirin_http/http_message.rb', line 4 def content @content end |
#header ⇒ Object
Returns the value of attribute header.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def header @header end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def host @host end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/kirin_http/http_message.rb', line 4 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def path @path end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def ssl @ssl end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/kirin_http/http_message.rb', line 3 def uri @uri end |
Instance Method Details
#url=(value) ⇒ Object
Endpoint of the Http Message
33 34 35 36 37 38 39 40 41 |
# File 'lib/kirin_http/http_message.rb', line 33 def url=(value) uri = URI.parse(value) @host = uri.host @port = uri.port @path = uri.request_uri @ssl = uri.scheme == "https" @uri = value @header["Host"] = uri.host end |