SurveyMonkey
Installation
Add this line to your application's Gemfile:
gem 'survey_monkey'
And then execute:
$ bundle
Or install it yourself as:
$ gem install survey_monkey
Usage
To Authenticate, you have two options:
Option 1: Use ENV Variables:
# Set the following variables ( the gem is configured to use dotenv.
# rename the config/survey_monkey.env.example file to config/survey_monkey.env and fill in your info )
# make sure to add config/survey_monkey.env to your .gitignore
# if you wish to use a different filename, provide it in the api_credentials options hash under :file_name
ENV['SURVEY_MONKEY_ACCESS_TOKEN']
ENV['SURVEY_MONKEY_API_KEY']
ENV['SURVEY_MONKEY_CLIENT_SECRET']
ENV['SURVEY_MONKEY_CLIENT_ID']
Option 2: Create an instance of SurveyMonkey::Auth with the credentials.
api_credentials = {
access_token: 'accesstoken',
api_key: 'apikey',
client_secret: 'clientsecret',
client_id: 'clientid'
}
auth = SurveyMonkey::Auth.new(api_credentials)
# supply your own auth when you create the new request
Define the method you wish to use:
api_method = 'get_survey_list'
Make the request:
# Create the request
# if ENV vars were used, auth can be excluded from options hash
# params can be excluded or nil to set with set_params method and a block
= {api_method: api_method, auth: auth, params: nil}
api_request = SurveyMonkey::Request.new(api_method)
# Set the parameters
api_request.set_parameters do |p|
p.page = 1
p.page_size = 10
p.order_asc = 'true'
end
# Run the request
api_request.run_request
# View the result
result = api_request.result
Quick Requests
# A shortcut for specifying params is to use a hash instead of the block.
# The params_hash is passed in the options hash under the :params key
# e.g.
params_hash = {page_size: 10, page: 1, order_asc: 'true'}
= {params: params_hash}
# A shortcut for making requests using default options is to simply call
# SurveyMonkey.method where method is the name of the API method you wish to call
# e.g.
api_request = SurveyMonkey.get_survey_list
# Run the request
api_request.run_request
# View the result
result = api_request.result
TODO
Add tests!
Contributing
- Fork it ( http://github.com/wdawson4/survey_monkey/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request