Class: Infostrada::BaseRequest

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/infostrada/base_request.rb

Overview

This is the class that every class making API requests must descend from. It includes HTTParty to easily support every type of HTTP request. The basic_auth is set up from the Infostrada.configuration mechanism described in the Infostrada module.

Constant Summary collapse

RETRIES =

How many times should we retry the request if Timeout::Error is raised?

5

Class Method Summary collapse

Class Method Details

.get!(path, options = {}, &block) ⇒ Object

Used with Timeout::Error rescue so we can keep trying to fetch the information after timeout.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/infostrada/base_request.rb', line 47

def self.get!(path, options = {}, &block)
  attempts = 1
  result = nil

  begin
    result = get(path, options, &block)
  rescue Timeout::Error => e
    puts "Timeout! Retrying... (#{attempts})"
    attempts += 1
    if attempts > RETRIES
      raise Infostrada::RequestError.new, 'Request timeout'
    else
      retry
    end
  end

  result
end