Class: RMeetup::Destroyer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rmeetup/destroyer/base.rb

Overview

RMeetup::Destroyer::Base

Base destroyer class that other destroyers will inherit from.

Direct Known Subclasses

Event, EventComment, MemberPhoto, Photo

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



21
22
23
24
# File 'lib/rmeetup/destroyer/base.rb', line 21

def initialize
  @type = nil
  @id = nil
end

Instance Method Details

#build_path(options) ⇒ Object



50
51
52
# File 'lib/rmeetup/destroyer/base.rb', line 50

def build_path(options)
  base_url + query(options)
end

#delete(options = {}) ⇒ Object

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

Parameters:

  • options (Hash) (defaults to: {})

    Options for deleting, it’s usually empty except the api key

Returns:

  • True on success

Raises:

  • (NotConfiguredError)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object

Create a query string from an options hash



55
56
57
# File 'lib/rmeetup/destroyer/base.rb', line 55

def query(options)
  '?' + URI.encode_www_form(options)
end