Class: Surveymonkey::API::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/surveymonkey/api/method.rb

Overview

Object representing a SurveyMonkey API method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, http_method = 'post') ⇒ Method

Create a new method. Does some input validation to make sure the associated HTTP method is valid.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/surveymonkey/api/method.rb', line 13

def initialize(path, http_method = 'post')
  begin
    $log.debug(sprintf("%s: enter", __method__))

    # FIXME validate the path
    @path = path

    # validate the method
    $log.debug(sprintf("%s:http_method: '%s'\n", __method__, http_method))
    the_method = http_method.to_s.downcase
    $log.debug(sprintf("%s:the_method: '%s'\n", __method__, the_method))

    if the_method =~ /^(get|post|patch|put|delete|move|copy|head|options)$/
      @http_method = the_method
      $log.debug(sprintf("%s: method: %s", __method__, the_method))
    else
      raise StandardError, "'#{the_method}' is not a valid HTTP method", caller
    end

  rescue StandardError => e
    $log.error(sprintf("%s: unable to initialize API method: %s\n", __method__, e.message))
    raise
  end
end

Instance Attribute Details

#http_methodObject (readonly)

Returns the value of attribute http_method.



7
8
9
# File 'lib/surveymonkey/api/method.rb', line 7

def http_method
  @http_method
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/surveymonkey/api/method.rb', line 7

def path
  @path
end