Sha256: c2e52d7b57df6fe411dd015df7d2a576fbf0469bcd62032ceb1eb77703be06dc
Contents?: true
Size: 1.22 KB
Versions: 7
Compression:
Stored size: 1.22 KB
Contents
require 'active_support/benchmarkable' require 'net/http' module Europeana module API ## # Europeana API request class Request include ActiveSupport::Benchmarkable # Request URI attr_reader :uri # API response attr_reader :response # @param [URI] def initialize(uri) @uri = uri end # @return (see Net::HTTP#request) def execute http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) retries = Europeana::API.max_retries begin attempt = Europeana::API.max_retries - retries + 1 logger.info("[Europeana::API] Request URL: #{uri}") benchmark("[Europeana::API] Request query (attempt ##{attempt})", level: :info) do @response = http.request(request) end rescue Timeout::Error, Errno::ECONNREFUSED, EOFError retries -= 1 raise unless retries > 0 logger.warn("[Europeana::API] Network error; sleeping #{Europeana::API.retry_delay}s") sleep Europeana::API.retry_delay retry end @response end def logger Europeana::API.logger end end end end
Version data entries
7 entries across 7 versions & 1 rubygems