Class: MeetupApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/meetup_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(apiKey) ⇒ Client

Returns a new instance of Client.



17
18
19
# File 'lib/meetup_api.rb', line 17

def initialize(apiKey)
  @key = apiKey
end

Instance Method Details

#fetch(uri, url_args = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/meetup_api.rb', line 49

def fetch(uri, url_args={})
  url_args['format'] = 'json'
  url_args['key'] = @key if @key
  args = URI.escape(url_args.collect{|k,v| "#{k}=#{v}"}.join('&'))
  url = "#{API_BASE_URL}#{uri}/?#{args}"
  data = Net::HTTP.get_response(URI.parse(url)).body
  
  # ugh - rate limit error throws badly formed JSON
  begin
    JSON.parse(data)
  rescue Exception => e
    raise BaseException(e)
  end
end

#get_comments(args) ⇒ Object



45
46
47
# File 'lib/meetup_api.rb', line 45

def get_comments(args)
  ApiResponse.new(fetch(COMMENTS_URI, args), Comment)
end

#get_events(args) ⇒ Object



21
22
23
# File 'lib/meetup_api.rb', line 21

def get_events(args)
  ApiResponse.new(fetch(EVENTS_URI, args), Event)
end

#get_groups(args) ⇒ Object



33
34
35
# File 'lib/meetup_api.rb', line 33

def get_groups(args)
  ApiResponse.new(fetch(GROUPS_URI, args), Group)
end

#get_members(args) ⇒ Object



29
30
31
# File 'lib/meetup_api.rb', line 29

def get_members(args)
  ApiResponse.new(fetch(MEMBERS_URI, args), Member)
end

#get_photos(args) ⇒ Object



37
38
39
# File 'lib/meetup_api.rb', line 37

def get_photos(args)
  ApiResponse.new(fetch(PHOTOS_URI, args), Photo)
end

#get_rsvps(args) ⇒ Object



25
26
27
# File 'lib/meetup_api.rb', line 25

def get_rsvps(args)
  ApiResponse.new(fetch(RSVPS_URI, args), Rsvp)
end

#get_topics(args) ⇒ Object



41
42
43
# File 'lib/meetup_api.rb', line 41

def get_topics(args)
  ApiResponse.new(fetch(TOPICS_URI, args), Photo)
end