Skip to content

Commit 70bdf29

Browse files
author
Jason Berlinsky
committed
Merge pull request #4 from carpeliam/master
add support for API versioning, including v2 support for events
2 parents ee2194d + 883c16c commit 70bdf29

45 files changed

Lines changed: 493 additions & 397 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
.DS_Store
2-
pkg/
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
Gemfile.lock
7+
InstalledFiles
8+
_yardoc
9+
coverage
10+
doc/
11+
lib/bundler/man
12+
pkg
13+
rdoc
14+
spec/reports
15+
test/tmp
16+
test/version_tmp
17+
tmp

Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
source :rubygems
2-
gem 'json'
3-
gem 'rspec'
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in rmeetup.gemspec
4+
gemspec

Gemfile.lock

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
PATH
2+
remote: .
3+
specs:
4+
rMeetup (1.1.0)
5+
json
6+
17
GEM
2-
remote: http://rubygems.org/
8+
remote: https://rubygems.org/
39
specs:
410
diff-lcs (1.1.3)
5-
json (1.6.6)
11+
json (1.8.1)
12+
rake (10.1.1)
613
rspec (2.8.0)
714
rspec-core (~> 2.8.0)
815
rspec-expectations (~> 2.8.0)
@@ -16,5 +23,7 @@ PLATFORMS
1623
ruby
1724

1825
DEPENDENCIES
19-
json
26+
bundler (~> 1.3)
27+
rMeetup!
28+
rake
2029
rspec

Rakefile

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
require 'rubygems'
2-
require 'rake'
3-
require 'echoe'
4-
5-
Echoe.new('rMeetup','1.0') do |p|
6-
p.description = "A simple Ruby gem, providing access to the Meetup API"
7-
p.url = "https://github.com/Jberlinsky/rmeetup"
8-
p.author = "Jason Berlinsky"
9-
p.email = "jason@jasonberlinsky.com"
10-
p.ignore_pattern = ["tmp/*", "script/*"]
11-
p.development_dependencies = []
12-
end
13-
14-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
1+
require "bundler/gem_tasks"

lib/rmeetup.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,74 @@
55
require 'rmeetup/type'
66
require 'rmeetup/collection'
77
require 'rmeetup/fetcher'
8+
require 'rmeetup/version'
89

910
module 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

lib/rmeetup/fetcher.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ module RMeetup
1212
module Fetcher
1313

1414
class << self
15-
# Return a fetcher for given type
16-
def for(type)
15+
# Return a fetcher for given type/API version
16+
def for(type, api_version = nil)
1717
return case type.to_sym
1818
when :topics
19-
Topics.new
19+
Topics.new(api_version)
2020
when :cities
21-
Cities.new
21+
Cities.new(api_version)
2222
when :members
23-
Members.new
23+
Members.new(api_version)
2424
when :rsvps
25-
Rsvps.new
25+
Rsvps.new(api_version)
2626
when :events
27-
Events.new
27+
Events.new(api_version)
2828
when :groups
29-
Groups.new
29+
Groups.new(api_version)
3030
when :comments
31-
Comments.new
31+
Comments.new(api_version)
3232
when :photos
33-
Photos.new
33+
Photos.new(api_version)
3434
end
3535
end
3636
end

lib/rmeetup/fetcher/base.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ def initialize
1717
# Base fetcher class that other fetchers
1818
# will inherit from.
1919
class Base
20-
def initialize
20+
MAX_API_VERSION = nil
21+
def initialize(api_version = nil)
22+
@api_version = if api_version
23+
self.class::MAX_API_VERSION && [api_version, self.class::MAX_API_VERSION].min
24+
else
25+
self.class::MAX_API_VERSION
26+
end
2127
@type = nil
2228
end
2329

@@ -57,7 +63,8 @@ def build_url(options)
5763
end
5864

5965
def base_url
60-
"http://api.meetup.com/#{@type}.json/"
66+
versioned_url = "#{@api_version}/" if @api_version.to_i > 1
67+
"http://api.meetup.com/#{versioned_url}#{@type}.json/"
6168
end
6269

6370
# Create a query string from an options hash

lib/rmeetup/fetcher/cities.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module RMeetup
22
module Fetcher
33
class Cities < Base
4-
def initialize
4+
def initialize(api_version = nil)
5+
super(api_version) # no support for API versioning yet
56
@type = :cities
67
end
78

89
# Turn the result hash into a City Class
910
def format_result(result)
10-
RMeetup::Type::City.new(result)
11+
RMeetup::Type::V1::City.new(result)
1112
end
1213
end
1314
end

lib/rmeetup/fetcher/comments.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
module RMeetup
22
module Fetcher
33
class Comments < Base
4-
def initialize
4+
def initialize(api_version = nil)
5+
super(api_version) # no support for API versioning yet
56
@type = :comments
67
end
78

89
# Turn the result hash into a Comment Class
910
def format_result(result)
10-
RMeetup::Type::Comment.new(result)
11+
RMeetup::Type::V1::Comment.new(result)
1112
end
1213
end
1314
end

lib/rmeetup/fetcher/events.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
module RMeetup
22
module Fetcher
33
class Events < Base
4-
def initialize
4+
MAX_API_VERSION = 2
5+
def initialize(api_version = nil)
6+
super(api_version)
57
@type = :events
68
end
79

810
# Turn the result hash into a Event Class
911
def format_result(result)
10-
RMeetup::Type::Event.new(result)
12+
if @api_version == 1
13+
RMeetup::Type::V1::Event.new(result)
14+
else
15+
RMeetup::Type::V2::Event.new(result)
16+
end
1117
end
1218
end
1319
end

0 commit comments

Comments
 (0)