survey_monkey 0.2.0 → 0.2.2
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 +4 -4
- data/README.md +24 -9
- data/lib/config/api_settings.yml +1 -1
- data/lib/survey_monkey/parameters.rb +21 -6
- data/lib/survey_monkey/recipient.rb +12 -8
- data/lib/survey_monkey/recipients.rb +5 -1
- data/lib/survey_monkey/request.rb +6 -0
- data/lib/survey_monkey/version.rb +1 -1
- data/lib/survey_monkey.rb +2 -1
- 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: 125097a806ade2658f50ab46a3fac7fc954da771
|
|
4
|
+
data.tar.gz: dd25f4b0540f416285a04a24ca34c5e553a9b987
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4cf4f96c0c90543d2bb4dc3d34669bc85b41916af9619572da7c2c543dd9ab8276e87d10f061c73a91f2fd59a69f38c8adc9c27b5e8f244c329063237881d43
|
|
7
|
+
data.tar.gz: 55defc012c0dcb8462dd1c080747dc03cb58dc66c691dcbbcc9e2d8ffe8ac9109ac81f2b7ea5a43f8a97e131c051f7bcb0a4b626ff81443f74f282dbd74a51c2
|
data/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
|
18
18
|
|
|
19
19
|
To Authenticate, you have two options:
|
|
20
20
|
|
|
21
|
-
1
|
|
21
|
+
Option 1: Use ENV Variables:
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
24
|
# Set the following variables ( the gem is configured to use dotenv.
|
|
@@ -32,14 +32,14 @@ ENV['SURVEY_MONKEY_CLIENT_SECRET']
|
|
|
32
32
|
ENV['SURVEY_MONKEY_CLIENT_ID']
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
2
|
|
35
|
+
Option 2: Create an instance of SurveyMonkey::Auth with the credentials.
|
|
36
36
|
|
|
37
37
|
```ruby
|
|
38
38
|
api_credentials = {
|
|
39
|
-
access_token:
|
|
40
|
-
api_key:
|
|
41
|
-
client_secret:
|
|
42
|
-
client_id:
|
|
39
|
+
access_token: 'accesstoken',
|
|
40
|
+
api_key: 'apikey',
|
|
41
|
+
client_secret: 'clientsecret',
|
|
42
|
+
client_id: 'clientid'
|
|
43
43
|
}
|
|
44
44
|
auth = SurveyMonkey::Auth.new(api_credentials)
|
|
45
45
|
|
|
@@ -58,15 +58,16 @@ Make the request:
|
|
|
58
58
|
```ruby
|
|
59
59
|
# Create the request
|
|
60
60
|
# if ENV vars were used, auth can be excluded from options hash
|
|
61
|
+
# params can be excluded or nil to set with set_params method and a block
|
|
61
62
|
|
|
62
|
-
options = {api_method: api_method, auth: auth}
|
|
63
|
+
options = {api_method: api_method, auth: auth, params: nil}
|
|
63
64
|
api_request = SurveyMonkey::Request.new(api_method)
|
|
64
65
|
|
|
65
66
|
# Set the parameters
|
|
66
67
|
api_request.set_parameters do |p|
|
|
67
68
|
p.page = 1
|
|
68
69
|
p.page_size = 10
|
|
69
|
-
p.
|
|
70
|
+
p.order_asc = 'true'
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
# Run the request
|
|
@@ -79,10 +80,24 @@ result = api_request.result
|
|
|
79
80
|
|
|
80
81
|
## Quick Requests
|
|
81
82
|
```ruby
|
|
83
|
+
# A shortcut for specifying params is to use a hash instead of the block.
|
|
84
|
+
# The params_hash is passed in the options hash under the :params key
|
|
85
|
+
# e.g.
|
|
86
|
+
params_hash = {page_size: 10, page: 1, order_asc: 'true'}
|
|
87
|
+
options = {params: params_hash}
|
|
88
|
+
|
|
82
89
|
# A shortcut for making requests using default options is to simply call
|
|
83
90
|
# SurveyMonkey.method where method is the name of the API method you wish to call
|
|
84
91
|
# e.g.
|
|
85
|
-
|
|
92
|
+
|
|
93
|
+
api_request = SurveyMonkey.get_survey_list options
|
|
94
|
+
|
|
95
|
+
# Run the request
|
|
96
|
+
api_request.run_request
|
|
97
|
+
|
|
98
|
+
# View the result
|
|
99
|
+
result = api_request.result
|
|
100
|
+
|
|
86
101
|
```
|
|
87
102
|
|
|
88
103
|
## TODO
|
data/lib/config/api_settings.yml
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
require 'survey_monkey/recipients'
|
|
2
2
|
require 'survey_monkey/recipient'
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_support/core_ext/string"
|
|
5
|
+
require "active_support/core_ext/object"
|
|
3
6
|
|
|
4
7
|
module SurveyMonkey
|
|
5
8
|
class Parameters
|
|
@@ -18,23 +21,35 @@ module SurveyMonkey
|
|
|
18
21
|
def to_hash
|
|
19
22
|
converted_hash = Hash.new
|
|
20
23
|
method_parameters.keys.each do |root|
|
|
21
|
-
if method_parameters[root].is_a? Hash ## has
|
|
24
|
+
if method_parameters[root].is_a? Hash ## The parameter has children
|
|
22
25
|
converted_hash[root] = Hash.new
|
|
23
26
|
method_parameters[root].keys.each do |child|
|
|
24
27
|
if method_parameters[root][child].is_a? Hash ## has grand_child
|
|
25
28
|
method_parameters[root].keys.each do |grand_child|
|
|
26
|
-
|
|
29
|
+
# save the value for each grand_child into the hash
|
|
30
|
+
converted_hash[root][child][grand_child] = self.send("#{root}_#{child}_#{grand_child}")
|
|
27
31
|
end
|
|
32
|
+
# Delete any nil grand_child keys
|
|
33
|
+
converted_hash[root][child].delete_if{ |k, v| v.nil? } if converted_hash[root].has_key?(child)
|
|
28
34
|
elsif method_parameters[root][child].is_a? Array
|
|
29
|
-
|
|
35
|
+
# child is an array. elements of array to hash
|
|
36
|
+
value = self.send("#{root}_#{child}")
|
|
37
|
+
unless value.empty?
|
|
38
|
+
converted_hash[root][child] = value
|
|
39
|
+
converted_hash[root][child].map{ |e| e.to_hash }
|
|
40
|
+
end
|
|
30
41
|
else
|
|
31
|
-
|
|
42
|
+
value = self.send("#{root}_#{child}")
|
|
43
|
+
converted_hash[root][child] = value unless value.nil? ## save value for child (dont assign nil values)
|
|
32
44
|
end
|
|
45
|
+
# Delete any root keys with nil values
|
|
46
|
+
converted_hash[root] = converted_hash[root].delete_if{ |k, v| v.nil? } if converted_hash.has_key?(root)
|
|
33
47
|
end
|
|
34
48
|
elsif method_parameters[root].is_a? Array
|
|
35
|
-
converted_hash[root] = self.send("#{root}").to_hash ## root Array
|
|
49
|
+
converted_hash[root] = self.send("#{root}").to_hash.delete_if{ |k, v| v.nil? } ## root Array
|
|
36
50
|
else
|
|
37
|
-
|
|
51
|
+
value = self.send("#{root}") ## No children
|
|
52
|
+
converted_hash[root] = value unless value.nil?
|
|
38
53
|
end
|
|
39
54
|
end
|
|
40
55
|
converted_hash
|
|
@@ -2,17 +2,21 @@ module SurveyMonkey
|
|
|
2
2
|
class Recipient
|
|
3
3
|
attr_accessor :email, :first_name, :last_name, :custom_id
|
|
4
4
|
|
|
5
|
-
def
|
|
6
|
-
email = options[:email]
|
|
7
|
-
first_name = options[:first_name]
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
custom_id = options[:custom_id]
|
|
11
|
-
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
@email = options[:email]
|
|
7
|
+
@first_name = options[:first_name]
|
|
8
|
+
@last_name = options[:last_name]
|
|
9
|
+
@custom_id = options[:custom_id]
|
|
12
10
|
raise "Email Required for Recipient" if email.nil?
|
|
13
11
|
end
|
|
12
|
+
|
|
14
13
|
def to_hash
|
|
15
|
-
|
|
14
|
+
hash = Hash.new
|
|
15
|
+
hash["email"] = email unless email.nil?
|
|
16
|
+
hash["first_name"] = first_name unless first_name.nil?
|
|
17
|
+
hash["last_name"] = last_name unless last_name.nil?
|
|
18
|
+
hash["custom_id"] = custom_id unless custom_id.nil?
|
|
19
|
+
hash
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
end
|
|
@@ -71,6 +71,7 @@ module SurveyMonkey
|
|
|
71
71
|
end
|
|
72
72
|
end
|
|
73
73
|
request.run
|
|
74
|
+
self
|
|
74
75
|
end
|
|
75
76
|
|
|
76
77
|
def set_on_complete_response
|
|
@@ -93,6 +94,11 @@ module SurveyMonkey
|
|
|
93
94
|
JSON.parse @response.body
|
|
94
95
|
end
|
|
95
96
|
|
|
97
|
+
def submit
|
|
98
|
+
run_request
|
|
99
|
+
result
|
|
100
|
+
end
|
|
101
|
+
|
|
96
102
|
private
|
|
97
103
|
def api_key
|
|
98
104
|
@api_key
|
data/lib/survey_monkey.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: survey_monkey
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Dawson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-01-
|
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: typhoeus
|