class Rubeetup::RequestSender

Responsible for sending responses over an http connection

Constants

HOST

Destination host

Attributes

http[R]

@return [Net::HTTP] this Sender’s http connection

request[R]

@return [Rubeetup::Request] this Sender’s request job

response_data[R]

@return [Net::HTTPResponse] the response data obtained from the request

Public Class Methods

new() click to toggle source
# File lib/rubeetup/request_sender.rb, line 30
def initialize
  @http = Net::HTTP.new(HOST)
end

Public Instance Methods

get_response(request) click to toggle source

Performs a request and returns back the response @param [Rubeetup::Request] request the request instance to be sent @return [Array<Rubeetup::ResponseWrapper>] the request response

# File lib/rubeetup/request_sender.rb, line 39
def get_response(request)
  @request = request
  @response_data = fetch
  response_class.new(self).data
end

Private Instance Methods

encode_resources() click to toggle source
# File lib/rubeetup/request_sender.rb, line 72
def encode_resources
  request.multipart.call(request.options)
end
fetch() click to toggle source
# File lib/rubeetup/request_sender.rb, line 47
def fetch
  request.http_verb == :post ? (req = post) : (req = get_or_delete)
  http.request(req)
end
get_or_delete() click to toggle source
# File lib/rubeetup/request_sender.rb, line 52
def get_or_delete
  path = "#{request.method_path}?#{stringify(request.options)}"
  http_method_class.new(path)
end
handler_class() click to toggle source
# File lib/rubeetup/request_sender.rb, line 89
def handler_class
  Typhoeus::Request
end
http_method_class() click to toggle source
# File lib/rubeetup/request_sender.rb, line 76
def http_method_class
  class_name = request.http_verb.capitalize.to_s
  if request.multipart
    Net::HTTP::Post::Multipart
  else
    Net::HTTP.const_get(class_name.to_sym)
  end
end
multipart_post() click to toggle source
# File lib/rubeetup/request_sender.rb, line 67
def multipart_post
  encode_resources
  http_method_class.new(request.method_path, request.options)
end
post() click to toggle source
# File lib/rubeetup/request_sender.rb, line 57
def post
  request.multipart ? multipart_post : url_encoded_post
end
response_class() click to toggle source
# File lib/rubeetup/request_sender.rb, line 85
def response_class
  Rubeetup::RequestResponse
end
url_encoded_post() click to toggle source
# File lib/rubeetup/request_sender.rb, line 61
def url_encoded_post
  req = http_method_class.new(request.method_path)
  req.set_form_data(request.options)
  req
end