Class: FederalRegister::Client
- Inherits:
-
Object
- Object
- FederalRegister::Client
show all
- Defined in:
- lib/federal_register/client.rb
Defined Under Namespace
Classes: BadRequest, FaradayResponseWrapper, GatewayTimeout, RecordNotFound, ResponseError, ServerError, ServiceUnavailable
Class Method Summary
collapse
Class Method Details
.base_uri ⇒ Object
29
30
31
|
# File 'lib/federal_register/client.rb', line 29
def self.base_uri
'https://www.federalregister.gov/api/v1'
end
|
.get(path, options = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/federal_register/client.rb', line 33
def self.get(path, options={})
@connection = Faraday.new(url: base_uri) do |conn|
conn.request :url_encoded
conn.response :logger if ENV['DEBUG'] conn.adapter Faraday.default_adapter
conn.options.open_timeout = ENV['FARADAY_OPEN_TIMEOUT'].try(:to_i) || 2
conn.options.timeout = 10
end
response = @connection.get(strip_protocol_and_host(path), options[:query] || {})
case response.status
when 200
FaradayResponseWrapper.new(JSON.parse(response.body))
when 400
raise BadRequest.new(response)
when 404
raise RecordNotFound.new(response)
when 500
raise ServerError.new(response)
when 503
raise ServiceUnavailable.new(response)
when 504
raise GatewayTimeout.new(response)
else
raise Faraday::Error.new(nil, response)
end
end
|