Class: SurveyGizmo::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/survey_gizmo/configuration.rb

Constant Summary collapse

DEFAULT_API_VERSION =
'v4'
DEFAULT_RESULTS_PER_PAGE =
50
DEFAULT_TIMEOUT_SECONDS =
300
DEFAULT_REGION =
:us
DEFAULT_LOCALE =
'English'
REGION_INFO =
{
  us: {
    url: 'https://restapi.surveygizmo.com',
    locale: 'Eastern Time (US & Canada)'
  },
  eu: {
    url: 'https://restapi.surveygizmo.eu',
    locale: 'UTC'
  }
}
DEFAULT_RETRIABLE_PARAMS =
{
  base_interval: 60,
  max_interval: 300,
  rand_factor: 0,
  tries: 4,
  on: [
    Errno::ETIMEDOUT,
    Faraday::ClientError,
    Net::ReadTimeout,
    SurveyGizmo::BadResponseError,
    SurveyGizmo::RateLimitExceededError
  ],
  on_retry: Proc.new do |exception, tries|
    SurveyGizmo.configuration.logger.warn("Retrying after #{exception.class}: #{tries} attempts.")
  end
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/survey_gizmo/configuration.rb', line 94

def initialize
  @api_token = ENV['SURVEYGIZMO_API_TOKEN'] || nil
  @api_token_secret = ENV['SURVEYGIZMO_API_TOKEN_SECRET'] || nil

  @api_version = DEFAULT_API_VERSION
  @results_per_page = DEFAULT_RESULTS_PER_PAGE
  @timeout_seconds = DEFAULT_TIMEOUT_SECONDS
  @retriable_params = DEFAULT_RETRIABLE_PARAMS
  @locale = DEFAULT_LOCALE
  self.region = DEFAULT_REGION

  @logger = SurveyGizmo::Logger.new(STDOUT)
  @api_debug = ENV['GIZMO_DEBUG'].to_s =~ /^(true|t|yes|y|1)$/i
end

Instance Attribute Details

#api_debugObject

Returns the value of attribute api_debug.



81
82
83
# File 'lib/survey_gizmo/configuration.rb', line 81

def api_debug
  @api_debug
end

#api_time_zoneObject

Returns the value of attribute api_time_zone.



83
84
85
# File 'lib/survey_gizmo/configuration.rb', line 83

def api_time_zone
  @api_time_zone
end

#api_tokenObject

Returns the value of attribute api_token.



78
79
80
# File 'lib/survey_gizmo/configuration.rb', line 78

def api_token
  @api_token
end

#api_token_secretObject

Returns the value of attribute api_token_secret.



79
80
81
# File 'lib/survey_gizmo/configuration.rb', line 79

def api_token_secret
  @api_token_secret
end

#api_urlObject

Returns the value of attribute api_url.



82
83
84
# File 'lib/survey_gizmo/configuration.rb', line 82

def api_url
  @api_url
end

#api_versionObject

Returns the value of attribute api_version.



84
85
86
# File 'lib/survey_gizmo/configuration.rb', line 84

def api_version
  @api_version
end

#localeObject

Returns the value of attribute locale.



89
90
91
# File 'lib/survey_gizmo/configuration.rb', line 89

def locale
  @locale
end

#loggerObject

Returns the value of attribute logger.



85
86
87
# File 'lib/survey_gizmo/configuration.rb', line 85

def logger
  @logger
end

#results_per_pageObject

Returns the value of attribute results_per_page.



86
87
88
# File 'lib/survey_gizmo/configuration.rb', line 86

def results_per_page
  @results_per_page
end

#retriable_paramsObject

Returns the value of attribute retriable_params.



88
89
90
# File 'lib/survey_gizmo/configuration.rb', line 88

def retriable_params
  @retriable_params
end

#retry_attemptsObject

TODO Deprecated; remove in 7.0



91
92
93
# File 'lib/survey_gizmo/configuration.rb', line 91

def retry_attempts
  @retry_attempts
end

#retry_intervalObject

Returns the value of attribute retry_interval.



92
93
94
# File 'lib/survey_gizmo/configuration.rb', line 92

def retry_interval
  @retry_interval
end

#timeout_secondsObject

Returns the value of attribute timeout_seconds.



87
88
89
# File 'lib/survey_gizmo/configuration.rb', line 87

def timeout_seconds
  @timeout_seconds
end

Instance Method Details

#region=(region) ⇒ Object

Raises:

  • (ArgumentError)


109
110
111
112
113
114
115
# File 'lib/survey_gizmo/configuration.rb', line 109

def region=(region)
  region_infos = REGION_INFO[region]
  raise ArgumentError.new("Unknown region: #{region}") unless region_infos

  @api_url = region_infos[:url]
  @api_time_zone = region_infos[:locale]
end