module Surveymonkey

Top-level module, holds the user-facing methods

Specify the version of the surveymonkey gem.

Constants

DateStringParams

Method params that take DateStrings

DefaultPageSize

Default page size for paginated API requests

PaginatedMethods

API methods that support pagination

VERSION

Public Class Methods

method_missing(method_name, *args) click to toggle source

Catch-all method; matches SurveyMonkey API method names. Call like so:

Surveymonkey.get_user_details({'foo' => 'bar'})
# File lib/surveymonkey.rb, line 50
def method_missing(method_name, *args)
  begin
    $log.debug sprintf("%s: %s", __method__, 'enter')

    the_args = Hash(Array(args).shift) || {}

    # extract page_size if passed in args
    page_size = the_args.delete('page_size') { |key| DefaultPageSize }.to_i
    $log.debug sprintf("%s: page_size: %i", __method__, page_size)

    method_params = parse_datestrings(the_args)
    $log.debug sprintf("%s: method_params: %s", __method__, method_params.inspect)

    # is this a paginated method?
    pagination_field = PaginatedMethods.fetch(method_name, nil)
    if pagination_field
      $log.info sprintf("calling method '%s' with pagination, page size %i", method_name, page_size)
      paginate_request(method_name, pagination_field, page_size, method_params)
    else
      $log.info sprintf("calling method '%s' without pagination", method_name)
      execute_request(method_name, method_params)
    end

  rescue TypeError => e
    $log.fatal sprintf("%s: method parameters must be a hash", __method__)
    exit 1

  rescue KeyError => e
    $log.fatal sprintf("%s: method '%s' not implemented", __method__, method_name.to_s)
    exit 1

  rescue StandardError => e
    $log.error sprintf("%s: %s", __method__, e.message)
    raise e

  end
end