Class: RMeetup::Fetcher::Base
- Inherits:
-
Object
- Object
- RMeetup::Fetcher::Base
- Defined in:
- lib/rmeetup/fetcher/base.rb
Overview
RMeetup::Fetcher::Base
Base fetcher class that other fetchers will inherit from.
Direct Known Subclasses
Cities, Events, Groups, Members, OpenEvents, OpenVenues, Photos, Rsvps, Venues
Instance Method Summary collapse
- #base_path ⇒ Object
-
#fetch(options = {}) ⇒ RMeetup::Collection
Fetch and parse a response based on a set of options.
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #path_and_query(options) ⇒ Object
-
#query(options) ⇒ Object
Create a query string from an options hash.
-
#requester(q) ⇒ Net:HTTP, Net:HTTPS
Decides whether to use HTTP or HTTPS.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
21 22 23 |
# File 'lib/rmeetup/fetcher/base.rb', line 21 def initialize @type = nil end |
Instance Method Details
#base_path ⇒ Object
50 51 52 |
# File 'lib/rmeetup/fetcher/base.rb', line 50 def base_path "/2/#{@type}" end |
#fetch(options = {}) ⇒ RMeetup::Collection
Fetch and parse a response based on a set of options. Override this method to ensure neccessary options are passed for the request.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rmeetup/fetcher/base.rb', line 29 def fetch( = {}) raise NotConfiguredError, /fetches only possible with a concrete fetcher/ if @type.nil? path = path_and_query() # Fetch and parse data from Meetup response_body = requester().get(path).body || raise(NoResponseError.new) data = JSON.parse(response_body) # Check to see if the api returned an error raise ApiError.new(data['details'],path) 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 |
#path_and_query(options) ⇒ Object
46 47 48 |
# File 'lib/rmeetup/fetcher/base.rb', line 46 def path_and_query() base_path + query() end |
#query(options) ⇒ Object
Create a query string from an options hash
55 56 57 |
# File 'lib/rmeetup/fetcher/base.rb', line 55 def query() '?' + URI.encode_www_form() end |
#requester(q) ⇒ Net:HTTP, Net:HTTPS
Decides whether to use HTTP or HTTPS. HTTPS is needed if we’re authoizing via the :access_token
64 65 66 67 68 69 70 71 72 |
# File 'lib/rmeetup/fetcher/base.rb', line 64 def requester(q) if q.has_key?(:api_key) http elsif q.has_key?(:access_token) https else http end end |