Class: SurveyGizmo::Configuration
- Inherits:
-
Object
- Object
- SurveyGizmo::Configuration
- 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
-
#api_debug ⇒ Object
Returns the value of attribute api_debug.
-
#api_time_zone ⇒ Object
Returns the value of attribute api_time_zone.
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#api_token_secret ⇒ Object
Returns the value of attribute api_token_secret.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#results_per_page ⇒ Object
Returns the value of attribute results_per_page.
-
#retriable_params ⇒ Object
Returns the value of attribute retriable_params.
-
#retry_attempts ⇒ Object
TODO Deprecated; remove in 7.0.
-
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
-
#timeout_seconds ⇒ Object
Returns the value of attribute timeout_seconds.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #region=(region) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_debug ⇒ Object
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_zone ⇒ Object
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_token ⇒ Object
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_secret ⇒ Object
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_url ⇒ Object
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_version ⇒ Object
Returns the value of attribute api_version.
84 85 86 |
# File 'lib/survey_gizmo/configuration.rb', line 84 def api_version @api_version end |
#locale ⇒ Object
Returns the value of attribute locale.
89 90 91 |
# File 'lib/survey_gizmo/configuration.rb', line 89 def locale @locale end |
#logger ⇒ Object
Returns the value of attribute logger.
85 86 87 |
# File 'lib/survey_gizmo/configuration.rb', line 85 def logger @logger end |
#results_per_page ⇒ Object
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_params ⇒ Object
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_attempts ⇒ Object
TODO Deprecated; remove in 7.0
91 92 93 |
# File 'lib/survey_gizmo/configuration.rb', line 91 def retry_attempts @retry_attempts end |
#retry_interval ⇒ Object
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_seconds ⇒ Object
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
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 |