class UWAPI::API

Public Class Methods

new(args) click to toggle source
# File lib/uwapi.rb, line 51
def initialize(args)
  if args.include?(:api_key)
    @api_key = args[:api_key]
  else
    raise ArgumentError, ':api_key is required. See http://api.uwaterloo.ca/'
  end
  @api_format = args[:api_format] if args.include?(:api_format)
  raise ArgumentError, ':api_format must be one of [json, xml]' unless ['json', 'xml'].include?(api_format)
end

Public Instance Methods

api_format() click to toggle source
# File lib/uwapi.rb, line 61
def api_format
  @api_format ||= 'json'
end
api_key() click to toggle source
# File lib/uwapi.rb, line 69
def api_key
  @api_key
end
api_url() click to toggle source
# File lib/uwapi.rb, line 65
def api_url
  'http://api.uwaterloo.ca/public/v1/'
end

Private Instance Methods

get(opt) click to toggle source
# File lib/uwapi.rb, line 74
def get(opt)
  request = HTTParty.get(api_url, :query => {:key => api_key, :output => api_format}.merge(opt))
  UWAPI::Result.new(request)
end