class RMeetup::Client

RMeetup::Client

Essentially a simple wrapper to delegate requests to different fetcher classes who are responsible for fetching and parsing their own responses.

Public Class Methods

new(opts = {}) { |configuration| ... } click to toggle source

Initializes a new Client object

@param opts [Hash] Options, currenlty only for providing clinet with the auth data @yield [Configuration], object with accessors :api_key and :access_token, used for providing auth data in a backward compatible way @return [RMeetup::Client]

# File lib/rmeetup/client.rb, line 31
def initialize(opts = {})
  if not(opts.empty?)
    configuration.api_key = opts[:api_key] if opts.has_key?(:api_key)
    configuration.access_token = opts[:access_token] if opts.has_key?(:access_token)
  else
    yield(configuration) if block_given?
  end
  check_configuration!
end

Public Instance Methods

delete(type, id, options = {}) click to toggle source

Delegates to appropriate RMeetup::Destroyer

# File lib/rmeetup/client.rb, line 52
def delete(type, id, options = {})
  RMeetup::Destroyer.for(type, id).delete options.merge(auth)
end
fetch(type, options = {}) click to toggle source

Delegates to appropriate RMeetup::Fetcher

# File lib/rmeetup/client.rb, line 42
def fetch(type, options = {})
  RMeetup::Fetcher.for(type).fetch options.merge(auth)
end
post(type, options = {}) click to toggle source

Delegates to appropriate RMeetup::Poster

# File lib/rmeetup/client.rb, line 47
def post(type, options = {})
  RMeetup::Poster.for(type).post options.merge(auth)
end

Private Instance Methods

auth() click to toggle source

Construct authorization part of the query. Preferes :api_key over :access_token

@return [Hash] Authorization part of the query.

# File lib/rmeetup/client.rb, line 67
def auth
  if configuration.api_key
    { :key => configuration.api_key, :sign => 'true' }
  elsif configuration.access_token
    { :access_token => configuration.access_token }
  end
end
check_configuration!() click to toggle source

Ensures that API key is set during configuration.

@raise [RMeetup::Error::ConfigurationError] Error is raised when API key isn’t provided

# File lib/rmeetup/client.rb, line 78
def check_configuration!
  fail Error::NotConfiguredError.new unless configuration.api_key || configuration.access_token
end
configuration() click to toggle source

Creates or returns Client configuration

@return [RMeetup::Configuration] Configuration is created and returned during Client initializtion and just returned otherwise

# File lib/rmeetup/client.rb, line 60
def configuration
  @configuration ||= Configuration.new
end