Module: Surveymonkey

Defined in:
lib/surveymonkey.rb,
lib/surveymonkey/version.rb,
lib/surveymonkey/datestring.rb

Overview

Specify the version of the surveymonkey gem.

Defined Under Namespace

Modules: Logging Classes: API, Client, DateString, Error, Request

Constant Summary collapse

DefaultPageSize =

Default page size for paginated API requests

1000
PaginatedMethods =

API methods that support pagination

{
  :get_survey_list     => 'surveys',
  :get_collector_list  => 'collectors',
  :get_respondent_list => 'respondents',
  :get_template_list   => 'templates',
}
DateStringParams =

Method params that take DateStrings

[
  'start_date',
  'end_date',
  'start_modified_date',
  'end_modified_date',
]
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.method_missing(method_name, *args) ⇒ Object

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

Surveymonkey.get_user_details({'foo' => 'bar'})


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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