Class: RMeetup::Fetcher::Base

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

Overview

RMeetup::Fetcher::Base

Base fetcher class that other fetchers will inherit from.

Direct Known Subclasses

Cities, Comments, Events, Groups, Members, Photos, Rsvps, Topics

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



20
21
22
# File 'lib/rmeetup/fetcher/base.rb', line 20

def initialize
  @type = nil
end

Instance Method Details

#fetch(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:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rmeetup/fetcher/base.rb', line 29

def fetch(options = {})
  url = build_url(options)
  
  json = get_response(url)
  data = JSON.parse(json)
  
  # Check to see if the api returned an error
  raise ApiError.new(data['details'],url) if data.has_key?('problem')
  
  collection = RMeetup::Collection.build(data)
  
  # Format each result in the collection and return it
  collection.map!{|result| format_result(result)}
end