class RMeetup::Destroyer::Base

RMeetup::Destroyer::Base

Base destroyer class that other destroyers will inherit from.

Public Class Methods

new() click to toggle source
# File lib/rmeetup/destroyer/base.rb, line 21
def initialize
  @type = nil
  @id = nil
end

Public Instance Methods

build_path(options) click to toggle source
# File lib/rmeetup/destroyer/base.rb, line 50
def build_path(options)
  base_url + query(options)
end
delete(options = {}) click to toggle source

Delete and return a response based on a set of options. Override this method to ensure necessary options are passed for the request.

@param options [Hash] Options for deleting, it’s usually empty except the api key @return True on success

# File lib/rmeetup/destroyer/base.rb, line 31
def delete(options = {})
  raise NotConfiguredError, /deletes only possible with a concrete destroyer/ if @type.nil?

  res = delete_response(base_url, options)
  data = JSON.parse(res.body)

  unless res.is_a?(Net::HTTPSuccess)

    # Check to see if the api returned an error
    if data.has_key?('problem')
      raise ApiError.new(data['details'], build_path(options))
    else
      raise NoResponseError.new
    end
  end

  true
end
query(options) click to toggle source

Create a query string from an options hash

# File lib/rmeetup/destroyer/base.rb, line 55
def query(options)
  '?' + URI.encode_www_form(options)
end

Protected Instance Methods

base_url() click to toggle source
# File lib/rmeetup/destroyer/base.rb, line 68
def base_url
  "https://api.meetup.com/2/#{@type}/#{@id}"
end
delete_response(url, options) click to toggle source
# File lib/rmeetup/destroyer/base.rb, line 72
def delete_response(url, options)
  path = url + query(options)
  req = Net::HTTP.new DOMAIN, 443
  req.use_ssl = true
  req.delete(path)
end
format_result(result) click to toggle source

OVERRIDE this method to format a result section as per Result type. Takes a result in a collection and formats it to be put back into the collection.

# File lib/rmeetup/destroyer/base.rb, line 64
def format_result(result)
  result
end