openapply 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +165 -387
- data/examples/demo/README.md +74 -18
- data/examples/demo/demo_site.rb +40 -74
- data/lib/openapply/convert.rb +371 -0
- data/lib/openapply/get_student.rb +125 -223
- data/lib/openapply/get_students.rb +143 -340
- data/lib/openapply/version.rb +1 -1
- data/lib/openapply.rb +12 -8
- data/openapply.gemspec +5 -0
- metadata +59 -3
- data/examples/demo/.rbenv-vars +0 -5
@@ -1,231 +1,129 @@
|
|
1
1
|
module Get
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
#
|
6
|
-
# ==== Attributes
|
7
|
-
# * +status+ - match status (be sure it is in the list of OpenApply status)
|
8
|
-
# * +since_id+ - get all ids matching the criteria LARGER than the given number
|
9
|
-
# * +since_date+ - get all records updated after the given date (YYYY-MM-DD) or
|
10
|
-
# Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
11
|
-
# * +count+ - return a custom number of records (no more than 1000)
|
12
|
-
#
|
13
|
-
# ==== Example code
|
14
|
-
# @demo = Openapply.new
|
15
|
-
# # return: any status (nil), any id greater than 95 updated since 2017-01-01 &
|
16
|
-
# # return only 2 records at a time
|
17
|
-
# @demo.custom_students_query(nil, since_id=95, since_date=2017-01-01, count=2)
|
18
|
-
#
|
19
|
-
# ==== Return Format
|
20
|
-
# { :students=>
|
21
|
-
# [{:id=>96,
|
22
|
-
# :serial_number=>86,
|
23
|
-
# :custom_id=>"86",
|
24
|
-
# :applicant_id=>"00000086",
|
25
|
-
# :email=>"Jerry.Patel@eduvo.com",
|
26
|
-
# :first_name=>"Jerry",
|
27
|
-
# :last_name=>"Patel",
|
28
|
-
# ...,
|
29
|
-
# :sibling_ids=>[],
|
30
|
-
# :updated_at=>"2017-07-11T14:46:44.000+08:00",
|
31
|
-
# :...,
|
32
|
-
# :parent_ids=>[267, 268]},
|
33
|
-
# {:id=>98,
|
34
|
-
# :serial_number=>87,
|
35
|
-
# :custom_id=>"87",
|
36
|
-
# :applicant_id=>"00000087",
|
37
|
-
# :email=>"Robin.Barnes@eduvo.com",
|
38
|
-
# :first_name=>"Robin",
|
39
|
-
# :last_name=>"Barnes",
|
40
|
-
# :sibling_ids=>[],
|
41
|
-
# :updated_at=>"2017-07-11T14:46:44.000+08:00",
|
42
|
-
# ...,
|
43
|
-
# :profile_photo=>
|
44
|
-
# "https://openapply-sandbox-devel-01.s3.amazonaws.com/uploads/student/avatar/000/000/098/f_rep.jpg?v=1499755604",
|
45
|
-
# :profile_photo_updated_at=>"2017-07-11T14:46:44.000+08:00",
|
46
|
-
# :parent_ids=>[406, 407]}],
|
47
|
-
# :linked=>
|
48
|
-
# {:parents=>
|
49
|
-
# [{:id=>267,
|
50
|
-
# :serial_number=>256,
|
51
|
-
# :custom_id=>"256",
|
52
|
-
# :name=>"Jane Patel",
|
53
|
-
# :first_name=>"Jane",
|
54
|
-
# :last_name=>"Patel",
|
55
|
-
# ...,
|
56
|
-
# :profile_photo=>
|
57
|
-
# "https://openapply-sandbox-devel-01.s3.amazonaws.com/uploads/parent/avatar/000/000/267/patel_mom.jpg?v=1499755607",
|
58
|
-
# :profile_photo_updated_at=>"2017-07-11T14:46:47.000+08:00",
|
59
|
-
# :parent_id=>"256",
|
60
|
-
# :custom_fields=>
|
61
|
-
# {:title=>"",
|
62
|
-
# :treat_parent_as_emergency_contact=>"Yes",
|
63
|
-
# :home_telephone=>"",
|
64
|
-
# ...,
|
65
|
-
# :parent_residency=>"Citizen"}},
|
66
|
-
# { ... },
|
67
|
-
# {:id=>407,
|
68
|
-
# :serial_number=>nil,
|
69
|
-
# :custom_id=>nil,
|
70
|
-
# :name=>"Boris Barnes",
|
71
|
-
# :first_name=>"Boris",
|
72
|
-
# :last_name=>"Barnes",
|
73
|
-
# ...,
|
74
|
-
# :profile_photo=>
|
75
|
-
# "https://openapply-sandbox-devel-01.s3.amazonaws.com/uploads/parent/avatar/000/000/407/6e9b4e89-0aa8-413c-8239-2990ea6b0e6d.jpg?v=1499755608",
|
76
|
-
# :profile_photo_updated_at=>"2017-07-11T14:46:48.000+08:00",
|
77
|
-
# :parent_id=>nil,
|
78
|
-
# :custom_fields=>
|
79
|
-
# {:title=>nil,
|
80
|
-
# :treat_parent_as_emergency_contact=>"Yes",
|
81
|
-
# :mobile_phone=>"852 6565 1190",
|
82
|
-
# :home_telephone=>"852 4545 1190",
|
83
|
-
# ...,
|
84
|
-
# :parent_residency=>nil}}]},
|
85
|
-
# :meta=>{:pages=>170, :per_page=>"2"}}
|
86
|
-
def students_custom_query(status=nil, since_id=nil, since_date=nil, count=api_records)
|
87
|
-
return { error: "invalid count" } unless count.to_i >= 1
|
3
|
+
# MULTIPLE STUDENTS DETAILS (full records) - found by status (or statuses)
|
4
|
+
###########################
|
88
5
|
|
89
|
-
|
90
|
-
answer = oa_answer( url )
|
91
|
-
return { error: "nil answer" } if answer.nil?
|
92
|
-
return { error: "nil students" } if answer[:students].nil?
|
93
|
-
return { student_ids: [] } if answer[:students].empty?
|
94
|
-
return answer
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
# Builds a custom url (with domain) to get a list of students summaries matching
|
99
|
-
# the attribute's criteria (but not do a Query) - returns a URL
|
6
|
+
# Returns all student details (combines student, guardian and payments records)
|
100
7
|
#
|
101
|
-
#
|
102
|
-
# * +status+ - match status (be sure it is in the list of OpenApply status)
|
103
|
-
# * +since_id+ - get all ids matching the criteria LARGER than the given number
|
104
|
-
# * +since_date+ - get all records updated after the given date (YYYY-MM-DD) or
|
105
|
-
# Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
106
|
-
# * +count+ - return a custom number of records (no more than 1000)
|
8
|
+
# === Attributes
|
107
9
|
#
|
108
|
-
#
|
109
|
-
#
|
110
|
-
#
|
10
|
+
# **flatten_keys** - brings these keys to the top level - prepending the group name to the key name -- we usually use:
|
11
|
+
# flatten_keys = [:custom_fields]
|
12
|
+
# **reject keys** -- removes the data matching these keys -- we usually use:
|
13
|
+
# reject_keys = [:parent_guardian] (since this is duplicated)
|
111
14
|
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
15
|
+
# === Usage
|
16
|
+
# students_details_by_status('applied')
|
17
|
+
# students_details_by_status('applied', [:custom_fields], [:parent_guardian])
|
18
|
+
# students_details_by_statuses(['applied','enrolled'])
|
19
|
+
# students_details_by_statuses(['applied','enrolled'], [:custom_fields], [:parent_guardian])
|
20
|
+
#
|
21
|
+
# === Returned Data
|
22
|
+
# returns the data structured as:
|
23
|
+
# { students:
|
24
|
+
# [
|
25
|
+
# { id: xxx, # openapply student id
|
26
|
+
# record: {xxx} # complete student record
|
27
|
+
# guardians: [ {xxx}, {xxx} ] # all guardian information
|
28
|
+
# payments: [ {xxx}, {xxx} ] # all payments made via openapply
|
29
|
+
# },
|
30
|
+
# {
|
31
|
+
# id: xxx, # openapply student id
|
32
|
+
# record: {xxx} # complete student record
|
33
|
+
# guardians: [ {xxx}, {xxx} ] # all guardian information
|
34
|
+
# payments: [ {xxx}, {xxx} ] # all payments made via openapply
|
35
|
+
# }
|
36
|
+
# ]
|
37
|
+
# }
|
38
|
+
def students_details_by_status( status, flatten_keys=[], reject_keys=[] )
|
39
|
+
|
40
|
+
check = check_details_keys_validity(flatten_keys, reject_keys)
|
41
|
+
return check unless check.nil? # or check[:error].nil?
|
42
|
+
|
43
|
+
ids = student_ids_by_status(status)
|
44
|
+
return { error: 'answer nil' } if ids.nil?
|
45
|
+
return { error: 'ids nil' } if ids[:student_ids].nil?
|
46
|
+
return { students: [] } if ids[:student_ids].empty?
|
121
47
|
|
122
|
-
|
48
|
+
# loop through each student
|
49
|
+
error_ids = []
|
50
|
+
student_records = []
|
51
|
+
ids[:student_ids].each do |id|
|
52
|
+
student = student_details_by_id( "#{id}", flatten_keys, reject_keys )
|
53
|
+
|
54
|
+
error_ids << id if student.nil? or
|
55
|
+
student[:student].nil? or
|
56
|
+
student[:student].empty?
|
57
|
+
student_records << student[:student] unless student.nil? or
|
58
|
+
student[:student].nil? or
|
59
|
+
student[:student].empty?
|
60
|
+
end
|
61
|
+
return { students: student_records }
|
123
62
|
end
|
63
|
+
alias_method :students_details, :students_details_by_status
|
64
|
+
alias_method :students_details_by_statuses, :students_details_by_status
|
65
|
+
|
66
|
+
# UTILITIES FOR MULTIPLE STUDENT LOOKUPS -- using recursion
|
67
|
+
########################################
|
124
68
|
|
69
|
+
# LIST OF IDS for a given STATUS
|
70
|
+
################################
|
125
71
|
|
126
72
|
# returns a list of student ids that match a give status (this is recursive -
|
127
73
|
# so returns the entire list - even if that list is longer than the api_return_count)
|
128
74
|
#
|
129
75
|
# ==== Attributes
|
130
|
-
#
|
76
|
+
# +status+ - a **string** matching one of the OA allowed statuses **OR**
|
77
|
+
# status can be an **array** of statuses (matching OA statuses)
|
131
78
|
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
79
|
+
# === Usage
|
80
|
+
# student_ids_by_status('applied')
|
81
|
+
# student_ids_by_statuses(['applied','enrolled'])
|
135
82
|
#
|
136
|
-
#
|
137
|
-
#
|
83
|
+
# === Return
|
84
|
+
# {student_ids: [1, 3, 40]}
|
85
|
+
# TODO: test with a mix of good and bad keys
|
86
|
+
# only use good keys be sure count >= 1
|
138
87
|
def student_ids_by_status(status)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
88
|
+
ids = []
|
89
|
+
# when a single status is sent
|
90
|
+
states = [status] if status.is_a? String
|
91
|
+
states = status if status.is_a? Array
|
92
|
+
states.each do |state|
|
93
|
+
answer = students_by_status(state)
|
94
|
+
|
95
|
+
ids += answer[:students].map{ |l| l[:id] } unless answer.nil? or
|
96
|
+
answer[:students].nil? or
|
97
|
+
answer[:students].empty?
|
98
|
+
end
|
99
|
+
return { student_ids: [] } if ids.nil? or ids.empty?
|
145
100
|
return { student_ids: ids }
|
146
101
|
end
|
147
102
|
alias_method :all_student_ids_by_status, :student_ids_by_status
|
103
|
+
alias_method :student_ids_by_statuses, :student_ids_by_status
|
148
104
|
|
105
|
+
# GET STUDENT SUMMARY INFO for a given status -- mostly used to get a list of ids
|
106
|
+
##########################
|
149
107
|
|
150
|
-
#
|
108
|
+
# Returns a list of student summaries (in OpenApply's format) that
|
151
109
|
# match a give status (this is recursive - so returns the entire list -
|
152
110
|
# even if that list is longer than the api_return_count)
|
153
111
|
#
|
154
112
|
# ==== Attributes
|
155
|
-
#
|
113
|
+
# +status+ - **MUST BE A STRING** returns the data as is from OpenApply
|
156
114
|
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
# [{:id=>95,
|
160
|
-
# :serial_number=>85,
|
161
|
-
# :custom_id=>"85",
|
162
|
-
# :applicant_id=>"00000085",
|
163
|
-
# :email=>"Richard.Washington@eduvo.com",
|
164
|
-
# :first_name=>"Richard",
|
165
|
-
# :last_name=>"Washington",
|
166
|
-
# :name=>"Richard Washington",
|
167
|
-
# ...,
|
168
|
-
# :parent_ids=>[492, 493]},
|
169
|
-
# {:id=>106,
|
170
|
-
# :serial_number=>90,
|
171
|
-
# :custom_id=>"90",
|
172
|
-
# :applicant_id=>"00000090",
|
173
|
-
# :email=>"Henry.Epelbaum@eduvo.com",
|
174
|
-
# :first_name=>"Samuel",
|
175
|
-
# :last_name=>"Epelbaum",
|
176
|
-
# ...,
|
177
|
-
# :parent_ids=>[265, 266]}],
|
178
|
-
# :linked=>
|
179
|
-
# {:parents=>
|
180
|
-
# [{:id=>492,
|
181
|
-
# :serial_number=>nil,
|
182
|
-
# :custom_id=>nil,
|
183
|
-
# :name=>"Philippa Washington",
|
184
|
-
# :first_name=>"Philippa",
|
185
|
-
# :last_name=>"Washington",
|
186
|
-
# ...,
|
187
|
-
# :custom_fields=>
|
188
|
-
# {:title=>nil,
|
189
|
-
# :treat_parent_as_emergency_contact=>nil,
|
190
|
-
# :mobile_phone=>"852 6712 1196",
|
191
|
-
# :home_telephone=>"+852 9954 1179",
|
192
|
-
# ...,
|
193
|
-
# :parent_residency=>nil}},
|
194
|
-
# {:id=>493,
|
195
|
-
# :serial_number=>nil,
|
196
|
-
# :custom_id=>nil,
|
197
|
-
# :name=>"Fred Washington",
|
198
|
-
# :first_name=>"Fred",
|
199
|
-
# :last_name=>"Washington",
|
200
|
-
# ...,
|
201
|
-
# :address=>"High Street 110",
|
202
|
-
# :address_ii=>nil,
|
203
|
-
# :city=>"Hong Kong",
|
204
|
-
# :state=>nil,
|
205
|
-
# :postal_code=>nil,
|
206
|
-
# :country=>"Hong Kong",
|
207
|
-
# :email=>"fredw@eduvo.com",
|
208
|
-
# :parent_role=>"Father",
|
209
|
-
# :updated_at=>"2017-07-11T14:46:48.000+08:00",
|
210
|
-
# ...,
|
211
|
-
# :custom_fields=>
|
212
|
-
# {:title=>nil,
|
213
|
-
# :treat_parent_as_emergency_contact=>nil,
|
214
|
-
# :mobile_phone=>"+852 9954 1179",
|
215
|
-
# :home_telephone=>"+852 9954 1179",
|
216
|
-
# ...,
|
217
|
-
# :parent_residency=>nil}}]},
|
218
|
-
# :meta=>{:pages=>1, :per_page=>"100"}}
|
115
|
+
# === Usage
|
116
|
+
# students_by_status('applied')
|
219
117
|
def students_by_status(status)
|
220
118
|
url = students_custom_url(status)
|
221
119
|
answer = oa_answer( url )
|
222
|
-
return { error: "
|
223
|
-
return { students: [] }
|
120
|
+
return { error: "nil" } if answer[:students].nil?
|
121
|
+
return { students: [] } if answer[:students].empty?
|
224
122
|
|
225
123
|
page_number = answer[:meta][:pages]
|
226
|
-
return answer
|
124
|
+
return answer if page_number == 1
|
227
125
|
|
228
|
-
# inspect meta data -- loop until page = 1
|
126
|
+
# inspect meta data -- loop until page = 1 (all students found)
|
229
127
|
all_students = answer[:students]
|
230
128
|
while page_number > 1
|
231
129
|
last_student = answer[:students].last
|
@@ -241,159 +139,64 @@ module Get
|
|
241
139
|
alias_method :students, :students_by_status
|
242
140
|
|
243
141
|
|
244
|
-
#
|
245
|
-
|
246
|
-
|
142
|
+
# CUSTOM QUERIES - recursion utlities
|
143
|
+
################
|
144
|
+
|
145
|
+
# Executes a custom query **(non-recursive)** to get a list of students
|
146
|
+
# summaries matching the allowed attribute's criteria -- used to build
|
147
|
+
# recursive or custom queries (within what is allowed by OpenApply API)
|
247
148
|
#
|
248
149
|
# ==== Attributes
|
249
150
|
# * +status+ - match status (be sure it is in the list of OpenApply status)
|
151
|
+
# * +since_id+ - get all ids matching the criteria LARGER than the given number
|
152
|
+
# * +since_date+ - get all records updated after the given date (YYYY-MM-DD) or
|
153
|
+
# Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
154
|
+
# * +count+ - return a custom number of records (no more than 1000)
|
250
155
|
#
|
251
|
-
# ====
|
252
|
-
#
|
253
|
-
#
|
254
|
-
#
|
255
|
-
#
|
256
|
-
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
|
262
|
-
|
263
|
-
# payments: []
|
264
|
-
# }
|
265
|
-
# ]}
|
266
|
-
# for example:
|
267
|
-
# :students=>
|
268
|
-
# [{:id=>"95",
|
269
|
-
# :record=>
|
270
|
-
# {:id=>95,
|
271
|
-
# :serial_number=>85,
|
272
|
-
# ...,
|
273
|
-
# :custom_fields=>
|
274
|
-
# {:language=>"English",
|
275
|
-
# :nationality=>"American (United States)",
|
276
|
-
# :referral_source=>"Friends",
|
277
|
-
# ...,
|
278
|
-
# :siblings_information=>
|
279
|
-
# [{:first_name=>"Jerry",
|
280
|
-
# :last_name=>"Washington",
|
281
|
-
# :gender=>"Male",
|
282
|
-
# :birth_date=>"2008-06-04"}],
|
283
|
-
# :emergency_contact=>[],
|
284
|
-
# :immunization_record=>[],
|
285
|
-
# :health_information=>[]},
|
286
|
-
# :parent_ids=>[492, 493]},
|
287
|
-
# :payments=>[],
|
288
|
-
# :guardians=>
|
289
|
-
# [{:id=>492,
|
290
|
-
# :serial_number=>nil,
|
291
|
-
# :custom_id=>nil,
|
292
|
-
# :name=>"Philippa Washington",
|
293
|
-
# :first_name=>"Philippa",
|
294
|
-
# :last_name=>"Washington",
|
295
|
-
# ...,
|
296
|
-
# :custom_fields=>
|
297
|
-
# {:title=>nil,
|
298
|
-
# :treat_parent_as_emergency_contact=>nil,
|
299
|
-
# :mobile_phone=>"852 6712 1196",
|
300
|
-
# :home_telephone=>"+852 9954 1179",
|
301
|
-
# ...,
|
302
|
-
# :parent_residency=>nil}},
|
303
|
-
# {:id=>493,
|
304
|
-
# :serial_number=>nil,
|
305
|
-
# :custom_id=>nil,
|
306
|
-
# :name=>"Fred Washington",
|
307
|
-
# :first_name=>"Fred",
|
308
|
-
# :last_name=>"Washington",
|
309
|
-
# ...,
|
310
|
-
# :custom_fields=>
|
311
|
-
# {:title=>nil,
|
312
|
-
# :treat_parent_as_emergency_contact=>nil,
|
313
|
-
# :mobile_phone=>"+852 9954 1179",
|
314
|
-
# :home_telephone=>"+852 9954 1179",
|
315
|
-
# ...,
|
316
|
-
# :parent_residency=>nil}}]},
|
317
|
-
# { ... },
|
318
|
-
# {:id=>"582",
|
319
|
-
# :record=>
|
320
|
-
# {:id=>582,
|
321
|
-
# :serial_number=>437,
|
322
|
-
# :custom_id=>nil,
|
323
|
-
# :applicant_id=>"00000437",
|
324
|
-
# :email=>"s3@example.com",
|
325
|
-
# :first_name=>"Ada",
|
326
|
-
# :last_name=>"Junior",
|
327
|
-
# ...,
|
328
|
-
# :profile_photo=>
|
329
|
-
# "https://openapply-sandbox-devel-01.s3.amazonaws.com/uploads/student/avatar/000/000/582/boy-01.jpg?v=1500883583",
|
330
|
-
# :profile_photo_updated_at=>"2017-07-24T16:06:23.000+08:00",
|
331
|
-
# :custom_fields=>
|
332
|
-
# {:language=>nil,
|
333
|
-
# :nationality=>nil,
|
334
|
-
# :referral_source=>nil,
|
335
|
-
# ...,
|
336
|
-
# :prior_school_list=>[],
|
337
|
-
# :immunization_record=>[],
|
338
|
-
# :health_information=>[]},
|
339
|
-
# :parent_ids=>[]},
|
340
|
-
# :payments=>[],
|
341
|
-
# :guardians=>[]}]}
|
342
|
-
def students_details_by_status(status)
|
343
|
-
ids = all_student_ids_by_status(status)
|
344
|
-
return { error: 'answer nil' } if ids.nil?
|
345
|
-
return { error: 'ids nil' } if ids[:student_ids].nil?
|
346
|
-
return { error: 'ids empty' } if ids[:student_ids].empty?
|
347
|
-
|
348
|
-
# loop through each student
|
349
|
-
error_ids = []
|
350
|
-
student_records = []
|
351
|
-
ids[:student_ids].each do |id|
|
352
|
-
# get each kids details w_billing
|
353
|
-
student = student_details_by_id( "#{id}" )
|
354
|
-
|
355
|
-
error_ids << id if student.nil? or
|
356
|
-
student[:student].nil? or
|
357
|
-
student[:student].empty?
|
358
|
-
student_records << student[:student] unless student.nil? or
|
359
|
-
student[:student].nil? or
|
360
|
-
student[:student].empty?
|
361
|
-
end
|
362
|
-
|
363
|
-
return { students: [], error_ids: error_ids } if student_records.empty?
|
364
|
-
return { students: student_records }
|
365
|
-
end
|
366
|
-
# alias_method :all_student_records_w_billing_by_status, :students_details_by_status
|
367
|
-
# alias_method :all_students_all_data_by_status, :students_details_by_status
|
368
|
-
alias_method :students_details, :students_details_by_status
|
156
|
+
# ==== Usage
|
157
|
+
# students_query(nil, since_id=95, since_date=2017-01-01, count=2)
|
158
|
+
#
|
159
|
+
# ==== returned
|
160
|
+
# { students:
|
161
|
+
# [
|
162
|
+
# { student summary data from openapply api },
|
163
|
+
# { student summary data from openapply api },
|
164
|
+
# ]
|
165
|
+
# }
|
166
|
+
def students_query(status=nil, since_id=nil, since_date=nil, count=api_records)
|
167
|
+
return { error: "invalid count" } unless count.to_i >= 1
|
369
168
|
|
370
|
-
|
371
|
-
|
169
|
+
url = students_custom_url(status, since_id, since_date, count)
|
170
|
+
answer = oa_answer( url )
|
171
|
+
return { error: "nil answer" } if answer.nil?
|
172
|
+
return { error: "nil students" } if answer[:students].nil?
|
173
|
+
return { students: [] } if answer[:students].empty?
|
174
|
+
return answer
|
372
175
|
end
|
176
|
+
alias_method :students_custom_query, :students_query
|
373
177
|
|
374
|
-
#
|
375
|
-
#
|
376
|
-
# def students_by_since_id(since_id, status = nil, date = nil)
|
377
|
-
# url = "#{@api_path}?count=#{api_records}&auth_token=#{@api_key}"
|
378
|
-
# elsif date.nil? or date == ""
|
379
|
-
# url = "#{@api_path}?status=#{status}&count=#{api_records}&auth_token=#{@api_key}"
|
380
|
-
# else
|
381
|
-
# url = "#{@api_path}?status=#{status}&since_date=#{date}&count=#{api_records}&auth_token=#{@api_key}"
|
382
|
-
# end
|
383
|
-
# return oa_answer( url, options )
|
384
|
-
# end
|
178
|
+
# Builds a custom url (with domain) to get a list of students summaries matching
|
179
|
+
# the attribute's criteria (but not do a Query) - returns a URL
|
385
180
|
#
|
181
|
+
# ==== Attributes
|
182
|
+
# * +status+ - match status (be sure it is in the list of OpenApply status)
|
183
|
+
# * +since_id+ - get all ids matching the criteria LARGER than the given number
|
184
|
+
# * +since_date+ - get all records updated after the given date (YYYY-MM-DD) or
|
185
|
+
# Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
186
|
+
# * +count+ - return a custom number of records (no more than 1000)
|
386
187
|
#
|
387
|
-
#
|
388
|
-
#
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
188
|
+
# ==== Return Format
|
189
|
+
# "/api/v1/students/?status=applied&since_id=96&since_date=2017-01-25&count=2&auth_token=319d9axxxxxxx"
|
190
|
+
def students_query_url(status=nil, since_id=nil, since_date=nil, count=api_records)
|
191
|
+
url_options = []
|
192
|
+
url_options << "status=#{status}" unless status.to_s.eql? ""
|
193
|
+
url_options << "since_id=#{since_id}" unless since_id.to_s.eql? ""
|
194
|
+
url_options << "since_date=#{since_date}" unless since_date.to_s.eql? ""
|
195
|
+
url_options << "count=#{count}"
|
196
|
+
url_options << "auth_token=#{api_key}"
|
197
|
+
|
198
|
+
return "#{api_path}?#{url_options.join('&')}"
|
199
|
+
end
|
200
|
+
alias_method :students_custom_url, :students_query_url
|
398
201
|
|
399
202
|
end
|
data/lib/openapply/version.rb
CHANGED
data/lib/openapply.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "openapply/get_students"
|
2
2
|
require "openapply/get_student"
|
3
|
+
require "openapply/convert"
|
3
4
|
require "openapply/version"
|
4
5
|
require "openapply/put"
|
5
6
|
require 'httparty'
|
@@ -11,11 +12,16 @@ module Openapply
|
|
11
12
|
#
|
12
13
|
class Client
|
13
14
|
|
14
|
-
#
|
15
|
-
include Get
|
16
|
-
# Contains the PUT api calls
|
15
|
+
# PUT api calls
|
17
16
|
include Put
|
18
|
-
|
17
|
+
|
18
|
+
# GET api calls
|
19
|
+
include Get
|
20
|
+
|
21
|
+
# Convert student data to various formats
|
22
|
+
include Convert
|
23
|
+
|
24
|
+
# Library for API calls to OpenApply
|
19
25
|
include HTTParty
|
20
26
|
|
21
27
|
# Defines OpenApply domain name from ENV-VARS
|
@@ -49,14 +55,12 @@ module Openapply
|
|
49
55
|
def api_path
|
50
56
|
ENV['OA_API_PATH'] || "/api/v1/students/"
|
51
57
|
end
|
52
|
-
# alias_method :base_path, :api_path
|
53
58
|
|
54
59
|
# Defines the maximum records OpenApply should return with each api call
|
55
|
-
# with ENV-VARS - (code default is
|
60
|
+
# with ENV-VARS - (code default is 50 - OA default is 10 - doc says 100)
|
56
61
|
def api_records
|
57
|
-
ENV['OA_REPLY_RECORDS'] || '
|
62
|
+
ENV['OA_REPLY_RECORDS'] || '50'
|
58
63
|
end
|
59
|
-
# alias_method :record_count, :api_max_records
|
60
64
|
|
61
65
|
# Handles httparty timeout errors - tries 3x before quitting
|
62
66
|
# https://stackoverflow.com/questions/26251422/handling-netreadtimeout-error-in-httparty
|
data/openapply.gemspec
CHANGED
@@ -32,11 +32,16 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_dependency "httparty", "~> 0.15"
|
34
34
|
spec.add_dependency "json" , "~> 2.1"
|
35
|
+
# need this version of axlsx to match roo's rubyzip needs
|
36
|
+
spec.add_dependency "axlsx" , "2.1.0.pre"
|
37
|
+
spec.add_dependency "net-ssh" , "~> 4.2"
|
38
|
+
spec.add_dependency "net-scp" , "~> 1.2"
|
35
39
|
|
36
40
|
spec.add_development_dependency "webmock" , "~> 3.1"
|
37
41
|
spec.add_development_dependency "bundler", "~> 1.15"
|
38
42
|
spec.add_development_dependency "rake", "~> 10.0"
|
39
43
|
spec.add_development_dependency "rspec", "~> 3.7"
|
44
|
+
spec.add_development_dependency "roo", "~> 2.7"
|
40
45
|
# spec.add_development_dependency "rspec", "~> 3.0"
|
41
46
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
42
47
|
# spec.add_development_dependency "rspec-nc", "~> 3.0"
|