class RubyMeetup::Client

This class is abstract. It has accessor methods for configuring the API site. By default it is set to api.meetup.com but may be changed using the class setter method site=.

The gem supports API request with two authentication strategies: API Key and OAuth 2 via the concrete classes ApiKeyClient and AuthenticatedClient, respectively. More information can be found in the specific class documentation.

Example usage:

> require 'ruby_meetup'
> RubyMeetup::ApiKeyClient.key = 'abcd000000000000000wxyz'
> client = RubyMeetup::ApiKeyClient.new
> json_string = client.get_path("/2/groups", {:group_id => 390230})
> second_result = client.get({:group_id => 939203})

If successful the captured response is a raw JSON string. The response can then be processed using a JSON parser. Otherwise an exception is raised.

Typically, ApiKeyClient class is used to read data while the AuthenticatedClient class is used for both read and write data, subject to Meetup API permission scopes.


Copyright © 2013 Long On, released under the MIT license

Attributes

path[RW]

Public Class Methods

site() click to toggle source

Retun the configured API endpoint

# File lib/ruby_meetup.rb, line 44
def self.site
  @@site
end
site=(string) click to toggle source

Set the global API endpoint

# File lib/ruby_meetup.rb, line 48
def self.site=string
  @@site = string
end

Public Instance Methods

get(options={}) click to toggle source

Make a GET API call with the current path value and @options. Return a JSON string if successful, otherwise an Exception

# File lib/ruby_meetup.rb, line 68
def get(options={})
  uri = new_uri
  params = merge_params(options)
  uri.query = URI.encode_www_form(params)

  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Get.new(uri)
    response = http.request(request)
    unless response.is_a?(Net::HTTPSuccess)
      raise "#{response.code} #{response.message}\n#{response.body}"
    end
    return response.body
  end
end
get_path(path, options={}) click to toggle source

A convenience method to set @path and @options in the same API call. Return a JSON string if successful, otherwise an Exception

# File lib/ruby_meetup.rb, line 56
def get_path(path, options={})
  self.path = path
  get(options)
end
post(options={}) click to toggle source

Make a POST API call with the current path value and @options. Return a JSON string if successful, otherwise an Exception

# File lib/ruby_meetup.rb, line 85
def post(options={})
  uri = new_uri
  params = merge_params(options)
  uri.query = URI.encode_www_form(params)

  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    request = Net::HTTP::Post.new(uri)
    response = http.request(request)
    unless response.is_a?(Net::HTTPSuccess)
      raise "#{response.code} #{response.message}\n#{response.body}"
    end
    return response.body
  end
end
post_path(path, options={}) click to toggle source
# File lib/ruby_meetup.rb, line 61
def post_path(path, options={})
  self.path = path
  post(options)
end