typeform_data 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/typeform_data/client.rb +24 -3
- data/lib/typeform_data/comparable_by_id_and_config.rb +1 -1
- data/lib/typeform_data/typeform.rb +1 -1
- data/lib/typeform_data/version.rb +1 -1
- data/lib/typeform_data.rb +0 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c89b3a3f4d42c31eb7caca0e233587b91c373b1
|
4
|
+
data.tar.gz: 6dbaf654728b826e8d71cb81b75d3ddd18763192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe56f2ccbb13af7c74e7f14f6d95a97a117d5b995081ac906e8be85b62c979d9b852f271b72c00626ed3df074bc08b0cda7f94a1dcad8f74b4eb451881aee795
|
7
|
+
data.tar.gz: 4bfddc0639cc2b3cb6b208f128e0ddf97ba7718a4c3d7b16c199fec49ac489d3b58a3c154eb0eda48d9378d437409e972ec76b47f4d1c89f581fa5e5967ff67e
|
data/README.md
CHANGED
@@ -47,7 +47,20 @@ typeform.responses.first.answers.map { |answer| [answer.field_text, answer.value
|
|
47
47
|
|
48
48
|
```
|
49
49
|
|
50
|
-
|
50
|
+
### Serialization & deserialization
|
51
|
+
|
52
|
+
Your API key will not be serialized. `TypeformData::Client#dump` is just a pass-through to `Marshal#dump`, but `Client#load` will re-set your API key on each of the deserialized objects-- this ensures the object graph stays intact through the serialization process.
|
53
|
+
|
54
|
+
```
|
55
|
+
serialized = client.dump(responses)
|
56
|
+
deserialized = client.load(serialized)
|
57
|
+
|
58
|
+
> deserialized == responses
|
59
|
+
=> true
|
60
|
+
|
61
|
+
> deserialized.first.typeform == responses.first.typeform
|
62
|
+
=> true
|
63
|
+
```
|
51
64
|
|
52
65
|
## Notes on the API
|
53
66
|
|
@@ -62,7 +75,7 @@ The main goal of this API wrapper is to encapsulate these implementation details
|
|
62
75
|
|
63
76
|
- At the moment, this gem has no runtime dependencies.
|
64
77
|
- We've only tested this gem against Ruby 2.3. I'm not sure whether it works with older versions.
|
65
|
-
- Under the hood, the object relationships are implemented by storing a reference to a config object containing your API key. This is what allows you to say `answer.typeform.responses` and ultimately make an API call originating from a `TypeformData::Typeform::Answer` without having to pass in a reference to a client or your API key (again). To avoid leaking your API key, make sure to clear out the `@config` reference if you add
|
78
|
+
- Under the hood, the object relationships are implemented by storing a reference to a config object containing your API key. This is what allows you to say `answer.typeform.responses` and ultimately make an API call originating from a `TypeformData::Typeform::Answer` without having to pass in a reference to a client or your API key (again). To avoid leaking your API key, make sure to clear out the `@config` reference if you add new serialization functionality! (We've already handled this for `Marshal#dump`.)
|
66
79
|
|
67
80
|
### Installation
|
68
81
|
|
data/lib/typeform_data/client.rb
CHANGED
@@ -18,9 +18,9 @@ module TypeformData
|
|
18
18
|
# Your API key will automatically be added to the request URL as a query param, as required by
|
19
19
|
# the API.
|
20
20
|
#
|
21
|
-
# @param String
|
22
|
-
# @param Hash
|
23
|
-
# @return TypeformData::ApiResponse
|
21
|
+
# @param [String]
|
22
|
+
# @param [Hash]
|
23
|
+
# @return [TypeformData::ApiResponse]
|
24
24
|
def get(endpoint, params = {})
|
25
25
|
TypeformData::Requestor.get(@config, endpoint, params)
|
26
26
|
end
|
@@ -35,5 +35,26 @@ module TypeformData
|
|
35
35
|
::TypeformData::Typeform.new(@config, id: id)
|
36
36
|
end
|
37
37
|
|
38
|
+
def dump(object)
|
39
|
+
Marshal.dump(object)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @param serialized [String] The output of Marshal.dump(vci) where vci is either (1) an
|
43
|
+
# instance of TypeformData::ValueClass or (2) an array of instances of
|
44
|
+
# TypeformData::ValueClass.
|
45
|
+
# @param default [Object] What to return if 'serialized' is blank or not a String.
|
46
|
+
def load(serialized, default = nil)
|
47
|
+
return default unless serialized.is_a?(String) && !serialized.empty?
|
48
|
+
|
49
|
+
Marshal.load(serialized).tap { |marshaled|
|
50
|
+
case marshaled
|
51
|
+
when Array
|
52
|
+
marshaled.each { |object| object.reconfig(@config) }
|
53
|
+
else
|
54
|
+
marshaled.reconfig(@config)
|
55
|
+
end
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
38
59
|
end
|
39
60
|
end
|
@@ -9,7 +9,7 @@ module TypeformData
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def ==(other)
|
12
|
-
unless other.respond_to?(:sort_key) && other.respond_to?(:config)
|
12
|
+
unless other.respond_to?(:sort_key, true) && other.respond_to?(:config, true)
|
13
13
|
raise ArgumentError, "#{other.inspect} does not specify a sort key and config"
|
14
14
|
end
|
15
15
|
other.sort_key == sort_key && other.config == config
|
@@ -97,7 +97,7 @@ module TypeformData
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# It looks like sometimes the Typeform API will report stats that are out-of-date relative to
|
100
|
-
# the responses it actually returns.
|
100
|
+
# the responses it actually returns.
|
101
101
|
def responses_request(input_params = {})
|
102
102
|
params = input_params.dup
|
103
103
|
requests = [ResponsesRequest.new(params, client.get('form/' + id, params))]
|
data/lib/typeform_data.rb
CHANGED
@@ -1,25 +1,4 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
module TypeformData
|
3
|
-
|
4
|
-
def self.dump(object)
|
5
|
-
Marshal.dump(object)
|
6
|
-
end
|
7
|
-
|
8
|
-
# Currently only handles single objects and arrays.
|
9
|
-
# @param [TypeformData::ValueClass]
|
10
|
-
# @param [TypeformData::Config]
|
11
|
-
def self.load(value_class_instance, config)
|
12
|
-
Marshal.load(value_class_instance).tap { |marshaled|
|
13
|
-
case marshaled
|
14
|
-
when Array
|
15
|
-
marshaled.each { |object| object.reconfig(config) }
|
16
|
-
else
|
17
|
-
marshaled.reconfig(config)
|
18
|
-
end
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
2
|
|
24
3
|
require 'net/http'
|
25
4
|
require 'net/https'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typeform_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Wallace
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|