survey_monkey 0.2.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 +7 -0
- data/.gitignore +20 -0
- data/.rvmrc +62 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +98 -0
- data/Rakefile +1 -0
- data/config/survey_monkey.env.example +4 -0
- data/lib/config/api_settings.yml +110 -0
- data/lib/survey_monkey/auth.rb +27 -0
- data/lib/survey_monkey/config.rb +7 -0
- data/lib/survey_monkey/parameters.rb +115 -0
- data/lib/survey_monkey/recipient.rb +18 -0
- data/lib/survey_monkey/recipients.rb +23 -0
- data/lib/survey_monkey/request.rb +105 -0
- data/lib/survey_monkey/version.rb +3 -0
- data/lib/survey_monkey.rb +40 -0
- data/survey_monkey.gemspec +29 -0
- metadata +145 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 5c6ff1c896073faa5c2f32aa2410c0d74d46086d
|
|
4
|
+
data.tar.gz: 208f9ee34f065f9c5b87c5d5906d95d39badea19
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 306f74acec296051f7b1ad0b0d67109e3cdb99002af433846799cddb50826af44d2980d2b8f1c45d528682ef57c769bee5a990ff0e3e571bdb536bd96e14bffc
|
|
7
|
+
data.tar.gz: 7f926d813786aeb7856138e3e678e8037fc5eed345de37bb53eccf4dcfe49f15aebf06db3492a556b00d65263fcd0b4a120c3dbfdca1fc0ee0343e685547c599
|
data/.gitignore
ADDED
data/.rvmrc
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
|
4
|
+
# development environment upon cd'ing into the directory
|
|
5
|
+
|
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
|
8
|
+
# echo "rvm use 2.1.0@survey_monkey" > .rvmrc
|
|
9
|
+
environment_id="ruby-2.1.0@survey_monkey"
|
|
10
|
+
|
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
|
12
|
+
# rvmrc_rvm_version="1.25.14 (stable)" # 1.10.1 seems like a safe start
|
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
|
15
|
+
# return 1
|
|
16
|
+
# }
|
|
17
|
+
|
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
|
24
|
+
then
|
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
|
27
|
+
do
|
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
|
29
|
+
then \. "${__hook}" || true
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
unset __hook
|
|
33
|
+
if (( ${rvm_use_flag:=1} >= 2 )) # display only when forced
|
|
34
|
+
then
|
|
35
|
+
if [[ $- == *i* ]] # check for interactive shells
|
|
36
|
+
then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
|
|
37
|
+
" # show the user the ruby and gemset they are using in green
|
|
38
|
+
else printf "%b" "Using: $GEM_HOME
|
|
39
|
+
" # don't use colors in non-interactive shells
|
|
40
|
+
fi
|
|
41
|
+
fi
|
|
42
|
+
else
|
|
43
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
|
44
|
+
rvm --create "$environment_id" || {
|
|
45
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
|
46
|
+
return 1
|
|
47
|
+
}
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
# If you use bundler, this might be useful to you:
|
|
51
|
+
# if [[ -s Gemfile ]] && {
|
|
52
|
+
# ! builtin command -v bundle >/dev/null ||
|
|
53
|
+
# builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
|
|
54
|
+
# }
|
|
55
|
+
# then
|
|
56
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
|
57
|
+
# gem install bundler
|
|
58
|
+
# fi
|
|
59
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
|
60
|
+
# then
|
|
61
|
+
# bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
|
|
62
|
+
# fi
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Nick Dawson
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# SurveyMonkey
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
Add this line to your application's Gemfile:
|
|
6
|
+
|
|
7
|
+
gem 'survey_monkey'
|
|
8
|
+
|
|
9
|
+
And then execute:
|
|
10
|
+
|
|
11
|
+
$ bundle
|
|
12
|
+
|
|
13
|
+
Or install it yourself as:
|
|
14
|
+
|
|
15
|
+
$ gem install survey_monkey
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
To Authenticate, you have two options:
|
|
20
|
+
|
|
21
|
+
1. Use ENV Variables:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
# Set the following variables ( the gem is configured to use dotenv.
|
|
25
|
+
# rename the config/survey_monkey.env.example file to config/survey_monkey.env and fill in your info )
|
|
26
|
+
# make sure to add config/survey_monkey.env to your .gitignore
|
|
27
|
+
# if you wish to use a different filename, provide it in the api_credentials options hash under :file_name
|
|
28
|
+
|
|
29
|
+
ENV['SURVEY_MONKEY_ACCESS_TOKEN']
|
|
30
|
+
ENV['SURVEY_MONKEY_API_KEY']
|
|
31
|
+
ENV['SURVEY_MONKEY_CLIENT_SECRET']
|
|
32
|
+
ENV['SURVEY_MONKEY_CLIENT_ID']
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
2. Create an instance of SurveyMonkey::Auth
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
api_credentials = {
|
|
39
|
+
access_token: 'accesstoken',
|
|
40
|
+
api_key: 'apikey',
|
|
41
|
+
client_secret: 'clientsecret',
|
|
42
|
+
client_id: 'clientid'
|
|
43
|
+
}
|
|
44
|
+
auth = SurveyMonkey::Auth.new(api_credentials)
|
|
45
|
+
|
|
46
|
+
# supply your own auth when you create the new request
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
Define the method you wish to use:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
api_method = 'get_survey_list'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Make the request:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
# Create the request
|
|
60
|
+
# if ENV vars were used, auth can be excluded from options hash
|
|
61
|
+
|
|
62
|
+
options = {api_method: api_method, auth: auth}
|
|
63
|
+
api_request = SurveyMonkey::Request.new(api_method)
|
|
64
|
+
|
|
65
|
+
# Set the parameters
|
|
66
|
+
api_request.set_parameters do |p|
|
|
67
|
+
p.page = 1
|
|
68
|
+
p.page_size = 10
|
|
69
|
+
p.order_ac = 'true'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Run the request
|
|
73
|
+
api_request.run_request
|
|
74
|
+
|
|
75
|
+
# View the result
|
|
76
|
+
result = api_request.result
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quick Requests
|
|
81
|
+
```ruby
|
|
82
|
+
# A shortcut for making requests using default options is to simply call
|
|
83
|
+
# SurveyMonkey.method where method is the name of the API method you wish to call
|
|
84
|
+
# e.g.
|
|
85
|
+
request = SurveyMonkey.get_survey_list
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## TODO
|
|
89
|
+
|
|
90
|
+
Add tests!
|
|
91
|
+
|
|
92
|
+
## Contributing
|
|
93
|
+
|
|
94
|
+
1. Fork it ( http://github.com/wdawson4/survey_monkey/fork )
|
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
96
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
98
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
get_survey_details:
|
|
2
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_survey_details
|
|
3
|
+
http_method: post
|
|
4
|
+
parameters:
|
|
5
|
+
survey_id: required
|
|
6
|
+
get_user_details:
|
|
7
|
+
uri: https://api.surveymonkey.net/v2/user/get_user_details
|
|
8
|
+
http_method: post
|
|
9
|
+
parameters:
|
|
10
|
+
get_survey_list:
|
|
11
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_survey_list
|
|
12
|
+
http_method: post
|
|
13
|
+
parameters:
|
|
14
|
+
page: optional
|
|
15
|
+
page_size: optional
|
|
16
|
+
start_date: optional
|
|
17
|
+
end_date: optional
|
|
18
|
+
title: optional
|
|
19
|
+
recipient_email: optional
|
|
20
|
+
order_asc: optional
|
|
21
|
+
fields: optional
|
|
22
|
+
get_collector_list:
|
|
23
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_collector_list
|
|
24
|
+
http_method: post
|
|
25
|
+
parameters:
|
|
26
|
+
survey_id: required
|
|
27
|
+
page: optional
|
|
28
|
+
page_size: optional
|
|
29
|
+
start_date: optional
|
|
30
|
+
end_date: optional
|
|
31
|
+
name: optional
|
|
32
|
+
order_asc: optional
|
|
33
|
+
fields: optional
|
|
34
|
+
create_collector:
|
|
35
|
+
uri: https://api.surveymonkey.net/v2/collectors/create_collector
|
|
36
|
+
http_method: post
|
|
37
|
+
parameters:
|
|
38
|
+
survey_id: required
|
|
39
|
+
collector:
|
|
40
|
+
type: required
|
|
41
|
+
name: optional
|
|
42
|
+
thank_you_message: optional
|
|
43
|
+
redirect_url: optional
|
|
44
|
+
get_respondent_list:
|
|
45
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_respondent_list
|
|
46
|
+
http_method: post
|
|
47
|
+
parameters:
|
|
48
|
+
survey_id: required
|
|
49
|
+
collector_id: optional
|
|
50
|
+
page: optional
|
|
51
|
+
page_size: optional
|
|
52
|
+
start_date: optional
|
|
53
|
+
end_date: optional
|
|
54
|
+
start_modified_date: optional
|
|
55
|
+
end_modified_date: optional
|
|
56
|
+
order_asc: optional
|
|
57
|
+
order_by: optional
|
|
58
|
+
fields: optional
|
|
59
|
+
get_responses:
|
|
60
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_responses
|
|
61
|
+
http_method: post
|
|
62
|
+
parameters:
|
|
63
|
+
respondent_ids: required
|
|
64
|
+
survey_id: required
|
|
65
|
+
get_response_counts:
|
|
66
|
+
uri: https://api.surveymonkey.net/v2/surveys/get_response_counts
|
|
67
|
+
http_method: post
|
|
68
|
+
parameters:
|
|
69
|
+
collector_id: required
|
|
70
|
+
create_flow:
|
|
71
|
+
uri: https://api.surveymonkey.net/v2/batch/create_flow
|
|
72
|
+
http_method: post
|
|
73
|
+
parameters:
|
|
74
|
+
survey:
|
|
75
|
+
template_id: optional
|
|
76
|
+
form_survey_id: optional
|
|
77
|
+
survey_title: optional
|
|
78
|
+
collector:
|
|
79
|
+
type: conditionally_required
|
|
80
|
+
name: optional
|
|
81
|
+
send: optional
|
|
82
|
+
recipients:
|
|
83
|
+
-
|
|
84
|
+
email: conditionally_required
|
|
85
|
+
first_name: optional
|
|
86
|
+
last_name: optional
|
|
87
|
+
custom_id: optional
|
|
88
|
+
email_message:
|
|
89
|
+
reply_email: conditionally_required
|
|
90
|
+
subject: conditionally_required
|
|
91
|
+
body_text: conditionally_required
|
|
92
|
+
send_flow:
|
|
93
|
+
uri: https://api.surveymonkey.net/v2/batch/send_flow
|
|
94
|
+
http_method: post
|
|
95
|
+
parameters:
|
|
96
|
+
survey_id: required
|
|
97
|
+
collector:
|
|
98
|
+
type: conditionally_required
|
|
99
|
+
name: optional
|
|
100
|
+
send: optional
|
|
101
|
+
recipients:
|
|
102
|
+
-
|
|
103
|
+
email: conditionally_required
|
|
104
|
+
first_name: optional
|
|
105
|
+
last_name: optional
|
|
106
|
+
custom_id: optional
|
|
107
|
+
email_message:
|
|
108
|
+
reply_email: conditionally_required
|
|
109
|
+
subject: conditionally_required
|
|
110
|
+
body_text: conditionally_required
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module SurveyMonkey
|
|
2
|
+
class Auth
|
|
3
|
+
attr_reader :access_token, :api_key, :client_secret, :client_id
|
|
4
|
+
def initialize(login = {})
|
|
5
|
+
file_name = login[:dotenv_file_name] || SURVEY_MONKEY_DOTENV_PATH
|
|
6
|
+
check_for_dotenv(file_name) unless env_vars_defined?
|
|
7
|
+
|
|
8
|
+
@access_token = login[:access_token] || ENV['SURVEY_MONKEY_ACCESS_TOKEN']
|
|
9
|
+
@api_key = login[:api_key] || ENV['SURVEY_MONKEY_API_KEY']
|
|
10
|
+
@client_secret = login[:client_secret] || ENV['SURVEY_MONKEY_CLIENT_SECRET']
|
|
11
|
+
@client_id = login[:client_id] || ENV['SURVEY_MONKEY_CLIENT_ID']
|
|
12
|
+
end
|
|
13
|
+
private
|
|
14
|
+
def check_for_dotenv(file_name)
|
|
15
|
+
Dotenv.load!(file_name) if ( File.exists?(file_name) && Dotenv.respond_to?('load') )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def env_vars_defined?
|
|
19
|
+
defined = false
|
|
20
|
+
env_vars = ['SURVEY_MONKEY_ACCESS_TOKEN', 'SURVEY_MONKEY_API_KEY','SURVEY_MONKEY_CLIENT_SECRET','SURVEY_MONKEY_CLIENT_ID']
|
|
21
|
+
env_vars.each do |var|
|
|
22
|
+
defined = true if ENV.has_key?(var)
|
|
23
|
+
end
|
|
24
|
+
defined
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'survey_monkey/recipients'
|
|
2
|
+
require 'survey_monkey/recipient'
|
|
3
|
+
|
|
4
|
+
module SurveyMonkey
|
|
5
|
+
class Parameters
|
|
6
|
+
attr_accessor :api_method, :uri
|
|
7
|
+
attr_reader :method_parameters
|
|
8
|
+
|
|
9
|
+
def initialize(request_method)
|
|
10
|
+
load_yaml_settings
|
|
11
|
+
check_for_valid_api_method request_method
|
|
12
|
+
@api_method = "#{request_method}"
|
|
13
|
+
@uri = api_settings[api_method]['uri']
|
|
14
|
+
define_parameter_methods(api_method)
|
|
15
|
+
yield self if block_given?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_hash
|
|
19
|
+
converted_hash = Hash.new
|
|
20
|
+
method_parameters.keys.each do |root|
|
|
21
|
+
if method_parameters[root].is_a? Hash ## has child
|
|
22
|
+
converted_hash[root] = Hash.new
|
|
23
|
+
method_parameters[root].keys.each do |child|
|
|
24
|
+
if method_parameters[root][child].is_a? Hash ## has grand_child
|
|
25
|
+
method_parameters[root].keys.each do |grand_child|
|
|
26
|
+
converted_hash[root][child][grand_child] = self.send("#{root}_#{child}_#{grand_child}") ## GrandChild
|
|
27
|
+
end
|
|
28
|
+
elsif method_parameters[root][child].is_a? Array
|
|
29
|
+
converted_hash[root][child] = self.send("#{root}_#{child}").to_hash ## Child Array
|
|
30
|
+
else
|
|
31
|
+
converted_hash[root][child] = self.send("#{root}_#{child}") ## Child
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
elsif method_parameters[root].is_a? Array
|
|
35
|
+
converted_hash[root] = self.send("#{root}").to_hash ## root Array
|
|
36
|
+
else
|
|
37
|
+
converted_hash[root] = self.send("#{root}") ## No children
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
converted_hash
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def http_method
|
|
44
|
+
( api_settings[api_method]['http_method'] || 'post' ).to_sym
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_json
|
|
48
|
+
self.to_hash.delete_if{ |k, v| v.nil? }.to_json
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def method_missing(meth, *args, &block)
|
|
52
|
+
super
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def api_settings
|
|
56
|
+
@settings
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def check_for_valid_api_method(api_method)
|
|
62
|
+
raise "api_method must be defined in initialization" if api_method.nil?
|
|
63
|
+
raise "Request Type #{api_method} not found" if api_settings[api_method].nil?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def load_yaml_settings
|
|
67
|
+
file = File.open API_SETTINGS_PATH
|
|
68
|
+
@settings = YAML.load file
|
|
69
|
+
raise 'api_settings.yml NOT FOUND' if @settings.nil? || @settings.empty?
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def define_parameter_methods(api_method)
|
|
73
|
+
@method_parameters = api_settings[api_method]['parameters']
|
|
74
|
+
|
|
75
|
+
self.instance_eval do
|
|
76
|
+
@method_parameters.each do |root_key,root_value|
|
|
77
|
+
if ( root_value == 'optional' ) || ( root_value == 'required' ) || ( root_value == 'conditionally_required' )
|
|
78
|
+
self.singleton_class.class_eval "attr_accessor :#{root_key}"
|
|
79
|
+
elsif root_value.is_a? Array
|
|
80
|
+
### COLLECTION! key should be plural
|
|
81
|
+
self.singleton_class.class_eval "attr_accessor :#{root_key}"
|
|
82
|
+
camel_key = plural_key.camelize
|
|
83
|
+
eval "@#{root_key} = #{camel_key}.new"
|
|
84
|
+
elsif root_value.is_a? Hash
|
|
85
|
+
root_value.each do |child_key,child_value|
|
|
86
|
+
if root_value[child_key].is_a? Hash
|
|
87
|
+
## Child HAS Child ( grand_child is leaf )
|
|
88
|
+
root_value[child_key].each do |grand_child_key,grand_child_value|
|
|
89
|
+
if ( grand_child_value == 'optional' ) || ( grand_child_value == 'required' ) || ( grand_child_value == 'conditionally_required' )
|
|
90
|
+
self.singleton_class.class_eval "attr_accessor :#{root_key}_#{child_key}_#{grand_child_key}"
|
|
91
|
+
else
|
|
92
|
+
raise "Invalid Configuration: Leaf Should be 'required' OR 'optional'"
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
elsif root_value[child_key].is_a? Array
|
|
96
|
+
self.singleton_class.class_eval "attr_accessor :#{root_key}_#{child_key}"
|
|
97
|
+
camel_key = "#{child_key}".camelize
|
|
98
|
+
eval "@#{root_key}_#{child_key} = #{camel_key}.new"
|
|
99
|
+
else
|
|
100
|
+
## Child has no child ( child is leaf )
|
|
101
|
+
if ( child_value == 'optional' ) || ( child_value == 'required' ) || ( child_value == 'conditionally_required' )
|
|
102
|
+
self.singleton_class.class_eval "attr_accessor :#{root_key}_#{child_key}"
|
|
103
|
+
else
|
|
104
|
+
raise "Invalid Configuration: Leaf Should be 'required' OR 'optional'"
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
else
|
|
109
|
+
raise "Invalid Configuration: Leaf Should be 'required' OR 'optional'"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module SurveyMonkey
|
|
2
|
+
class Recipient
|
|
3
|
+
attr_accessor :email, :first_name, :last_name, :custom_id
|
|
4
|
+
|
|
5
|
+
def intialize(options = {})
|
|
6
|
+
email = options[:email]
|
|
7
|
+
first_name = options[:first_name]
|
|
8
|
+
first_name = options[:first_name]
|
|
9
|
+
last_name = options[:last_name]
|
|
10
|
+
custom_id = options[:custom_id]
|
|
11
|
+
|
|
12
|
+
raise "Email Required for Recipient" if email.nil?
|
|
13
|
+
end
|
|
14
|
+
def to_hash
|
|
15
|
+
{ email: email, name: name, last_name: last_name, custom_id: custom_id }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module SurveyMonkey
|
|
2
|
+
class Recipients
|
|
3
|
+
include Enumerable
|
|
4
|
+
|
|
5
|
+
def initialize(*recipients)
|
|
6
|
+
@recipients = ( recipients || Array.new )
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def each(&block)
|
|
10
|
+
@recipients.each do |recipient|
|
|
11
|
+
block.call(recipient)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def <<(recipient)
|
|
16
|
+
@recipients << recipient
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_hash
|
|
20
|
+
map { |e| e.as_json }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module SurveyMonkey
|
|
2
|
+
class Request
|
|
3
|
+
attr_accessor :api_method, :uri, :request, :parameters, :response
|
|
4
|
+
|
|
5
|
+
def initialize(options={})
|
|
6
|
+
@auth = options[:auth] || Auth.new
|
|
7
|
+
@api_method = options[:api_method].to_s
|
|
8
|
+
@init_parameters = options[:params]
|
|
9
|
+
|
|
10
|
+
@api_key = @auth.api_key
|
|
11
|
+
@access_token = @auth.access_token
|
|
12
|
+
|
|
13
|
+
### Instantiate Parameters based on API method
|
|
14
|
+
@parameters = Parameters.new(@api_method)
|
|
15
|
+
@uri = @parameters.uri
|
|
16
|
+
|
|
17
|
+
# If options[:params] was spet, set parameters now
|
|
18
|
+
if @init_parameters.respond_to? :each
|
|
19
|
+
set_parameters do |p|
|
|
20
|
+
@init_parameters.each do |key,value|
|
|
21
|
+
p.send "#{key}=", value
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def set_parameters
|
|
28
|
+
yield @parameters if block_given?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def request_body
|
|
32
|
+
### Params to be included in Body of request, should be a JSON encoded string
|
|
33
|
+
@parameters.to_json
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def request_method
|
|
37
|
+
@parameters.http_method
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def request_params
|
|
41
|
+
### Params to be URL Encoded
|
|
42
|
+
Hash['api_key' => api_key]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def request_header
|
|
46
|
+
### Header includes content-type and access token
|
|
47
|
+
Hash["Authorization" => "bearer #{access_token}", "Content-Type" => "application/json"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def request_url
|
|
51
|
+
uri
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def build_request
|
|
55
|
+
@request = Typhoeus::Request.new(request_url, method: request_method, body: request_body, params: request_params, headers: request_header)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def run_request
|
|
59
|
+
request = build_request
|
|
60
|
+
request.on_complete do |response|
|
|
61
|
+
if response.success?
|
|
62
|
+
@response = response
|
|
63
|
+
elsif response.timed_out?
|
|
64
|
+
@response = "Response timed out"
|
|
65
|
+
elsif response.code == 0
|
|
66
|
+
# Could not get an http response, something's wrong.
|
|
67
|
+
@response = response.return_message
|
|
68
|
+
else
|
|
69
|
+
# Received a non-successful http response.
|
|
70
|
+
@response = "HTTP request failed: #{response.code}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
request.run
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def set_on_complete_response
|
|
77
|
+
@request.on_complete do |response|
|
|
78
|
+
if response.success?
|
|
79
|
+
@response = response
|
|
80
|
+
elsif response.timed_out?
|
|
81
|
+
@response = "Response timed out"
|
|
82
|
+
elsif response.code == 0
|
|
83
|
+
# Could not get an http response, something's wrong.
|
|
84
|
+
@response = response.return_message
|
|
85
|
+
else
|
|
86
|
+
# Received a non-successful http response.
|
|
87
|
+
@response = "HTTP request failed: #{response.code}"
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def result
|
|
93
|
+
JSON.parse @response.body
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
private
|
|
97
|
+
def api_key
|
|
98
|
+
@api_key
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def access_token
|
|
102
|
+
@access_token
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require "dotenv"
|
|
2
|
+
require "active_record"
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "json"
|
|
5
|
+
require "typhoeus"
|
|
6
|
+
require "yaml"
|
|
7
|
+
require "survey_monkey/config"
|
|
8
|
+
require "survey_monkey/version"
|
|
9
|
+
require "survey_monkey/request"
|
|
10
|
+
require "survey_monkey/auth"
|
|
11
|
+
require "survey_monkey/parameters"
|
|
12
|
+
|
|
13
|
+
module SurveyMonkey
|
|
14
|
+
def self.request(options)
|
|
15
|
+
Request.new(options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.load_yaml_settings
|
|
19
|
+
file = File.open API_SETTINGS_PATH
|
|
20
|
+
settings = YAML.load file
|
|
21
|
+
raise 'api_settings.yml NOT FOUND' if settings.nil? || settings.empty?
|
|
22
|
+
settings
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.method_missing(meth, *args, &block)
|
|
26
|
+
settings = SurveyMonkey.load_yaml_settings
|
|
27
|
+
settings.keys.each do |key|
|
|
28
|
+
if ( key.to_s == meth.to_s )
|
|
29
|
+
if args.empty?
|
|
30
|
+
return Request.new( Hash[api_method: meth] )
|
|
31
|
+
else
|
|
32
|
+
options = args.first
|
|
33
|
+
options.merge!(Hash[api_method: meth])
|
|
34
|
+
return Request.new(options)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
super
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'survey_monkey/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "survey_monkey"
|
|
8
|
+
spec.version = SurveyMonkey::VERSION
|
|
9
|
+
spec.authors = ["Nick Dawson"]
|
|
10
|
+
spec.email = ["wdawson4@me.com"]
|
|
11
|
+
spec.summary = %q{This is a ruby interface for the SurveyMonkey.com API.}
|
|
12
|
+
spec.description = %q{This is a ruby interface for the SurveyMonkey.com API}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_runtime_dependency "typhoeus", "~> 0.6.9"
|
|
22
|
+
spec.add_runtime_dependency "activerecord", "~> 4.0.2"
|
|
23
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.2"
|
|
24
|
+
spec.add_runtime_dependency "dotenv", "~> 1.0.2"
|
|
25
|
+
|
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
27
|
+
spec.add_development_dependency "rake"
|
|
28
|
+
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: survey_monkey
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nick Dawson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: typhoeus
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.6.9
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.6.9
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 4.0.2
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 4.0.2
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activesupport
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 4.0.2
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 4.0.2
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: dotenv
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 1.0.2
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.0.2
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: bundler
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.5'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.5'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rake
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: This is a ruby interface for the SurveyMonkey.com API
|
|
98
|
+
email:
|
|
99
|
+
- wdawson4@me.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".rvmrc"
|
|
106
|
+
- Gemfile
|
|
107
|
+
- LICENSE.txt
|
|
108
|
+
- README.md
|
|
109
|
+
- Rakefile
|
|
110
|
+
- config/survey_monkey.env.example
|
|
111
|
+
- lib/config/api_settings.yml
|
|
112
|
+
- lib/survey_monkey.rb
|
|
113
|
+
- lib/survey_monkey/auth.rb
|
|
114
|
+
- lib/survey_monkey/config.rb
|
|
115
|
+
- lib/survey_monkey/parameters.rb
|
|
116
|
+
- lib/survey_monkey/recipient.rb
|
|
117
|
+
- lib/survey_monkey/recipients.rb
|
|
118
|
+
- lib/survey_monkey/request.rb
|
|
119
|
+
- lib/survey_monkey/version.rb
|
|
120
|
+
- survey_monkey.gemspec
|
|
121
|
+
homepage: ''
|
|
122
|
+
licenses:
|
|
123
|
+
- MIT
|
|
124
|
+
metadata: {}
|
|
125
|
+
post_install_message:
|
|
126
|
+
rdoc_options: []
|
|
127
|
+
require_paths:
|
|
128
|
+
- lib
|
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
|
+
requirements:
|
|
131
|
+
- - ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: '0'
|
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
requirements: []
|
|
140
|
+
rubyforge_project:
|
|
141
|
+
rubygems_version: 2.2.0
|
|
142
|
+
signing_key:
|
|
143
|
+
specification_version: 4
|
|
144
|
+
summary: This is a ruby interface for the SurveyMonkey.com API.
|
|
145
|
+
test_files: []
|