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(options = {}) ⇒ Client

Creates a CollegiateLink client.

Parameters:

  • options - A hash containing the following values:

    • apikey - The CollegiateLink “apikey”

    • ip - (Optional) The IP address that the apikey is approved for, if and only if that is how the apikey is configured on CollegiateLink’s side.

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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/collegiatelink/client.rb', line 17

def initialize(options = {})
  @params = {
    apikey: options[:apikey],
  }
  @params.merge(ip: options[:ip]) if options[:ip]

  @opts = {
    privatekey: options[:privatekey],
  }
  @@proxy = Net::HTTP
end

Class Method Details

.proxyObject



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

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.



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/collegiatelink/client.rb', line 71

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

  request('events', CollegiateLink::Event, params)
end

#financetransactions(params = {}) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/collegiatelink/client.rb', line 51

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

  request('financetransactions', CollegiateLink::FinanceTransaction, 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



47
48
49
# File 'lib/collegiatelink/client.rb', line 47

def organizations(params = {})
  request('organizations', CollegiateLink::Organization, params)
end

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



84
85
86
87
88
# File 'lib/collegiatelink/client.rb', line 84

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

  request('memberships', CollegiateLink::Member, params)
end

#use_socks_proxy(host, port) ⇒ Object



33
34
35
# File 'lib/collegiatelink/client.rb', line 33

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