Class: Smaak::NetHttpAdaptor

Inherits:
Object
  • Object
show all
Defined in:
lib/smaak/adaptors/net_http_adaptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ NetHttpAdaptor

Returns a new instance of NetHttpAdaptor.

Raises:

  • (ArgumentError)


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

#requestObject (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

#bodyObject



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

#hostObject



23
24
25
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 23

def host
  URI.parse(@request.path).host
end

#methodObject



31
32
33
# File 'lib/smaak/adaptors/net_http_adaptor.rb', line 31

def method
  @request.method
end

#pathObject



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

Raises:

  • (ArgumentError)


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