survey-gizmo-ruby 6.1.2 → 6.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f278de3b358b26c742f439c74da14b9cede1df7
4
- data.tar.gz: f2fa277155e842c93dc98c9b927cb129893b2311
3
+ metadata.gz: 0d6ac831f23cde9a33a402318e0156e444e8a4fe
4
+ data.tar.gz: 26c120f520f737920fb22d55344210dd06b31875
5
5
  SHA512:
6
- metadata.gz: bec15907fc482a6ae12fd09aff10a7eb68723eb8ec4cbdc38234348da4c52aa6ecc80eac0877c78d9ef6fec4a797672a5c81f05e6969e853a58c2eed8b8c6c44
7
- data.tar.gz: 698358708e14e25993e1ff3bc075c66f3f9202d44054dddbce29f770ae76bbd0c4618c89eac6d663f8997a78a02ee2b75b0d1cff619223bc627f0c0744265c8e
6
+ metadata.gz: f39778fccf60c152b5b53856f7289382b95a727da34900f6bc8ebcba4be621a8943b3c7d4c5f86e9b12ca439668d8423b66471dfcc86f0f29f93a5356032db93
7
+ data.tar.gz: fa8e6251c2634bba965bf2097be1f9f5937acb2c28f339733a5ccb6c889cfaf6dd3d18d26c19b7dd13b17a29cb4dceaef63d99fdce7fab77e8aaec93ef90e6e3
data/CHANGELOG.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ## Major Changes in 6.x
4
4
  * **BREAKING CHANGE**: SurveyGizmo changed the authentication so you need to configure `api_token` and `api_token_secret` instead of user and password.
5
5
  * **BREAKING CHANGE**: Pester has been removed as the retry source in favor of `Retriable`.
6
+ * FEATURE: `Configuration#region` will configure the region to use the corresponding api and time zone.
6
7
 
7
8
  ## Major Changes in 5.x
8
9
 
data/README.md CHANGED
@@ -29,8 +29,8 @@ SurveyGizmo.configure do |config|
29
29
  # Optional - Defaults to v4, but you can probably set to v3 safely if you suspect a bug in v4
30
30
  config.api_version = 'v4'
31
31
 
32
- # Optional - Set if you need to hit a different base URL (e.g. the .eu domain)
33
- config.api_url = 'https://restapi.surveygizmo.eu'
32
+ # Optional - Set if you need to hit a different region (e.g. the .eu domain)
33
+ config.region = :eu
34
34
 
35
35
  # Optional - Defaults to 50, maximum 500. Setting too high may cause SurveyGizmo to start throwing timeouts.
36
36
  config.results_per_page = 100
@@ -11,6 +11,7 @@ require 'digest/md5'
11
11
  require 'faraday'
12
12
  require 'faraday_middleware'
13
13
  require 'logger'
14
+ require 'net/http'
14
15
  require 'retriable'
15
16
  require 'virtus'
16
17
 
@@ -10,7 +10,7 @@ module SurveyGizmo::API
10
10
  {
11
11
  field: 'datesubmitted',
12
12
  operator: '>=',
13
- value: time.in_time_zone(SurveyGizmo::Configuration::SURVEYGIZMO_TIME_ZONE).strftime('%Y-%m-%d %H:%M:%S')
13
+ value: time.in_time_zone(SurveyGizmo.configuration.api_time_zone).strftime('%Y-%m-%d %H:%M:%S')
14
14
  }
15
15
  end
16
16
 
@@ -19,19 +19,30 @@ module SurveyGizmo
19
19
  end
20
20
 
21
21
  class Configuration
22
- DEFAULT_REST_API_URL = 'https://restapi.surveygizmo.com'
23
22
  DEFAULT_API_VERSION = 'v4'
24
23
  DEFAULT_RESULTS_PER_PAGE = 50
25
24
  DEFAULT_TIMEOUT_SECONDS = 300
26
25
  DEFAULT_RETRIES = 3
27
26
  DEFAULT_RETRY_INTERVAL = 60
28
- SURVEYGIZMO_TIME_ZONE = 'Eastern Time (US & Canada)'
27
+ DEFAULT_REGION = :us
28
+
29
+ REGION_INFO = {
30
+ us: {
31
+ url: 'https://restapi.surveygizmo.com',
32
+ locale: 'Eastern Time (US & Canada)'
33
+ },
34
+ eu: {
35
+ url: 'https://restapi.surveygizmo.eu',
36
+ locale: 'Berlin'
37
+ }
38
+ }
29
39
 
30
40
  attr_accessor :api_token
31
41
  attr_accessor :api_token_secret
32
42
 
33
43
  attr_accessor :api_debug
34
44
  attr_accessor :api_url
45
+ attr_accessor :api_time_zone
35
46
  attr_accessor :api_version
36
47
  attr_accessor :logger
37
48
  attr_accessor :results_per_page
@@ -45,16 +56,25 @@ module SurveyGizmo
45
56
  @api_token = ENV['SURVEYGIZMO_API_TOKEN'] || nil
46
57
  @api_token_secret = ENV['SURVEYGIZMO_API_TOKEN_SECRET'] || nil
47
58
 
48
- @api_url = DEFAULT_REST_API_URL
49
59
  @api_version = DEFAULT_API_VERSION
50
60
  @results_per_page = DEFAULT_RESULTS_PER_PAGE
51
61
 
52
62
  @timeout_seconds = DEFAULT_TIMEOUT_SECONDS
53
63
  @retry_attempts = DEFAULT_RETRIES
54
64
  @retry_interval = DEFAULT_RETRY_INTERVAL
65
+ self.region = DEFAULT_REGION
55
66
 
56
67
  @logger = SurveyGizmo::Logger.new(STDOUT)
57
68
  @api_debug = ENV['GIZMO_DEBUG'].to_s =~ /^(true|t|yes|y|1)$/i
58
69
  end
70
+
71
+ def region=(region)
72
+ region_infos = REGION_INFO[region]
73
+ ArgumentError.new("Unknown region: #{region}") unless region_infos
74
+
75
+ @api_url = region_infos[:url]
76
+ @api_time_zone = region_infos[:locale]
77
+ end
59
78
  end
79
+
60
80
  end
@@ -42,7 +42,7 @@ module SurveyGizmo
42
42
  # SurveyGizmo returns date information using US/Eastern timezone but does not provide time zone information.
43
43
  # See https://apihelp.surveygizmo.com/help/article/link/surveyresponse-returned-fields#examplereturns
44
44
  TIME_FIELDS.each do |time_key|
45
- datum[time_key] = ActiveSupport::TimeZone.new(SurveyGizmo::Configuration::SURVEYGIZMO_TIME_ZONE).parse(datum[time_key]) unless datum[time_key].blank?
45
+ datum[time_key] = ActiveSupport::TimeZone.new(SurveyGizmo.configuration.api_time_zone).parse(datum[time_key]) unless datum[time_key].blank?
46
46
  end
47
47
 
48
48
  datum.keys.grep(/^\[/).each do |key|
@@ -1,3 +1,3 @@
1
1
  module SurveyGizmo
2
- VERSION = '6.1.2'
2
+ VERSION = '6.1.3'
3
3
  end
@@ -24,4 +24,39 @@ describe SurveyGizmo::Configuration do
24
24
 
25
25
  expect(SurveyGizmo::Connection.send(:connection).params).to eq('api_token' => 'slimthug', 'api_token_secret' => 'fourfourz')
26
26
  end
27
+
28
+ describe '#region=' do
29
+ it 'should set US region by default' do
30
+ SurveyGizmo.configure
31
+ expect(SurveyGizmo.configuration.api_url).to eq('https://restapi.surveygizmo.com')
32
+ expect(SurveyGizmo.configuration.api_time_zone).to eq('Eastern Time (US & Canada)')
33
+ end
34
+
35
+ it 'should set US region with :us symbol specified' do
36
+ SurveyGizmo.configure do |config|
37
+ config.region = :us
38
+ end
39
+
40
+ expect(SurveyGizmo.configuration.api_url).to eq('https://restapi.surveygizmo.com')
41
+ expect(SurveyGizmo.configuration.api_time_zone).to eq('Eastern Time (US & Canada)')
42
+ end
43
+
44
+ it 'should set EU region with :eu symbol specified' do
45
+ SurveyGizmo.configure do |config|
46
+ config.region = :eu
47
+ end
48
+
49
+ expect(SurveyGizmo.configuration.api_url).to eq('https://restapi.surveygizmo.eu')
50
+ expect(SurveyGizmo.configuration.api_time_zone).to eq('Berlin')
51
+ end
52
+
53
+ it 'should fail with an unavailable region' do
54
+ expect {
55
+ SurveyGizmo.configure do |config|
56
+ config.region = :cz
57
+ end
58
+ }.to raise_error
59
+ end
60
+
61
+ end
27
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: survey-gizmo-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.2
4
+ version: 6.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kabari Hendrick
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-06-06 00:00:00.000000000 Z
14
+ date: 2016-06-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -267,4 +267,3 @@ test_files:
267
267
  - spec/test_json/page.json
268
268
  - spec/test_json/question.json
269
269
  - spec/test_json/survey.json
270
- has_rdoc: