class MonkeyBusiness::ApiResource

Base class for all Surveymonkey API resources

Attributes

path[RW]

Public Class Methods

new(api, options = {}, path_prefix = nil) click to toggle source
# File lib/api/api_resource.rb, line 10
def initialize(api, options = {}, path_prefix = nil)
  @api = api
  @id = options.delete(:id)
  @options = options

  resource_name = self.class
                      .name
                      .gsub(/.+::/, '')
                      .gsub(/(.)([A-Z])/, '\1_\2')
                      .downcase

  @path = "#{path_prefix}/#{resource_name}"
  @path += "/#{@id}" if @id
end

Public Instance Methods

request() click to toggle source
# File lib/api/api_resource.rb, line 25
def request
  @api.request(path, @options)
end

Private Instance Methods

fail_without_id() click to toggle source
# File lib/api/api_resource.rb, line 31
    def fail_without_id
      return if @id
      raise MonkeyBusiness::ApiMethodError, <<~MESSAGE
          ID must be provided for the following method:
            #{caller_locations(1, 1)[0].label}
          Expected:
            #{@path}/:id
          Received:
            #{@path}
        MESSAGE
    end