typeform_data 3.0.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a29d5216f5bc251d42df766ac5f6ee3453a113e
4
- data.tar.gz: 824508bc3d4e477d0fbaa7a673fa4abad012c011
3
+ metadata.gz: d59e6ace3ebd1f11c50608dd55f8ab6473447540
4
+ data.tar.gz: a56983d75dc15baa9b95c57401d208f025339f50
5
5
  SHA512:
6
- metadata.gz: d615981da83f83f61f8663bd3c1182de16255b32d01a90080d679d0bfe5be3c2a50646540a0de7d9300f4aeb3a1ae1f91dbb28e1c54e8dbcab76fe740286a924
7
- data.tar.gz: 84bdecd33b209bfd7c0e2eddfc5687321bc23230a6aa32a11506dfe358ae92a6f5f7534d9ac85a11c292fca3e792433f690fb93effa3a36413a49bb4011a1be0
6
+ metadata.gz: 736daabbd96df999d30946e6c20d7b8b28d13562adb50c0b481f2bfd78c4c8e59532ea93753478863e26cf4b457bdcd1067f9199db8657ff7fbef2bf57ccdfbd
7
+ data.tar.gz: 84873ab4d73b0f89be5a6fc01f2f5d9c9f4fe0535c6ab669fbc4842fdc95e173ec7b7446e1c6434df90deca6a352410787e563cc2dbefce14e0cd869c69386a3
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /.ruby-version
4
+ /.ruby-gemset
3
5
  /Gemfile.lock
4
6
  /_yardoc/
5
7
  /coverage/
data/README.md CHANGED
@@ -107,7 +107,11 @@ And then execute:
107
107
 
108
108
  ### Development
109
109
 
110
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
110
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To get started, you'll probably want to run something like:
111
+
112
+ ```
113
+ TypeformData::Client.new(api_key: your_api_key).all_typeforms
114
+ ```
111
115
 
112
116
  ### Releasing a new version
113
117
 
@@ -38,6 +38,10 @@ module TypeformData
38
38
  TypeformData::Typeform.new(@config, id: id)
39
39
  end
40
40
 
41
+ # The goals of this alias are:
42
+ # 1. To bring the serialization process within TypeformData's API, so
43
+ # we can modify it in the future if needed.
44
+ # 2. Maintain symmetry with #load, which needs to be part of the API.
41
45
  def dump(object)
42
46
  Marshal.dump(object)
43
47
  end
@@ -59,5 +63,13 @@ module TypeformData
59
63
  }
60
64
  end
61
65
 
66
+ def marshal_dump
67
+ raise 'Do not serialize TypeformData::Client-- it contains your API key'
68
+ end
69
+
70
+ def as_json(*_args)
71
+ raise 'Do not serialize TypeformData::Client-- it contains your API key'
72
+ end
73
+
62
74
  end
63
75
  end
@@ -65,6 +65,11 @@ module TypeformData
65
65
 
66
66
  # This method will make an AJAX request if this Typeform's name hasn't already been set during
67
67
  # initialization.
68
+ #
69
+ # Since the readable_attributes call above calls attr_reader(:name) for us, this method
70
+ # redefines name, and causes an (expected) "warning: method redefined" message when running
71
+ # tests.
72
+ #
68
73
  # @return [String]
69
74
  def name
70
75
  @name ||= client.all_typeforms.find { |typeform| typeform.id == id }.name
@@ -1,28 +1,32 @@
1
1
  # frozen_string_literal: true
2
- module Utils
2
+ module TypeformData
3
+ module Utils
3
4
 
4
- # Repeats the block until it succeeds or a limit is reached, waiting twice as long as it
5
- # previously did after each failure.
6
- # @param config [TypeformData::Config]
7
- # @param rescued_exceptions [Class] Subclasses of Exception.
8
- # @param max_retries [Integer]
9
- # @param initial_wait [Integer] In seconds.
10
- def self.retry_with_exponential_backoff(config, retry_exceptions, max_retries: 5, initial_wait: 1)
11
- seconds_to_wait = initial_wait
5
+ # Repeats the block until it succeeds or a limit is reached, waiting twice as long as it
6
+ # previously did after each failure.
7
+ # @param config [TypeformData::Config]
8
+ # @param rescued_exceptions [Class] Subclasses of Exception.
9
+ # @param max_retries [Integer]
10
+ # @param initial_wait [Integer] In seconds.
11
+ def self.retry_with_exponential_backoff(config, retry_exceptions, max_retries: 5,
12
+ initial_wait: 1)
12
13
 
13
- max_retries.times do |iteration|
14
- begin
15
- break yield
16
- rescue *retry_exceptions
17
- config.logger.warn "Retry. Waiting #{seconds_to_wait}s, attempt #{iteration} of "\
18
- "#{max_retries}."
14
+ seconds_to_wait = initial_wait
19
15
 
20
- sleep seconds_to_wait
21
- seconds_to_wait *= 2
16
+ max_retries.times do |iteration|
17
+ begin
18
+ break yield
19
+ rescue *retry_exceptions
20
+ config.logger.warn "Retry. Waiting #{seconds_to_wait}s, attempt #{iteration} of "\
21
+ "#{max_retries}."
22
22
 
23
- raise if iteration == max_retries - 1
23
+ sleep seconds_to_wait
24
+ seconds_to_wait *= 2
25
+
26
+ raise if iteration == max_retries - 1
27
+ end
24
28
  end
25
29
  end
26
- end
27
30
 
31
+ end
28
32
  end
@@ -23,6 +23,49 @@ module TypeformData
23
23
  end
24
24
  end
25
25
 
26
+ # ActiveSupport defines Object#as_json in
27
+ # activesupport/lib/active_support/core_ext/object/json.rb which exists to separate
28
+ # stringification from serialization logic. as_json is not core Ruby, but we implement it here
29
+ # for compatibility with to_json when ActiveSupport is loaded.
30
+ #
31
+ # In addition to protection against serializing the API key, this method is needed for #to_json
32
+ # to work at all, since the :config object contains IO objects and ActiveSupport's #as_json
33
+ # method fails when trying to serialize IO objects. See
34
+ # https://github.com/rails/rails/issues/26132.
35
+ #
36
+ # Testing this method:
37
+ #
38
+ # For now, we're not including ActiveSupport as a development dependency because of the risk
39
+ # of accidentally writing code that relies on an ActiveSupport core extension that might not
40
+ # be present where this gem is being used.
41
+ #
42
+ # To test this method in the console, add
43
+ #
44
+ # spec.add_development_dependency 'activesupport'
45
+ #
46
+ # to typeform_data.gemspec and then run something like
47
+ #
48
+ # require 'active_support'; require 'active_support/json'; \
49
+ # c = TypeformData::Client.new(api_key: ...); \
50
+ # at = c.all_typeforms; tf = at.reverse.find { |t| t.stats.completed > 0 }; \
51
+ # tf.responses(completed: true, limit: 1).first.to_json
52
+ #
53
+ # using bin/console.
54
+ #
55
+ # One last thing: if you pass options #to_json or #as_json, Rails will use the same options for
56
+ # all calls in the object graph, so the following behavior is expected (if counterintuitive):
57
+ #
58
+ # # response.as_json(only: 'answers')
59
+ # => {"answers"=>[{}, {}, {}, {}]}
60
+ #
61
+ # @param [Hash]
62
+ def as_json(options = {})
63
+ # Note: :config doesn't work here-- using the string form is mandatory.
64
+ return super({ except: 'config' }) if options.empty?
65
+
66
+ super(options.merge(except: ['config'] + Array(options[:except])))
67
+ end
68
+
26
69
  def self.included(base)
27
70
  base.extend(ClassMethods)
28
71
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TypeformData
3
- VERSION = '3.0.1'
3
+ VERSION = '4.0.0'
4
4
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.name = 'typeform_data'
10
10
  spec.version = TypeformData::VERSION
11
- spec.authors = ['Max Wallace']
11
+ spec.authors = ['Max Wallace', 'Eli Rose']
12
12
  spec.email = ['engineering@shearwaterintl.com']
13
13
 
14
14
  spec.summary = 'An opinionated, OO client for the Typeform.com Data API'
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'pry-byebug', '~> 3.3'
36
36
  spec.add_development_dependency 'pry-doc', '~> 0.8'
37
37
  spec.add_development_dependency 'byebug', '~> 8.2'
38
- spec.add_development_dependency 'rubocop', '~> 0.39'
38
+ spec.add_development_dependency 'rubocop', '~> 0.47'
39
39
 
40
40
  end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typeform_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Wallace
8
+ - Eli Rose
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
12
+ date: 2017-06-18 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -128,14 +129,14 @@ dependencies:
128
129
  requirements:
129
130
  - - "~>"
130
131
  - !ruby/object:Gem::Version
131
- version: '0.39'
132
+ version: '0.47'
132
133
  type: :development
133
134
  prerelease: false
134
135
  version_requirements: !ruby/object:Gem::Requirement
135
136
  requirements:
136
137
  - - "~>"
137
138
  - !ruby/object:Gem::Version
138
- version: '0.39'
139
+ version: '0.47'
139
140
  description: typeform_data is a minimal, opinionated, OO client for the Typeform.com
140
141
  Data API with no runtime dependencies.
141
142
  email:
@@ -193,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  version: '0'
194
195
  requirements: []
195
196
  rubyforge_project:
196
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.6.8
197
198
  signing_key:
198
199
  specification_version: 4
199
200
  summary: An opinionated, OO client for the Typeform.com Data API