Class: RMeetup::Poster::Base

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

Overview

RMeetup::Poster::Base

Base poster class that other posters will inherit from.

Direct Known Subclasses

Event, EventComment

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



28
29
30
31
# File 'lib/rmeetup/poster/base.rb', line 28

def initialize
  @type = nil
  @response_type = ResponseType::BASIC_RESPONSE
end

Instance Method Details

#post(options = {}) ⇒ Object

Fetch and parse a response based on a set of options. Override this method to ensure neccessary options are passed for the request.

Raises:

  • (NotConfiguredError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rmeetup/poster/base.rb', line 38

def post(options = {})
  raise NotConfiguredError, /posts only possible with a concrete type/ if @type.nil?

  url = build_url(options)
  res = post_response(url, options)
  response_body = res.body
  data = JSON.parse(response_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'], url)
    else
      raise NoResponseError.new
    end
  end

  case @response_type
    when ResponseType::OBJECT
      format_result(data)
    else
      res
  end
end