Class: Rpruby::HttpClient Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rpruby/http_client.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initializeHttpClient

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HttpClient.



6
7
8
# File 'lib/rpruby/http_client.rb', line 6

def initialize
  create_client
end

Instance Method Details

#send_request(verb, path, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rpruby/http_client.rb', line 10

def send_request(verb, path, options = {})
  path.prepend("/api/v1/#{Settings.instance.project}/")
  path.prepend(origin) unless use_persistent?
  3.times do
    begin
      response = @http.request(verb, path, options)
    rescue StandardError => e
      puts "Request #{request_info(verb, path)} produced an exception:"
      puts e
      recreate_client
    else
      return response.parse(:json) if response.status.success?

      message = "Request #{request_info(verb, path)} returned code #{response.code}."
      message << " Response:\n#{response}" unless response.to_s.empty?
      puts message
    end
  end
end