Sha256: 7e9daf404a33a25fd745b54ed83d554897512ecd5f52ef2528646f1691588d98

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require "logging"

require "surveymonkey/version"
require "surveymonkey/logging"
require "surveymonkey/request"

##
# Top-level module, holds the user-facing methods

module Surveymonkey

  class << self
    # Constants

    # Public methods

    ##
    # Catch-all method; matches SurveyMonkey API method names.  Call like so:
    #  
    #  Surveymonkey.get_user_details({'method_params' => {'foo' => 'bar'}})

    def method_missing(method_name, *args)
      begin
        $log.debug(sprintf("%s: %s\n", __method__, 'enter'))

        method_params = Hash(Array(args).shift) || {}
        $log.debug(sprintf("%s: method_params: %s\n", __method__, method_params.inspect))

        request = Surveymonkey::Request.new(method_name.to_s, method_params)
        response = request.execute
        response

      rescue TypeError => e
        $log.fatal(sprintf("%s: method parameters must be a hash\n", __method__))
        exit 1
      rescue KeyError => e
        $log.fatal(sprintf("%s: method '%s' not implemented\n", __method__, method_name.to_s))
        exit 1
      rescue StandardError => e
        $log.error(sprintf("%s: %s\n", __method__, e.message))
        raise
      end
    end

    # Private methods
    private

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
surveymonkey-0.3.0 lib/surveymonkey.rb
surveymonkey-0.2.2 lib/surveymonkey.rb
surveymonkey-0.2.1 lib/surveymonkey.rb