Sha256: b8553a290ca53b315f2285613e156730bff6da55a3d611d80e6c9407ac7a3266

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'active_support/core_ext/module/delegation'

module SurveyGizmo
  class Connection
    class << self
      delegate :put, :get, :delete, :post, to: :connection

      def reset!
        @connection = nil
      end

      private

      def connection
        options = {
          url: SurveyGizmo.configuration.api_url,
          params: { 'user:md5' => "#{SurveyGizmo.configuration.user}:#{Digest::MD5.hexdigest(SurveyGizmo.configuration.password)}" },
          request: {
            timeout: SurveyGizmo.configuration.timeout_seconds,
            open_timeout: SurveyGizmo.configuration.timeout_seconds
          }
        }

        @connection ||= Faraday.new(options) do |connection|
          connection.request :url_encoded

          connection.response :parse_survey_gizmo_data
          connection.response :pester_survey_gizmo
          connection.response :logger, @logger, bodies: true if SurveyGizmo.configuration.api_debug
          connection.response :json, content_type: /\bjson$/

          connection.adapter Faraday.default_adapter
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
survey-gizmo-ruby-5.0.4 lib/survey_gizmo/connection.rb