survey-gizmo-ruby 5.0.4 → 6.0.2

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: c2d8dfa46ed2f287166d32c156466b1ff39d84b7
4
- data.tar.gz: c22d6cb33d3e3a57fe6d848e33011dd9c5f860ad
3
+ metadata.gz: 30f8503c9d46c13e9b4e6eb1d4f43b590b3190b9
4
+ data.tar.gz: 00583ecebd74b93a0d6c9111860f45ef8b79e289
5
5
  SHA512:
6
- metadata.gz: 89cda081f559f84fb5c19493ddb11e2f48bd0d8c4ff26d76ab6f4d8320428dc5dbfc7561cbbf929a67fb4217cae391414b269eeb6a330c2a7fb3f9549d1986eb
7
- data.tar.gz: 06cac087f8f21a42fe5a6e2c535d0e407fac2d86fa39967778942e68ce469419dadb7e56308a47a95e48c1e87d5241788d9465792b7356d48805bf2372995f2d
6
+ metadata.gz: 4332bf1ec4094d68e58866578c2a1b6a31755e0d59127c162502cf73a7e47d7dab52dddbbce4a1b24dcdbdf0f2070896f4e7c48b283f8780a2c74ebe264dbd87
7
+ data.tar.gz: 8569ffac734405c8e1d54afbdd2c458dfdbd609a35650b676708c508e64c7d45370e18a49be0ee2b43a691700e2c4ef3077abec2311dcdc5bc57e80613ee85d7
data/README.md CHANGED
@@ -8,6 +8,10 @@ Currently supports SurveyGizmo API **v4** (default) and **v3**.
8
8
 
9
9
  ## Versions
10
10
 
11
+ ### Major Changes in 6.x
12
+ * **BREAKING CHANGE**: SurveyGizmo changed the authentication so you need to configure `api_token` and `api_token_secret` instead of user and password.
13
+ * **BREAKING CHANGE**: Pester has been removed as the retry source in favor of Faraday's `Request::Retry`.
14
+
11
15
  ### Major Changes in 5.x
12
16
 
13
17
  * **BREAKING CHANGE**: `.all` returns an `Enumerator`, not an `Array`. This will break your code if you are using the return value of `.all` without iterating over it.
@@ -47,8 +51,8 @@ require 'survey-gizmo-ruby'
47
51
 
48
52
  # Configure your credentials
49
53
  SurveyGizmo.configure do |config|
50
- config.user = 'still_tippin@woodgraingrip.com'
51
- config.password = 'it_takes_grindin_to_be_a_king'
54
+ config.api_token = 'still_tippin_woodgraingrip'
55
+ config.api_token_secret = 'it_takes_grindin_to_be_a_king'
52
56
 
53
57
  # Optional - Defaults to v4, but you can probably set to v3 safely if you suspect a bug in v4
54
58
  config.api_version = 'v4'
@@ -61,32 +65,28 @@ SurveyGizmo.configure do |config|
61
65
 
62
66
  # Optional - Defaults to 300 seconds
63
67
  config.timeout_seconds = 600
68
+
69
+ # Optional - Defaults to 3 retries with a 60 second delay interval
70
+ config.retry_attempts = 3
71
+ config.retry_interval = 60
64
72
  end
65
73
  ```
66
74
 
67
- ### Retries
75
+ `api_token` and `api_token_secret` can be read from environment variables, in which case you would set them like this:
68
76
 
69
- The [Pester](https://github.com/lumoslabs/pester) gem is used to manage retry strategies. By default it will be configured to handle 1 retry with a 60 second timeout upon encountering basic net timeouts and rate limit errors, which is enough for most people's needs.
77
+ ```bash
78
+ $ export SURVEYGIZMO_API_TOKEN=till_tippin_woodgraingrip
79
+ $ export SURVEYGIZMO_API_TOKEN_SECRET=it_takes_grindin_to_be_a_king
80
+ $ bundle exec ruby whatever
81
+ ```
70
82
 
71
- If, however, you want to specify more retries, a longer backoff, new classes to retry on, or otherwise get fancy with the retry strategy, you can configured Pester directly. SurveyGizmo API calls are executed in Pester's `survey_gizmo_ruby` environment, so anything you configure there will apply to all your requests.
83
+ And then your ruby code just has to make sure to call
72
84
 
73
85
  ```ruby
74
- # For example, to change the retry interval, max attempts, or exception classes to be retried:
75
- Pester.configure do |config|
76
- # Retry 10 times
77
- config.environments[:survey_gizmo_ruby][:max_attempts] = 10
78
- # Backoff for 2 minutes
79
- config.environments[:survey_gizmo_ruby][:delay_interval] = 120
80
- # Retry different exception classes
81
- config.environments[:survey_gizmo_ruby][:retry_error_classes] = [MyExceptionClass, MyOtherExceptionClass]
82
- end
86
+ SurveyGizmo.configure
87
+ ````
83
88
 
84
- # To set Pester to retry on ALL exception classes, do this:
85
- # (use with caution! Can include exceptions Rails likes to throw on SIGHUP)
86
- Pester.configure do |config|
87
- config.environments[:survey_gizmo_ruby][:retry_error_classes] = nil
88
- end
89
- ```
89
+ once at some point.
90
90
 
91
91
  ## Usage
92
92
 
@@ -11,7 +11,6 @@ require 'digest/md5'
11
11
  require 'faraday'
12
12
  require 'faraday_middleware'
13
13
  require 'logger'
14
- require 'pester'
15
14
  require 'virtus'
16
15
 
17
16
  path = File.join(File.expand_path(File.dirname(__FILE__)), 'survey_gizmo')
@@ -10,48 +10,12 @@ module SurveyGizmo
10
10
  def configure
11
11
  @configuration ||= Configuration.new
12
12
  yield(configuration) if block_given?
13
- configure_pester
14
13
  end
15
14
 
16
15
  def reset!
17
16
  self.configuration = Configuration.new
18
- Pester.configure { |c| c.environments[:survey_gizmo_ruby] = nil }
19
- configure_pester
20
17
  Connection.reset!
21
18
  end
22
-
23
- private
24
-
25
- def configure_pester
26
- default_config = {
27
- on_retry: Pester::Behaviors::Sleep::Constant,
28
- logger: configuration.logger,
29
- max_attempts: 2,
30
- delay_interval: 60,
31
- retry_error_classes: retryables
32
- }
33
-
34
- Pester.configure do |c|
35
- if c.environments[:survey_gizmo_ruby].nil?
36
- c.environments[:survey_gizmo_ruby] = default_config
37
- else
38
- default_config.each { |k,v| c.environments[:survey_gizmo_ruby][k] ||= v unless k == :retry_error_classes }
39
-
40
- # Don't set :retry_error_classes to something when user has configured nothing
41
- if c.environments[:survey_gizmo_ruby][:retry_error_classes].nil? && !c.environments[:survey_gizmo_ruby].has_key?(:retry_error_classes)
42
- c.environments[:survey_gizmo_ruby][:retry_error_classes] = retryables
43
- end
44
- end
45
- end
46
- end
47
-
48
- def retryables
49
- [
50
- Net::ReadTimeout,
51
- Faraday::Error::TimeoutError,
52
- SurveyGizmo::RateLimitExceededError
53
- ]
54
- end
55
19
  end
56
20
 
57
21
  class Configuration
@@ -59,22 +23,35 @@ module SurveyGizmo
59
23
  DEFAULT_API_VERSION = 'v4'
60
24
  DEFAULT_RESULTS_PER_PAGE = 50
61
25
  DEFAULT_TIMEOUT_SECONDS = 300
26
+ DEFAULT_RETRIES = 3
27
+ DEFAULT_RETRY_INTERVAL = 60
62
28
 
63
- attr_accessor :user
64
- attr_accessor :password
29
+ attr_accessor :api_token
30
+ attr_accessor :api_token_secret
65
31
 
66
32
  attr_accessor :api_debug
67
33
  attr_accessor :api_url
68
34
  attr_accessor :api_version
69
35
  attr_accessor :logger
70
36
  attr_accessor :results_per_page
37
+
71
38
  attr_accessor :timeout_seconds
39
+ attr_accessor :retry_attempts
40
+ attr_accessor :retry_interval
41
+
72
42
 
73
43
  def initialize
44
+ @api_token = ENV['SURVEYGIZMO_API_TOKEN'] || nil
45
+ @api_token_secret = ENV['SURVEYGIZMO_API_TOKEN_SECRET'] || nil
46
+
74
47
  @api_url = DEFAULT_REST_API_URL
75
48
  @api_version = DEFAULT_API_VERSION
76
49
  @results_per_page = DEFAULT_RESULTS_PER_PAGE
50
+
77
51
  @timeout_seconds = DEFAULT_TIMEOUT_SECONDS
52
+ @retry_attempts = DEFAULT_RETRIES
53
+ @retry_interval = DEFAULT_RETRY_INTERVAL
54
+
78
55
  @logger = SurveyGizmo::Logger.new(STDOUT)
79
56
  @api_debug = ENV['GIZMO_DEBUG'].to_s =~ /^(true|t|yes|y|1)$/i
80
57
  end
@@ -14,19 +14,37 @@ module SurveyGizmo
14
14
  def connection
15
15
  options = {
16
16
  url: SurveyGizmo.configuration.api_url,
17
- params: { 'user:md5' => "#{SurveyGizmo.configuration.user}:#{Digest::MD5.hexdigest(SurveyGizmo.configuration.password)}" },
17
+ params: {
18
+ api_token: SurveyGizmo.configuration.api_token,
19
+ api_token_secret: SurveyGizmo.configuration.api_token_secret
20
+ },
18
21
  request: {
19
22
  timeout: SurveyGizmo.configuration.timeout_seconds,
20
23
  open_timeout: SurveyGizmo.configuration.timeout_seconds
21
24
  }
22
25
  }
23
26
 
27
+ retry_options = {
28
+ max: SurveyGizmo.configuration.retry_attempts,
29
+ interval: SurveyGizmo.configuration.retry_interval,
30
+ exceptions: [
31
+ SurveyGizmo::BadResponseError,
32
+ SurveyGizmo::RateLimitExceededError,
33
+ Errno::ETIMEDOUT,
34
+ Net::ReadTimeout,
35
+ Faraday::Error::TimeoutError,
36
+ 'Timeout::Error',
37
+ 'Error::TimeoutError'
38
+ ]
39
+ }
40
+
24
41
  @connection ||= Faraday.new(options) do |connection|
42
+ connection.request :retry, retry_options
25
43
  connection.request :url_encoded
26
44
 
27
45
  connection.response :parse_survey_gizmo_data
28
46
  connection.response :pester_survey_gizmo
29
- connection.response :logger, @logger, bodies: true if SurveyGizmo.configuration.api_debug
47
+ connection.response :logger, SurveyGizmo.configuration.logger, bodies: true if SurveyGizmo.configuration.api_debug
30
48
  connection.response :json, content_type: /\bjson$/
31
49
 
32
50
  connection.adapter Faraday.default_adapter
@@ -6,12 +6,10 @@ module SurveyGizmo
6
6
  Faraday::Response.register_middleware(pester_survey_gizmo: self)
7
7
 
8
8
  def call(environment)
9
- Pester.survey_gizmo_ruby.retry do
10
- @app.call(environment).on_complete do |response|
11
- fail RateLimitExceededError if response.status == 429
12
- fail BadResponseError, "Bad response code #{response.status} in #{response.inspect}" unless response.status == 200
13
- fail BadResponseError, response.body['message'] unless response.body['result_ok'] && response.body['result_ok'].to_s =~ /^true$/i
14
- end
9
+ @app.call(environment).on_complete do |response|
10
+ fail RateLimitExceededError if response.status == 429
11
+ fail BadResponseError, "Bad response code #{response.status} in #{response.inspect}" unless response.status == 200
12
+ fail BadResponseError, response.body['message'] unless response.body['result_ok'] && response.body['result_ok'].to_s =~ /^true$/i
15
13
  end
16
14
  end
17
15
  end
@@ -3,6 +3,9 @@ require 'logger'
3
3
  module SurveyGizmo
4
4
  class Logger < ::Logger
5
5
  def format_message(severity, timestamp, progname, msg)
6
+ msg.gsub!(/#{Regexp.quote(SurveyGizmo.configuration.api_token)}/, '<SG_API_KEY>') if SurveyGizmo.configuration.api_token
7
+ msg.gsub!(/#{Regexp.quote(SurveyGizmo.configuration.api_token_secret)}/, '<SG_API_SECRET>') if SurveyGizmo.configuration.api_token_secret
8
+
6
9
  "#{timestamp.strftime('%Y-%m-%d %H:%M:%S')} #{severity} #{msg}\n"
7
10
  end
8
11
  end
@@ -35,10 +35,10 @@ module SurveyGizmo
35
35
  # Properties from the conditions hash (e.g. survey_id) will be added to the returned objects
36
36
  def all(conditions = {})
37
37
  fail ':all_pages and :page are mutually exclusive' if conditions[:page] && conditions[:all_pages]
38
- logger.warn('WARNING: Only retrieving first page of results!') if conditions[:page].nil? && conditions[:all_pages].nil?
38
+ logger.warn('WARNING: Only retrieving first page of results!') unless conditions[:page] || conditions[:all_pages]
39
39
 
40
40
  all_pages = conditions.delete(:all_pages)
41
- conditions[:resultsperpage] = SurveyGizmo.configuration.results_per_page unless conditions[:resultsperpage]
41
+ conditions[:resultsperpage] ||= SurveyGizmo.configuration.results_per_page
42
42
 
43
43
  Enumerator.new do |yielder|
44
44
  response = nil
@@ -78,8 +78,8 @@ module SurveyGizmo
78
78
  # @route is either a hash to be used directly or a string from which standard routes will be built
79
79
  def routes
80
80
  fail "route not set in #{name}" unless @route
81
-
82
81
  return @route if @route.is_a?(Hash)
82
+
83
83
  routes = { create: @route }
84
84
  [:get, :update, :delete].each { |k| routes[k] = @route + '/:id' }
85
85
  routes
@@ -130,7 +130,7 @@ module SurveyGizmo
130
130
 
131
131
  ### BELOW HERE ARE INSTANCE METHODS ###
132
132
 
133
- # If we have an id, it's an update, because we already know the surveygizmo assigned id
133
+ # If we have an id, it's an update because we already know the surveygizmo assigned id
134
134
  # Returns itself if successfully saved, but with attributes (like id) added by SurveyGizmo
135
135
  def save
136
136
  method, path = id ? [:post, :update] : [:put, :create]
@@ -1,3 +1,3 @@
1
1
  module SurveyGizmo
2
- VERSION = '5.0.4'
2
+ VERSION = '6.0.2'
3
3
  end
@@ -4,8 +4,8 @@ require 'survey_gizmo/configuration'
4
4
  describe SurveyGizmo::Configuration do
5
5
  before(:each) do
6
6
  SurveyGizmo.configure do |config|
7
- config.user = 'test@test.com'
8
- config.password = 'password'
7
+ config.api_token = 'token'
8
+ config.api_token_secret = 'doken'
9
9
  end
10
10
  end
11
11
 
@@ -15,10 +15,10 @@ describe SurveyGizmo::Configuration do
15
15
 
16
16
  it 'should allow changing user and pass' do
17
17
  SurveyGizmo.configure do |config|
18
- config.user = 'slimthug'
19
- config.password = 'fourfourz'
18
+ config.api_token = 'slimthug'
19
+ config.api_token_secret = 'fourfourz'
20
20
  end
21
21
 
22
- expect(SurveyGizmo::Connection.send(:connection).params).to eq({ 'user:md5'=>'slimthug:836fd7e2961a094c01cb7ba78bac6a06' })
22
+ expect(SurveyGizmo::Connection.send(:connection).params).to eq('api_token' => 'slimthug', 'api_token_secret' => 'fourfourz')
23
23
  end
24
24
  end
data/spec/spec_helper.rb CHANGED
@@ -12,13 +12,13 @@ RSpec.configure do |config|
12
12
 
13
13
  config.before(:each) do
14
14
  SurveyGizmo.configure do |config|
15
- config.user = 'test@test.com'
16
- config.password = 'password'
17
- config.logger.level = Logger::FATAL
18
- end
15
+ config.api_token = 'king_of_the_whirled'
16
+ config.api_token_secret = 'dreamword'
19
17
 
20
- Pester.configure do |config|
21
- config.environments[:survey_gizmo_ruby][:logger] = ::Logger.new(nil)
18
+ config.retry_attempts = 0
19
+ config.retry_interval = 0
20
+
21
+ config.logger.level = Logger::FATAL
22
22
  end
23
23
 
24
24
  @base = "#{SurveyGizmo.configuration.api_url}/#{SurveyGizmo.configuration.api_version}"
@@ -21,7 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'faraday', '>= 0.9.1', '~> 0.9'
22
22
  gem.add_dependency 'faraday_middleware', '~> 0.10'
23
23
  gem.add_dependency 'i18n'
24
- gem.add_dependency 'pester', '>= 1.0.0'
25
24
  gem.add_dependency 'virtus', '>= 1.0.0'
26
25
 
27
26
  gem.add_development_dependency 'rspec', '~> 2.11.0'
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: 5.0.4
4
+ version: 6.0.2
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-01-26 00:00:00.000000000 Z
14
+ date: 2016-02-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -103,20 +103,6 @@ dependencies:
103
103
  - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
- - !ruby/object:Gem::Dependency
107
- name: pester
108
- requirement: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: 1.0.0
113
- type: :runtime
114
- prerelease: false
115
- version_requirements: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: 1.0.0
120
106
  - !ruby/object:Gem::Dependency
121
107
  name: virtus
122
108
  requirement: !ruby/object:Gem::Requirement