CollegiateLink 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/collegiatelink.rb +1 -4
- data/lib/collegiatelink/client.rb +24 -10
- data/lib/collegiatelink/organization.rb +57 -3
- data/lib/collegiatelink/request.rb +8 -5
- data/lib/collegiatelink/response.rb +1 -1
- metadata +20 -5
data/lib/collegiatelink.rb
CHANGED
@@ -4,6 +4,7 @@ require 'net/ssh'
|
|
4
4
|
require 'guid'
|
5
5
|
require 'nokogiri'
|
6
6
|
require 'happymapper'
|
7
|
+
require 'socksify/http'
|
7
8
|
|
8
9
|
require 'collegiatelink/response'
|
9
10
|
require 'collegiatelink/request'
|
@@ -15,10 +16,6 @@ require 'collegiatelink/organization'
|
|
15
16
|
# development, so let me know if you plan to use it. (tomdooner@gmail.com)
|
16
17
|
#
|
17
18
|
module CollegiateLink
|
18
|
-
# URL base for all requests. The API key will be substituted into this when
|
19
|
-
# the request is made.
|
20
|
-
URL_BASE = 'https://%s.collegiatelink.net/ws/'
|
21
|
-
|
22
19
|
# Currently-supported CollegiateLink action request types
|
23
20
|
ACTIONS = [
|
24
21
|
'organization/list',
|
@@ -13,11 +13,20 @@ module CollegiateLink
|
|
13
13
|
def initialize(apikey, ip, sharedkey)
|
14
14
|
@params = {
|
15
15
|
apikey: apikey,
|
16
|
-
ip: ip
|
16
|
+
ip: ip,
|
17
17
|
}
|
18
18
|
@opts = {
|
19
|
-
sharedkey: sharedkey
|
19
|
+
sharedkey: sharedkey,
|
20
20
|
}
|
21
|
+
@@proxy = Net::HTTP
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.proxy
|
25
|
+
@@proxy
|
26
|
+
end
|
27
|
+
|
28
|
+
def use_socks_proxy(host, port)
|
29
|
+
@@proxy = Net::HTTP.SOCKSProxy(host, port)
|
21
30
|
end
|
22
31
|
|
23
32
|
##
|
@@ -31,8 +40,7 @@ module CollegiateLink
|
|
31
40
|
# See CollegiateLink::Request#initialize for a list of optional parameters
|
32
41
|
#
|
33
42
|
def organizations(params = {})
|
34
|
-
orgs = request('organization/list', params)
|
35
|
-
orgs.map{ |o| CollegiateLink::Organization.parse(o.to_s) }
|
43
|
+
orgs = request('organization/list', CollegiateLink::Organization, params)
|
36
44
|
end
|
37
45
|
|
38
46
|
##
|
@@ -56,21 +64,27 @@ module CollegiateLink
|
|
56
64
|
params[:startdate] = params[:startdate].to_i * 1000
|
57
65
|
params[:enddate] = params[:enddate].to_i * 1000
|
58
66
|
|
59
|
-
events = request('event/list', params)
|
60
|
-
|
67
|
+
events = request('event/list', CollegiateLink::Event, params)
|
68
|
+
end
|
69
|
+
|
70
|
+
def roster(id, params = {})
|
71
|
+
params.merge!(:id => id)
|
72
|
+
|
73
|
+
members = request('organization/roster', CollegiateLink::Member, params)
|
61
74
|
end
|
62
75
|
|
63
76
|
private
|
64
77
|
|
65
|
-
def request(action, params = {})
|
78
|
+
def request(action, model, params = {})
|
66
79
|
cl_request = CollegiateLink::Request.new(action, params.merge(@params), @opts)
|
67
80
|
cl_resp = cl_request.perform
|
68
81
|
|
69
|
-
all_items = cl_resp.items
|
82
|
+
all_items = cl_resp.items.map { |i| model.parse(i.to_s) }
|
70
83
|
|
71
84
|
while cl_resp.has_next_page?
|
72
|
-
|
73
|
-
|
85
|
+
cl_request = cl_request.request_for_next_page
|
86
|
+
cl_resp = cl_request.perform
|
87
|
+
all_items += cl_resp.items.map { |i| model.parse(i.to_s) }
|
74
88
|
end
|
75
89
|
|
76
90
|
all_items
|
@@ -45,10 +45,15 @@ module CollegiateLink
|
|
45
45
|
#
|
46
46
|
# ==== Properties:
|
47
47
|
# * <tt>:id </tt> - Integer
|
48
|
-
# * <tt>:
|
48
|
+
# * <tt>:parentId</tt> - Integer
|
49
49
|
# * <tt>:name </tt> - String
|
50
|
-
# * <tt>:
|
51
|
-
# * <tt>:
|
50
|
+
# * <tt>:description </tt> - String
|
51
|
+
# * <tt>:shortName </tt> - String
|
52
|
+
# * <tt>:siteUrl </tt> - String
|
53
|
+
# * <tt>:status </tt> - String
|
54
|
+
# * <tt>:type </tt> - String
|
55
|
+
# * <tt>:addresses </tt> - Array of CollegiateLink::Address
|
56
|
+
# * <tt>:categories </tt> - Array of CollegiateLink::Category
|
52
57
|
class Organization
|
53
58
|
include HappyMapper
|
54
59
|
|
@@ -95,4 +100,53 @@ module CollegiateLink
|
|
95
100
|
|
96
101
|
has_one :organization, Organization
|
97
102
|
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# A position of someone in an organization
|
106
|
+
#
|
107
|
+
class Position
|
108
|
+
include HappyMapper
|
109
|
+
|
110
|
+
element :name, String
|
111
|
+
element :enddate, Integer
|
112
|
+
element :startdate, Integer
|
113
|
+
element :userstartdate, Integer
|
114
|
+
element :userenddate, Integer
|
115
|
+
|
116
|
+
def current?
|
117
|
+
use_startdate = (userstartdate > 0) ? userstartdate : startdate
|
118
|
+
indefinite = (userenddate < 0) && (enddate < 0)
|
119
|
+
|
120
|
+
starts = Time.at(use_startdate / 1000, use_startdate % 1000)
|
121
|
+
|
122
|
+
if indefinite
|
123
|
+
return (starts < Time.now)
|
124
|
+
else
|
125
|
+
use_enddate = (userenddate > 0) ? userenddate : enddate
|
126
|
+
ends = Time.at(use_enddate / 1000, use_enddate % 1000)
|
127
|
+
return (starts < Time.now && Time.now < ends)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# A Member record returned by CollegiateLink
|
134
|
+
#
|
135
|
+
class Member
|
136
|
+
include HappyMapper
|
137
|
+
|
138
|
+
#element :affiliation # Not sure the format of this...
|
139
|
+
element :campusemail, String
|
140
|
+
element :firstname, String
|
141
|
+
element :id, Integer
|
142
|
+
element :lastname, String
|
143
|
+
element :preferredemail, String
|
144
|
+
element :username, String
|
145
|
+
|
146
|
+
has_many :positions, Position
|
147
|
+
|
148
|
+
def active_positions
|
149
|
+
positions.keep_if { |p| p.current? }
|
150
|
+
end
|
151
|
+
end
|
98
152
|
end
|
@@ -33,6 +33,9 @@ module CollegiateLink
|
|
33
33
|
@params[:page] ||= 1
|
34
34
|
@params[:pagesize] ||= 100
|
35
35
|
@params[:modelformatting] ||= 'normal'
|
36
|
+
|
37
|
+
# Default values for optional parameters
|
38
|
+
@opts[:url_base] ||= 'https://%s.collegiatelink.net/ws/' % @params[:apikey]
|
36
39
|
end
|
37
40
|
|
38
41
|
##
|
@@ -48,16 +51,16 @@ module CollegiateLink
|
|
48
51
|
|
49
52
|
# Then, compute the URL...
|
50
53
|
url = URI([
|
51
|
-
|
52
|
-
@action
|
53
|
-
'?'
|
54
|
-
URI.encode_www_form(request_params)
|
54
|
+
@opts[:url_base],
|
55
|
+
@action,
|
56
|
+
'?',
|
57
|
+
URI.encode_www_form(request_params),
|
55
58
|
].join)
|
56
59
|
|
57
60
|
puts "requesting: \n#{url}" if @opts[:debug]
|
58
61
|
|
59
62
|
# Make the Request!
|
60
|
-
res =
|
63
|
+
res = CollegiateLink::Client.proxy.new(url.host, url.port)
|
61
64
|
res.use_ssl = true
|
62
65
|
res.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
63
66
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: CollegiateLink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guid
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: socksify
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: rspec
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,7 +99,7 @@ dependencies:
|
|
83
99
|
- - ! '>='
|
84
100
|
- !ruby/object:Gem::Version
|
85
101
|
version: '0'
|
86
|
-
type: :
|
102
|
+
type: :runtime
|
87
103
|
prerelease: false
|
88
104
|
version_requirements: !ruby/object:Gem::Requirement
|
89
105
|
none: false
|
@@ -125,6 +141,5 @@ rubyforge_project:
|
|
125
141
|
rubygems_version: 1.8.24
|
126
142
|
signing_key:
|
127
143
|
specification_version: 3
|
128
|
-
summary:
|
144
|
+
summary: Old, deprecated gem. Use the lowercased gem "collegiatelink" instead!
|
129
145
|
test_files: []
|
130
|
-
has_rdoc:
|