55require 'rmeetup/type'
66require 'rmeetup/collection'
77require 'rmeetup/fetcher'
8+ require 'rmeetup/version'
89
910module RMeetup
10-
11+
1112 # RMeetup Errors
1213 class NotConfiguredError < StandardError
1314 def initialize
1415 super "Please provide your Meetup API key before fetching data."
1516 end
1617 end
17-
18+
1819 class InvalidRequestTypeError < StandardError
1920 def initialize ( type )
2021 super "Fetch type '#{ type } ' not a valid."
2122 end
2223 end
23-
24+
2425 # == RMeetup::Client
25- #
26+ #
2627 # Essentially a simple wrapper to delegate requests to
2728 # different fetcher classes who are responsible for fetching
2829 # and parsing their own responses.
2930 class Client
3031 FETCH_TYPES = [ :topics , :cities , :members , :rsvps , :events , :groups , :comments , :photos ]
31-
32+
3233 # Meetup API Key
3334 # Get one at http://www.meetup.com/meetup_api/key/
3435 # Needs to be the group organizers API Key
3536 # to be able to RSVP for other people
3637 @@api_key = nil
3738 def self . api_key ; @@api_key ; end ;
3839 def self . api_key = ( key ) ; @@api_key = key ; end ;
39-
40+
41+ # requested Meetup API Version
42+ # If set, the gem will attempt to use this
43+ # version of the API. If not set, the maximum
44+ # version for any particular type will be used.
45+ @@api_version = nil
46+ def self . api_version ; @@api_version ; end ;
47+ def self . api_version = ( version ) ; @@api_version = version ; end ;
48+
4049 def self . fetch ( type , options = { } )
4150 check_configuration!
42-
51+
4352 # Merge in all the standard options
4453 # Keeping whatever was passed in
4554 options = default_options . merge ( options )
46-
55+
4756 if FETCH_TYPES . include? ( type . to_sym )
4857 # Get the custom fetcher used to manage options, api call to get a type of response
49- fetcher = RMeetup ::Fetcher . for ( type )
58+ fetcher = RMeetup ::Fetcher . for ( type , api_version )
5059 return fetcher . fetch ( options )
5160 else
5261 raise InvalidRequestTypeError . new ( type )
5362 end
5463 end
55-
64+
5665 protected
5766 def self . default_options
5867 {
5968 :key => api_key
6069 }
6170 end
62-
71+
6372 # Raise an error if RMeetup has not been
6473 # provided with an api key
6574 def self . check_configuration!
6675 raise NotConfiguredError . new unless api_key
6776 end
6877 end
69- end
78+ end
0 commit comments