Class: CollegiateLink::Client

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

Overview

The Client is what makes the requests to CollegiateLink.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apikey, ip, sharedkey) ⇒ Client

Creates a CollegiateLink client.

Parameters:

  • apikey - The CollegiateLink “apikey” for your institution. For example, at Case Western Reserve University we go to casewestern.collegiatelink.net, so our “apikey” is “casewestern”

  • ip - The IP address that the sharedkey is approved for.

  • sharedkey - The shared key granted by CollegiateLink to your IP and institution.



13
14
15
16
17
18
19
20
21
22
# File 'lib/collegiatelink/client.rb', line 13

def initialize(apikey, ip, sharedkey)
  @params = {
    apikey: apikey,
    ip:     ip,
  }
  @opts = {
    sharedkey: sharedkey,
  }
  @@proxy = Net::HTTP
end

Class Method Details

.proxyObject



24
25
26
# File 'lib/collegiatelink/client.rb', line 24

def self.proxy
  @@proxy
end

Instance Method Details

#events(params = {}) ⇒ Object

Return a complete list of CollegiateLink::Event instances for your institution.

Required Parameters:

  • :startdate - Time instance or the Unix integral timestamp for the beginning of results.

  • :enddate - Time instance or the Unix integral timestamp for the end of results.

Optional Parameters:

See CollegiateLink::Request#initialize for a list of additional parameters that requests can use.



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/collegiatelink/client.rb', line 57

def events(params = {})
  # Default to showing events in the past 7 days
  seven_days = 7 * 24 * 60 * 60
  params[:startdate] ||= (Time.now.to_i - seven_days)
  params[:enddate]   ||= (Time.now.to_i)

  # Convert to milliseconds...
  params[:startdate] = params[:startdate].to_i * 1000
  params[:enddate]   = params[:enddate].to_i * 1000

  events = request('event/list', CollegiateLink::Event, params)
end

#organizations(params = {}) ⇒ Object

Return a complete list of CollegiateLink::Organization instances for your institution.

Required Parameters:

None

Optional Parameters:

See CollegiateLink::Request#initialize for a list of optional parameters



42
43
44
# File 'lib/collegiatelink/client.rb', line 42

def organizations(params = {})
  orgs = request('organization/list', CollegiateLink::Organization, params)
end

#roster(id, params = {}) ⇒ Object



70
71
72
73
74
# File 'lib/collegiatelink/client.rb', line 70

def roster(id, params = {})
  params.merge!(:id => id)

  members = request('organization/roster', CollegiateLink::Member, params)
end

#use_socks_proxy(host, port) ⇒ Object



28
29
30
# File 'lib/collegiatelink/client.rb', line 28

def use_socks_proxy(host, port)
  @@proxy = Net::HTTP.SOCKSProxy(host, port)
end