Module: EvalIn::HTTP
Overview
This module contains generic wrappers over net/http We can’t just use Net::HTTP.get, b/c it doesn’t use ssl on 1.9.3 github.com/ruby/ruby/blob/v2_1_2/lib/net/http.rb#L478-479 github.com/ruby/ruby/blob/v1_9_3_547/lib/net/http.rb#L454
Instance Method Summary collapse
-
#generic_request_for(params) ⇒ Object
stole this out of implementation for post_form github.com/ruby/ruby/blob/2afed6eceff2951b949db7ded8167a75b431bad6/lib/net/http.rb#L503 can use this to view the request: http.set_debug_output $stdout.
- #get_request(raw_url, user_agent) ⇒ Object
- #jsonify_url(url) ⇒ Object
- #post_request(raw_url, form_data, user_agent) ⇒ Object
Instance Method Details
#generic_request_for(params) ⇒ Object
stole this out of implementation for post_form github.com/ruby/ruby/blob/2afed6eceff2951b949db7ded8167a75b431bad6/lib/net/http.rb#L503 can use this to view the request: http.set_debug_output $stdout
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/eval_in/http.rb', line 29 def generic_request_for(params) uri = URI params.fetch(:raw_url) path = uri.path path = '/' if path.empty? request = params.fetch(:request_type).new(path) request['User-Agent'] = params[:user_agent] if params.key? :user_agent request.form_data = params[:form_data] if params.key? :form_data request.basic_auth uri.user, uri.password if uri.user Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https')) { |http| http.request request } end |
#get_request(raw_url, user_agent) ⇒ Object
14 15 16 17 18 |
# File 'lib/eval_in/http.rb', line 14 def get_request(raw_url, user_agent) generic_request_for raw_url: raw_url, request_type: Net::HTTP::Get, user_agent: user_agent end |
#jsonify_url(url) ⇒ Object
40 41 42 43 44 |
# File 'lib/eval_in/http.rb', line 40 def jsonify_url(url) uri = URI(url) uri.path = Pathname.new(uri.path).sub_ext('.json').to_s uri.to_s end |
#post_request(raw_url, form_data, user_agent) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/eval_in/http.rb', line 20 def post_request(raw_url, form_data, user_agent) generic_request_for raw_url: raw_url, request_type: Net::HTTP::Post, user_agent: user_agent, form_data: form_data end |