Class: DockTest::RequestContext
- Inherits:
-
Object
- Object
- DockTest::RequestContext
- Defined in:
- lib/dock_test/request_context.rb
Instance Method Summary collapse
- #curl_command ⇒ Object
- #execute ⇒ Object
- #http_request ⇒ Object
-
#initialize(options) ⇒ RequestContext
constructor
A new instance of RequestContext.
- #verb_has_side_effects? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ RequestContext
Returns a new instance of RequestContext.
6 7 8 |
# File 'lib/dock_test/request_context.rb', line 6 def initialize() @options = end |
Instance Method Details
#curl_command ⇒ Object
23 24 25 26 27 28 |
# File 'lib/dock_test/request_context.rb', line 23 def curl_command headers_string = http_request.to_hash. map {|key, vals| vals.map {|val| [key, val]}.flatten}. map {|x| "-H '#{x[0].capitalize}: #{x[1]}'"}.join(' ') "curl -vv -X #{http_request.method.upcase} -d '#{http_request.body}' #{headers_string} '#{request_url}'" end |
#execute ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dock_test/request_context.rb', line 30 def execute Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https'), :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http| oauth_sign! if DockTest.oauth? # processing oauth signing http.request(http_request) end end |
#http_request ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dock_test/request_context.rb', line 10 def http_request @_request ||= Net::HTTP.const_get(verb.capitalize).new(uri.request_uri).tap do |req| # add the params to the body of other requests req.body = params if verb_has_side_effects? # sets the headers headers.each do |key, value| req[key] = value end end end |
#verb_has_side_effects? ⇒ Boolean
42 43 44 |
# File 'lib/dock_test/request_context.rb', line 42 def verb_has_side_effects? %w(post put patch delete).include?(verb) end |