Class: Smaak::NetHttpAdaptor
- Inherits:
-
Object
- Object
- Smaak::NetHttpAdaptor
- Defined in:
- lib/smaak/adaptors/net_http_adaptor.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(body) ⇒ Object
- #each_header(&block) ⇒ Object
- #host ⇒ Object
-
#initialize(request) ⇒ NetHttpAdaptor
constructor
A new instance of NetHttpAdaptor.
- #method ⇒ Object
- #path ⇒ Object
- #set_header(header, value) ⇒ Object
Constructor Details
#initialize(request) ⇒ NetHttpAdaptor
Returns a new instance of NetHttpAdaptor.
9 10 11 12 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 9 def initialize(request) raise ArgumentError.new("Must provide a Net::HTTPRequest") unless request.is_a? Net::HTTPRequest @request = request end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
7 8 9 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 7 def request @request end |
Instance Method Details
#body ⇒ Object
35 36 37 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 35 def body @request.body end |
#body=(body) ⇒ Object
39 40 41 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 39 def body=(body) @request.body = body end |
#each_header(&block) ⇒ Object
19 20 21 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 19 def each_header(&block) @request.each_header(&block) end |
#host ⇒ Object
23 24 25 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 23 def host URI.parse(@request.path).host end |
#method ⇒ Object
31 32 33 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 31 def method @request.method end |
#path ⇒ Object
27 28 29 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 27 def path URI.parse(@request.path).path end |
#set_header(header, value) ⇒ Object
14 15 16 17 |
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 14 def set_header(header, value) raise ArgumentError.new("Header must be a non-blank string") unless Smaak::Utils.non_blank_string?(header) @request[header] = value end |