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_name = 'UNSPECIFIED') ⇒ 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
37
38
# File 'lib/surveymonkey/api/method.rb', line 13

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

    # FIXME validate the path
    @path = path.to_s

    # store our short name
    @method_name = method_name.to_s

    # validate the method
    the_method = http_method.to_s.downcase
    $log.debug(sprintf("%s: the_method: '%s' (was '%s')", __method__, the_method, http_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", __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

#method_nameObject (readonly)

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#to_sObject



40
41
42
# File 'lib/surveymonkey/api/method.rb', line 40

def to_s
  self.method_name
end