survey-gizmo-ruby 6.0.3 → 6.1.0

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: 0df56a925ae1b46ab339112104842f941081b571
4
- data.tar.gz: 6492ac9c08f5398fa2722df6898738b5ec480c58
3
+ metadata.gz: c9212a1b4d700277db950e43704325fe142193b3
4
+ data.tar.gz: 5fa9f82cd2349c0bd649e56807ee8378687205c3
5
5
  SHA512:
6
- metadata.gz: ee894f64477a704f7c77139c4732c73a81d0b29ef9cc29e4f42f12034f932726fe9722276e7a2c8565b7eeb48168a99a5881dfa62020e9582074852b7997f005
7
- data.tar.gz: e56cceae702194825ed8f608efafad7c17da1266cf3957e9c934d85fe73144e05af5c145d9d1c33d2b7ceb109381ca02116d0c4770f100450b900cf4c6477347
6
+ metadata.gz: 5731f64d824843664d1dd208fc92bbf1060815d96bf25c545908018b0508167f3f955c3e021f0f6d127c15fd8e5f3321f96643cedd938f4ff25785735172b2b9
7
+ data.tar.gz: 94874505cc5d2739334cf86bde4805616eb2dd178d865eaf20cba1cf670733f870debee1b38b0ae61225db68f22c5498f677cef48915002b25c70f1b8bb9ce97
@@ -11,6 +11,7 @@ require 'digest/md5'
11
11
  require 'faraday'
12
12
  require 'faraday_middleware'
13
13
  require 'logger'
14
+ require 'retriable'
14
15
  require 'virtus'
15
16
 
16
17
  path = File.join(File.expand_path(File.dirname(__FILE__)), 'survey_gizmo')
@@ -3,7 +3,21 @@ require 'active_support/core_ext/module/delegation'
3
3
  module SurveyGizmo
4
4
  class Connection
5
5
  class << self
6
- delegate :put, :get, :delete, :post, to: :connection
6
+ def get(route)
7
+ Retriable.retriable(retriable_args) { connection.get(route) }
8
+ end
9
+
10
+ def post(route, params)
11
+ Retriable.retriable(retriable_args) { connection.post(route, params) }
12
+ end
13
+
14
+ def put(route, params)
15
+ Retriable.retriable(retriable_args) { connection.put(route, params) }
16
+ end
17
+
18
+ def delete(route)
19
+ Retriable.retriable(retriable_args) { connection.delete(route) }
20
+ end
7
21
 
8
22
  def reset!
9
23
  @connection = nil
@@ -12,7 +26,7 @@ module SurveyGizmo
12
26
  private
13
27
 
14
28
  def connection
15
- options = {
29
+ faraday_options = {
16
30
  url: SurveyGizmo.configuration.api_url,
17
31
  params: {
18
32
  api_token: SurveyGizmo.configuration.api_token,
@@ -24,31 +38,29 @@ module SurveyGizmo
24
38
  }
25
39
  }
26
40
 
27
- retry_options = {
28
- max: SurveyGizmo.configuration.retry_attempts,
41
+ @connection ||= Faraday.new(faraday_options) do |connection|
42
+ connection.request :url_encoded
43
+
44
+ connection.response :parse_survey_gizmo_data
45
+ connection.response :json, content_type: /\bjson$/
46
+ connection.response :logger, SurveyGizmo.configuration.logger, bodies: true if SurveyGizmo.configuration.api_debug
47
+
48
+ connection.adapter Faraday.default_adapter
49
+ end
50
+ end
51
+
52
+ def retriable_args
53
+ {
29
54
  interval: SurveyGizmo.configuration.retry_interval,
30
- exceptions: [
55
+ tries: SurveyGizmo.configuration.retry_attempts + 1,
56
+ on: [
31
57
  SurveyGizmo::BadResponseError,
32
58
  SurveyGizmo::RateLimitExceededError,
33
59
  Errno::ETIMEDOUT,
34
60
  Net::ReadTimeout,
35
61
  Faraday::Error::TimeoutError,
36
- 'Timeout::Error',
37
- 'Error::TimeoutError'
38
62
  ]
39
63
  }
40
-
41
- @connection ||= Faraday.new(options) do |connection|
42
- connection.request :retry, retry_options
43
- connection.request :url_encoded
44
-
45
- connection.response :parse_survey_gizmo_data
46
- connection.response :pester_survey_gizmo
47
- connection.response :logger, SurveyGizmo.configuration.logger, bodies: true if SurveyGizmo.configuration.api_debug
48
- connection.response :json, content_type: /\bjson$/
49
-
50
- connection.adapter Faraday.default_adapter
51
- end
52
64
  end
53
65
  end
54
66
  end
@@ -1,14 +1,35 @@
1
1
  require 'faraday_middleware/response_middleware'
2
2
 
3
3
  module SurveyGizmo
4
+ class RateLimitExceededError < RuntimeError; end
5
+ class BadResponseError < RuntimeError; end
6
+
4
7
  class ParseSurveyGizmo < FaradayMiddleware::ResponseMiddleware
5
8
  Faraday::Response.register_middleware(parse_survey_gizmo_data: self)
6
9
 
7
- PAGINATION_FIELDS = ['total_count', 'page', 'total_pages', 'results_per_page']
8
- TIME_FIELDS = ['datesubmitted', 'created_on', 'modified_on', 'datecreated', 'datemodified']
10
+ PAGINATION_FIELDS = [
11
+ 'page',
12
+ 'results_per_page',
13
+ 'total_count',
14
+ 'total_pages'
15
+ ]
16
+
17
+ TIME_FIELDS = [
18
+ 'created_on',
19
+ 'datecreated',
20
+ 'datemodified',
21
+ 'datesubmitted',
22
+ 'modified_on'
23
+ ]
9
24
 
10
- def parse_response?(env)
11
- true
25
+ def call(environment)
26
+ @app.call(environment).on_complete do |response|
27
+ fail RateLimitExceededError if response.status == 429
28
+ fail BadResponseError, "Bad response code #{response.status} in #{response.inspect}" unless response.status == 200
29
+ fail BadResponseError, response.body['message'] unless response.body['result_ok'] && response.body['result_ok'].to_s =~ /^true$/i
30
+
31
+ process_response(response)
32
+ end
12
33
  end
13
34
 
14
35
  define_parser do |body|
@@ -1,3 +1,3 @@
1
1
  module SurveyGizmo
2
- VERSION = '6.0.3'
2
+ VERSION = '6.1.0'
3
3
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency 'awesome_print', '~> 1'
21
21
  gem.add_dependency 'faraday', '>= 0.9.1', '~> 0.9'
22
22
  gem.add_dependency 'faraday_middleware', '~> 0.9'
23
+ gem.add_dependency 'retriable', '~> 1.4'
23
24
  gem.add_dependency 'i18n'
24
25
  gem.add_dependency 'virtus', '>= 1.0.0'
25
26
 
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.0.3
4
+ version: 6.1.0
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-03-04 00:00:00.000000000 Z
14
+ date: 2016-03-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -89,6 +89,20 @@ dependencies:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0.9'
92
+ - !ruby/object:Gem::Dependency
93
+ name: retriable
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.4'
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '1.4'
92
106
  - !ruby/object:Gem::Dependency
93
107
  name: i18n
94
108
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +216,6 @@ files:
202
216
  - lib/survey_gizmo/configuration.rb
203
217
  - lib/survey_gizmo/connection.rb
204
218
  - lib/survey_gizmo/faraday_middleware/parse_survey_gizmo.rb
205
- - lib/survey_gizmo/faraday_middleware/pester_survey_gizmo.rb
206
219
  - lib/survey_gizmo/logger.rb
207
220
  - lib/survey_gizmo/multilingual_title.rb
208
221
  - lib/survey_gizmo/resource.rb
@@ -1,16 +0,0 @@
1
- module SurveyGizmo
2
- class RateLimitExceededError < RuntimeError; end
3
- class BadResponseError < RuntimeError; end
4
-
5
- class PesterSurveyGizmoMiddleware < Faraday::Middleware
6
- Faraday::Response.register_middleware(pester_survey_gizmo: self)
7
-
8
- def call(environment)
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
13
- end
14
- end
15
- end
16
- end