Class: Ace::Support::Models::Atoms::ApiFetcher
- Inherits:
-
Object
- Object
- Ace::Support::Models::Atoms::ApiFetcher
- Defined in:
- lib/ace/support/models/atoms/api_fetcher.rb
Overview
Fetches data from the models.dev API using Faraday (ADR-010 compliant)
Constant Summary collapse
- API_URL =
"https://models.dev/api.json"- FIXTURE_JSON_ENV =
"ACE_MODELS_FIXTURE_JSON"- API_URL_ENV =
"ACE_MODELS_API_URL"- TIMEOUT =
30- OPEN_TIMEOUT =
10- MAX_RETRIES =
2- RETRY_INTERVAL =
0.5
Class Method Summary collapse
-
.fetch(url = nil) ⇒ String
Fetch the API JSON.
Class Method Details
.fetch(url = nil) ⇒ String
Fetch the API JSON
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ace/support/models/atoms/api_fetcher.rb', line 26 def fetch(url = nil) fixture_json = ENV[FIXTURE_JSON_ENV] return fixture_json unless fixture_json.to_s.strip.empty? resolved_url = url || ENV[API_URL_ENV] || API_URL response = connection.get(resolved_url) unless response.success? raise ApiError.new( "API request failed: #{response.status} #{response.reason_phrase}", status_code: response.status ) end response.body rescue Faraday::TimeoutError => e raise NetworkError, "Request timed out: #{e.}" rescue Faraday::ConnectionFailed => e raise NetworkError, "Connection failed: #{e.}" rescue Faraday::SSLError => e raise NetworkError, "SSL error: #{e.}" rescue Faraday::Error => e raise NetworkError, "Network error fetching API: #{e.}" end |