module EvalIn::HTTP

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

Public Instance Methods

generic_request_for(params) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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