Sha256: 01a1793aa00c6ae26438d24c47ea864106098987c7706c1e01b19750e81e22b6
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
require 'active_support/core_ext/module/delegation' module SurveyGizmo class Connection class << self def get(route) Retriable.retriable(retriable_args) { connection.get(route) } end def post(route, params) Retriable.retriable(retriable_args) { connection.post(route, params) } end def put(route, params) Retriable.retriable(retriable_args) { connection.put(route, params) } end def delete(route) Retriable.retriable(retriable_args) { connection.delete(route) } end def reset! @connection = nil end private def connection faraday_options = { url: SurveyGizmo.configuration.api_url, params: { api_token: SurveyGizmo.configuration.api_token, api_token_secret: SurveyGizmo.configuration.api_token_secret }, request: { timeout: SurveyGizmo.configuration.timeout_seconds, open_timeout: SurveyGizmo.configuration.timeout_seconds } } @connection ||= Faraday.new(faraday_options) do |connection| connection.request :url_encoded connection.response :parse_survey_gizmo_data connection.response :json, content_type: /\bjson$/ connection.response :logger, SurveyGizmo.configuration.logger, bodies: true if SurveyGizmo.configuration.api_debug connection.adapter Faraday.default_adapter end end def retriable_args { interval: SurveyGizmo.configuration.retry_interval, tries: SurveyGizmo.configuration.retry_attempts + 1, on: [ SurveyGizmo::BadResponseError, SurveyGizmo::RateLimitExceededError, Errno::ETIMEDOUT, Net::ReadTimeout, Faraday::Error::ParsingError, Faraday::Error::TimeoutError ] } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
survey-gizmo-ruby-6.2.6 | lib/survey_gizmo/connection.rb |