Class: RpiUnion::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rpi_union.rb

Constant Summary collapse

API_BASE_URI =
'http://api.union.rpi.edu/query.php'
GET_USER_TASK =
'GetUser'
LIST_ALL_ORGANIZATIONS_TASK =
'ListAllOrganizations'
GET_ORGANIZATION_TASK =
'GetOrganization'
GET_USER_ORGS_TASK =
'GetUserOrgs'

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Initialize a new Client with the specified API key



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

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#get_organization(id) ⇒ Hash

Get information about a club

Parameters:

  • id (Int)

    The ID of the club

Returns:

  • (Hash)

    The result of the API call. Send an example request to see the format.



60
61
62
63
# File 'lib/rpi_union.rb', line 60

def get_organization(id)
  opts = { :query => { :id => id } }
  get_with_key_task(GET_ORGANIZATION_TASK, opts)
end

#get_user(options = {}) ⇒ Hash

Get the properties of a specific user.

Parameters:

  • options (Hash) (defaults to: {})

    Must contain one of: ‘:rin`, `:id` (API/database ID), or `rcsid`

Returns:

  • (Hash)

    The output of the API call. This is of the form: ‘…, “rin”: …, “phone”: …, “class”: …`



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rpi_union.rb', line 26

def get_user(options = {})
  opts = {}
  opts[:query] = {}

  if options.key?(:rin)
    opts[:query][:rin] = options[:rin]
  elsif options.key?(:rcsid)
    opts[:query][:rcsid] = options[:rcsid]
  elsif options.key?(:id)
    opts[:query][:dbid] = options[:id]
  else
    raise "You must pass one of the following as an option to get_user(): "+
      "'rin', 'rcsid', or 'id'"
  end

  # Set middlename if it was pass in options
  if options.key?(:middlename)
    opts[:query][:middlename] = options[:middlename]
  end

  get_with_key_task(GET_USER_TASK, opts)
end

#get_user_orgs(rin) ⇒ Object

Get the IDs of all the clubs of which the user is an officer

Parameters:

  • rin (Int)

    The RIN of the user to search for.



68
69
70
71
# File 'lib/rpi_union.rb', line 68

def get_user_orgs(rin)
  opts = { :query => { :rin => rin } }
  get_with_key_task(GET_USER_ORGS_TASK, opts)
end

#list_all_organizationsArray

Get all of the Union clubs

Returns:

  • (Array)

    An array of hashes of the form ‘…, “club_name”: …`



52
53
54
# File 'lib/rpi_union.rb', line 52

def list_all_organizations
  get_with_key_task(LIST_ALL_ORGANIZATIONS_TASK)
end