Class: HttpVanilli::OtherMapper
- Defined in:
- lib/http_vanilli/other_mapper.rb
Instance Method Summary collapse
-
#build_request(kind, http, request, body, &block) ⇒ Object
Take the info from the innards of Net::HTTP and build a request.
- #customise_request(&block) ⇒ Object
-
#map_request(request) ⇒ Object
Map the request.
-
#map_request?(request) ⇒ Boolean
Should we map the request?.
-
#unmapped_request(request) ⇒ Object
The request wasn’t matched and normal net connection was disallowed.
Instance Method Details
#build_request(kind, http, request, body, &block) ⇒ Object
Take the info from the innards of Net::HTTP and build a request.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/http_vanilli/other_mapper.rb', line 11 def build_request(kind,http,request,body,&block) req = OpenStruct.new req.block = block pp http pp request.to_hash protocol = http.use_ssl? ? "https" : "http" path = request.path path = Addressable::URI.parse(request.path).request_uri if request.path =~ /^http/ req.uri = Addressable::URI.parse( "#{protocol}://#{http.address}:#{http.port}#{path}" ) req.method = request.method.downcase.to_sym if @customise_request @customise_request[req] end req end |
#customise_request(&block) ⇒ Object
6 7 8 |
# File 'lib/http_vanilli/other_mapper.rb', line 6 def customise_request(&block) @customise_request = block end |
#map_request(request) ⇒ Object
Map the request
39 40 41 42 43 44 45 46 47 |
# File 'lib/http_vanilli/other_mapper.rb', line 39 def map_request(request) response = HttpVanilli::NetHttp::Response.new(200,'cool') response.body = "boddy" nhrsp = response.to_net_http request.block[nhrsp] if request.block nhrsp end |
#map_request?(request) ⇒ Boolean
Should we map the request?
34 35 36 |
# File 'lib/http_vanilli/other_mapper.rb', line 34 def map_request?(request) true end |
#unmapped_request(request) ⇒ Object
The request wasn’t matched and normal net connection was disallowed.
50 51 52 |
# File 'lib/http_vanilli/other_mapper.rb', line 50 def unmapped_request(request) raise "unmatched_request :(" end |