Class: RMeetup::Poster::Base
- Inherits:
-
Object
- Object
- RMeetup::Poster::Base
- Defined in:
- lib/rmeetup/poster/base.rb
Overview
RMeetup::Poster::Base
Base poster class that other posters will inherit from.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#post(options = {}) ⇒ Object
Fetch and parse a response based on a set of options.
Constructor Details
#initialize ⇒ Base
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.
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( = {}) raise NotConfiguredError, /posts only possible with a concrete type/ if @type.nil? url = build_url() res = post_response(url, ) 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 |