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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b681f4a386b3ab614a6eb7c4f8b244119a687a275eb0457dc54ff0b49901204
|
4
|
+
data.tar.gz: b6f98f8ca674289a607606c5c79b6e1160e45c53cf88aa038cad2aeaff32c52a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656f153e570d7afaede6b73765637868ded3079eadac0763f17fbd1a052ec3f47c787adbefd20b634dbb8f2b8e87afebf8758bae467a9b50e02c3f850dbb4e50
|
7
|
+
data.tar.gz: b4c33173f2bd17b2ab0476231bbcc4ea2cd1a49ec362c24821c34c075cdb231f8620966a2f0f214b529d9a571e61006c116d51001115bfb74880c9865ca45742
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,18 +2,33 @@
|
|
2
2
|
|
3
3
|
This gem allows ruby access to the OpenApply API v1 - and supports the GET features described at: https://dev.faria.co/oa
|
4
4
|
|
5
|
+
|
5
6
|
### Still TODO
|
6
7
|
|
8
|
+
* xlsx export?
|
7
9
|
* test timeouts
|
8
10
|
* write PUTS methods
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
* write a recursive query to pull students by since id (
|
13
|
-
|
11
|
+
* write a recursive query to pull students by since date
|
12
|
+
* add protection for bad keys - when not an array or not symbol
|
13
|
+
* investigate slow response when returning large number of records
|
14
|
+
* write a recursive query to pull students by since id (sort of already done)
|
15
|
+
|
16
|
+
|
17
|
+
### CHANGE LOG
|
18
|
+
|
19
|
+
* **v0.1.0** - test release -- 2017-11-01
|
14
20
|
|
21
|
+
* **v0.2.0** - first release -- **NOT** compatible with 0.1.0 -- 2017-11-07
|
22
|
+
- get student details of a give status (and pure api calls)
|
23
|
+
- recursive query until all receipt of all records received
|
15
24
|
|
16
|
-
|
25
|
+
* **v0.2.1** - update compatible with 0.2.0 - 2017-11-20
|
26
|
+
- convert api data into an array, csv or xlsx
|
27
|
+
- allow data flattening prep for post processing
|
28
|
+
- allow queries to lookup students with multiple statuses
|
29
|
+
- allow scp string object to file export (no automated tests)
|
30
|
+
|
31
|
+
### Installation
|
17
32
|
|
18
33
|
Add this line to your application's Gemfile:
|
19
34
|
|
@@ -29,12 +44,17 @@ Or install it yourself as:
|
|
29
44
|
|
30
45
|
$ gem install openapply
|
31
46
|
|
32
|
-
## Usage
|
33
47
|
|
34
|
-
###
|
48
|
+
### Docs
|
35
49
|
|
36
50
|
* http://www.rubydoc.info/gems/openapply
|
37
51
|
|
52
|
+
|
53
|
+
#### Examples Code
|
54
|
+
|
55
|
+
see /examples in repo -- https://github.com/btihen/openapply/tree/master/examples/demo
|
56
|
+
|
57
|
+
|
38
58
|
### Configuration
|
39
59
|
|
40
60
|
* Setup / Config the following ENV-VARS (example code uses **.rbenv-vars**):
|
@@ -44,7 +64,8 @@ Or install it yourself as:
|
|
44
64
|
OA_TIMEOUT=5
|
45
65
|
|
46
66
|
# 100 records is the advertised default record count, but in reality it is 10
|
47
|
-
|
67
|
+
# this gem uses 50 as the default
|
68
|
+
OA_RELPY_RECORDS=50
|
48
69
|
|
49
70
|
# currently this is the only API path available
|
50
71
|
OA_API_PATH=/api/v1/students/
|
@@ -53,6 +74,8 @@ OA_API_PATH=/api/v1/students/
|
|
53
74
|
OA_BASE_URI=demo.openapply.com
|
54
75
|
|
55
76
|
# this is the demo site key - you will need your own key for your own site
|
77
|
+
# from https://demo.openapply.com/admin/dashboard (it will reset every hour)
|
78
|
+
# navigate to Settings > Integrations, and enable the API, and generate a token
|
56
79
|
OA_AUTH_TOKEN=demo_site_api_key
|
57
80
|
```
|
58
81
|
|
@@ -64,7 +87,9 @@ Associates the above settings with HTTParty
|
|
64
87
|
@oa = OpenApply::Client.new
|
65
88
|
```
|
66
89
|
|
67
|
-
|
90
|
+
### USAGE
|
91
|
+
|
92
|
+
#### USAGE SUMMARY
|
68
93
|
|
69
94
|
```ruby
|
70
95
|
# instantiate
|
@@ -75,141 +100,158 @@ Associates the above settings with HTTParty
|
|
75
100
|
@oa.api_key
|
76
101
|
@oa.base_path
|
77
102
|
@oa.api_timeout
|
78
|
-
@oa.
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
#### Method list
|
84
|
-
|
85
|
-
* individual student details
|
86
|
-
|
87
|
-
```ruby
|
88
|
-
# all student info & parents info
|
89
|
-
def student_by_id(student_id, options ={})
|
90
|
-
# all payments associated with a student
|
91
|
-
def payments_by_id(student_id, options={})
|
92
|
-
# this is all student details (combines studnet, parent and payments)
|
93
|
-
def student_details_by_id(id, flatten = false)
|
94
|
-
```
|
95
|
-
|
96
|
-
* group of students (summary data) -- **(recursive - collects all pages of records if return_count < total_records)**
|
103
|
+
@oa.api_records
|
104
|
+
#
|
105
|
+
# directly call against the OA API
|
106
|
+
@oa.oa_api_call('/api/v1/students/?status=accepted&count=5&auth_token=add_api_key')
|
107
|
+
#
|
97
108
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
# only student ids of students with a given status
|
102
|
-
def student_ids_by_status(status)
|
109
|
+
# Individual students records (separated)
|
110
|
+
@oa.student_by_id(95)
|
111
|
+
@oa.payments_by_id(95)
|
103
112
|
#
|
104
|
-
#
|
105
|
-
|
113
|
+
# individual student records combined & possible pre-processing
|
114
|
+
# ATTRIBUTES: id, [:keys_to_un-nest], [:keys_to_exclude]
|
115
|
+
@oa.student_details_by_id(95)
|
116
|
+
@oa.student_details_by_id(95, [:custom_fields], [:parent_guardian])
|
106
117
|
#
|
107
|
-
#
|
108
|
-
|
109
|
-
#
|
110
|
-
#
|
111
|
-
|
118
|
+
# student summaries of a given status (recursively if more than on page)
|
119
|
+
@oa.students_by_status('applied')
|
120
|
+
#
|
121
|
+
# student details of a given status (recursively if more than on page)
|
122
|
+
@oa.students_details_by_status('applied')
|
123
|
+
@oa.students_details_by_status('applied', [:custom_fields])
|
124
|
+
@oa.students_details_by_status('applied', nil, [:parent_guardian])
|
125
|
+
@oa.students_details_by_status('applied', [:custom_fields], [:parent_guardian])
|
126
|
+
#
|
127
|
+
# student details with multiple status (recursively if more than on page)
|
128
|
+
@oa.students_details_by_statuses(['applied','enrolled'], [:custom_fields])
|
129
|
+
@oa.students_details_by_statuses(['applied','enrolled'], nil, [:parent_guardian])
|
130
|
+
@oa.students_details_by_statuses(['applied','enrolled'], [:custom_fields], [:parent_guardian])
|
131
|
+
#
|
132
|
+
# create an array
|
133
|
+
@oa.students_as_array_by_status('applied', [:custom_fields], [:parent_guardian], [:id, :name], {count: 1, keys: [:id, :name, :address]}, {count: 2, order: :newest, keys: [:date, :amount]} )
|
134
|
+
# multiple statuses into an array
|
135
|
+
@oa.students_as_array_by_statuses(['applied','enrolled'], [:custom_fields], [:parent_guardian], [:id, :name], {count: 1, keys: [:id, :name, :address]}, {count: 2, order: :newest, keys: [:date, :amount]} )
|
136
|
+
#
|
137
|
+
# Create a csv string
|
138
|
+
@oa.students_as_csv_by_status('applied',[:custom_fields], [:parent_guardian], [:id, :name], {type: :guardians, count: 1, keys: [:id, :name, :address]}, {type: :payments, count: 2, order: :newest, keys: [:date, :amount]} )
|
139
|
+
# multiple status into
|
140
|
+
csv_string=@oa.students_as_csv_by_statuses(['applied','enrolled'],[:custom_fields], [:parent_guardian], [:id, :name], {type: :guardians, count: 1, keys: [:id, :name, :address]}, {type: :payments, count: 2, order: :newest, keys: [:date, :amount]} )
|
141
|
+
#
|
142
|
+
# send CSV to a remote server as a file - using ssh-keys
|
143
|
+
@oa.send_data_to_remote_server(csv_string, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
|
144
|
+
|
145
|
+
# Create XLSX file
|
146
|
+
@oa.students_as_xlsx_by_status('applied',[:custom_fields], [:parent_guardian], [:id, :name], {type: :guardians, count: 1, keys: [:id, :name, :address]}, {type: :payments, count: 2, order: :newest, keys: [:date, :amount]} )
|
147
|
+
# multiple status into
|
148
|
+
xlsx_obj=@oa.students_as_xlsx_by_statuses(['applied','enrolled'],[:custom_fields], [:parent_guardian], [:id, :name], {type: :guardians, count: 1, keys: [:id, :name, :address]}, {type: :payments, count: 2, order: :newest, keys: [:date, :amount]} )
|
149
|
+
#
|
150
|
+
# send XLSX to a remote server as a file - using ssh-keys
|
151
|
+
@oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.xlsx', '0750')
|
112
152
|
```
|
113
153
|
|
114
|
-
|
154
|
+
#### INDIVIDUAL STUDENT QUERIES
|
155
|
+
|
115
156
|
```ruby
|
116
|
-
|
117
|
-
|
157
|
+
# all student info & parents info -- returns the data straight from OpenApply
|
158
|
+
student_record = @oa.student_by_id(95)
|
159
|
+
|
160
|
+
# all payments associated with a student -- returns the data straight from OpenApply
|
161
|
+
student_payments = @oa.payments_by_id(95)
|
162
|
+
|
163
|
+
# Returns all student details (combines studnet, parent and payments)
|
164
|
+
# **flatten_keys** - brings these keys to the top level - prepending the group name to the key name -- we usually use:
|
165
|
+
# flatten_keys = [:custom_fields]
|
166
|
+
# **reject keys** -- removes the data matching these keys -- we usually use:
|
167
|
+
# reject_keys = [:parent_guardian] (since this is duplicated)
|
168
|
+
# returns the data structured as:
|
169
|
+
# { student: {
|
170
|
+
# id: xxx,
|
171
|
+
# record: {xxx} # complete student record
|
172
|
+
# guardians: [ {} ] # all guardian information
|
173
|
+
# payments: [ {} ] # all payments made via openapply
|
174
|
+
# }
|
175
|
+
# }
|
176
|
+
@oa.student_details_by_id(95)
|
177
|
+
# or
|
178
|
+
@oa.student_details_by_id(95, [:custom_fields], [:parent_guardian])
|
118
179
|
```
|
119
180
|
|
120
|
-
####
|
181
|
+
#### DATA OF GROUPS OF STUDENTS
|
121
182
|
|
122
|
-
|
183
|
+
searched recursively - collects all pages of records
|
123
184
|
|
124
185
|
```ruby
|
125
|
-
#
|
186
|
+
# SUMMARY INFO of students with a given status - ONLY ONE STATUS string!
|
187
|
+
@oa.students_by_status('applied')
|
126
188
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
# parents: [
|
141
|
-
# id: value5,
|
142
|
-
# name: parent_name,
|
143
|
-
# custom_fields: {
|
144
|
-
# key6: value6,
|
145
|
-
# ...
|
146
|
-
# }
|
147
|
-
# ]
|
148
|
-
# }
|
149
|
-
# }
|
189
|
+
# STUDENT IDs of students with a given status or array of statuses
|
190
|
+
ids = @oa.student_ids_by_status('applied')
|
191
|
+
ids = @oa.student_ids_by_statuses(['applied','enrolled'])
|
192
|
+
# [1, 2, 60]
|
193
|
+
#
|
194
|
+
# FULL STUDENT DETAILS for all students of a given status or statuses
|
195
|
+
# **returned as a hash)** -- attributes are (status, flatten_keys, reject_keys)
|
196
|
+
# example usage:
|
197
|
+
@oa.students_details_by_status('applied')
|
198
|
+
@oa.students_details_by_status('applied',[:custom_fields])
|
199
|
+
@oa.students_details_by_status('applied', [:custom_fields], [:parent_guardian])
|
200
|
+
@oa.students_details_by_status(['applied','enrolled'])
|
201
|
+
@oa.students_details_by_status(['applied','enrolled'], nil, [:parent_guardian])
|
150
202
|
```
|
151
203
|
|
152
|
-
|
204
|
+
|
205
|
+
#### STUDENT DATA TRANFORMATIONS
|
153
206
|
|
154
207
|
```ruby
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
161
|
-
|
162
|
-
#
|
163
|
-
|
164
|
-
#
|
208
|
+
# student details - in an array format (instead of hash)
|
209
|
+
# ATTRIBUTES - status, flatten_keys, reject_keys, student_keys(into array), guardian_info(into array), payment_info(into array)
|
210
|
+
# guardian and payment info options:
|
211
|
+
# count - how many records to return
|
212
|
+
# keys - which keys to return to array/csv
|
213
|
+
# order: :newest/:oldest (for payments) - return newest or oldest payments first
|
214
|
+
@oa.students_as_array_by_status('applied', nil, nil, [:id, :name], nil, {count: 2, order: :newest, keys: [:date, :amount]} )
|
215
|
+
# all options
|
216
|
+
@oa.students_as_array_by_status('applied',[:custom_fields], [:parent_guardian], [:id, :name], {count: 1, keys: [:id, :name, :address]}, {count: 2, order: :newest, keys: [:date, :amount]} )
|
217
|
+
#
|
218
|
+
# Create a csv string
|
219
|
+
@oa.students_as_csv_by_status('applied', nil, nil, [:id, :name], nil, {count: 2, order: :newest, keys: [:date, :amount]} )
|
220
|
+
# all options
|
221
|
+
csv=@oa.students_as_csv_by_status('applied',[:custom_fields], [:parent_guardian], [:id, :name], {count: 1, keys: [:id, :name, :address]}, {count: 2, order: :newest, keys: [:date, :amount]} )
|
222
|
+
#
|
223
|
+
# send CSV to a remote server as a file - using ssh-keys
|
224
|
+
# attributes: csv_string, srv_hostname, srv_username, srv_path_file, file_permissions(0750 - default if not specified)
|
225
|
+
@oa.send_data_to_remote_server(csv, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
|
226
|
+
#
|
227
|
+
# Create a XLSX package
|
228
|
+
@oa.students_as_xlsx_by_status('applied', nil, nil, [:id, :name], nil, {count: 2, order: :newest, keys: [:date, :amount]} )
|
229
|
+
# all options
|
230
|
+
xlsx=@oa.students_as_xlsx_by_status('applied',[:custom_fields], [:parent_guardian], [:id, :name], {count: 1, keys: [:id, :name, :address]}, {count: 2, order: :newest, keys: [:date, :amount]} )
|
231
|
+
#
|
232
|
+
# send CSV to a remote server as a file - using ssh-keys
|
233
|
+
# attributes: csv_string, srv_hostname, srv_username, srv_path_file, file_permissions(0750 - default if not specified)
|
234
|
+
@oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
|
165
235
|
```
|
166
236
|
|
167
|
-
|
237
|
+
#### CUSTOM GROUP QUERIES - summary data
|
168
238
|
|
169
239
|
```ruby
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
#
|
174
|
-
|
175
|
-
#
|
176
|
-
#
|
177
|
-
|
178
|
-
|
179
|
-
#
|
180
|
-
|
181
|
-
# custom_fields: {
|
182
|
-
# key2: value2,
|
183
|
-
# ...
|
184
|
-
# }
|
185
|
-
# },
|
186
|
-
# payments: [
|
187
|
-
# {payment1},
|
188
|
-
# {payment2}
|
189
|
-
# ],
|
190
|
-
# guardians: [
|
191
|
-
# { id: id,
|
192
|
-
# name: guardian1,
|
193
|
-
# ... ,
|
194
|
-
# custom_fields: {
|
195
|
-
# key2: value2,
|
196
|
-
# ...
|
197
|
-
# }
|
198
|
-
# },
|
199
|
-
# { id: id,
|
200
|
-
# name: guardian2,
|
201
|
-
# ... ,
|
202
|
-
# custom_fields: {
|
203
|
-
# key2: value2,
|
204
|
-
# ...
|
205
|
-
# }
|
206
|
-
# }
|
207
|
-
# ]
|
208
|
-
# }
|
209
|
-
# }
|
240
|
+
# status = 'applied' # all records matching a valid openapply status
|
241
|
+
# since_id = 95 # all records with ids after 95
|
242
|
+
# since_date = '2017-11-12' # all records modified after 2017-11-12 (& time)
|
243
|
+
# count = 20 # records per page
|
244
|
+
|
245
|
+
# build a custom url query to send to OA api
|
246
|
+
# returns a url that can be passed to api
|
247
|
+
@oa.students_query_url('applied', 106, '2017-11-12', 25)
|
248
|
+
|
249
|
+
# executes a custom query and returns a group of student summaries matching criteria
|
250
|
+
@oa.students_query('applied', 106, '2017-11-12', 25)
|
210
251
|
```
|
211
252
|
|
212
|
-
|
253
|
+
|
254
|
+
#### OpenApply's allowed statuses
|
213
255
|
|
214
256
|
* **valid status includes:**
|
215
257
|
- Status
|
@@ -223,270 +265,6 @@ def custom_students_url(status=nil, since_id=nil, since_date=nil, count=api_reco
|
|
223
265
|
- Withdrawn
|
224
266
|
|
225
267
|
|
226
|
-
* Get student summary info of all students of a given status **(all pages - uses recursion)**
|
227
|
-
|
228
|
-
```ruby
|
229
|
-
# def all_student_summaries_by_status(status)
|
230
|
-
|
231
|
-
@oa = OpenApply::Client.new
|
232
|
-
@answer = @oa.students_by_status('applied')
|
233
|
-
|
234
|
-
# answer format is:
|
235
|
-
# { students: [
|
236
|
-
# { id: id1,
|
237
|
-
# name: kid1,
|
238
|
-
# ...,
|
239
|
-
# { id: id2,
|
240
|
-
# name: kid_name_2,
|
241
|
-
# ...,
|
242
|
-
# }
|
243
|
-
# ],
|
244
|
-
# linked: {
|
245
|
-
# parents: [
|
246
|
-
# id: value5,
|
247
|
-
# name: parent_name,
|
248
|
-
# custom_fields: {
|
249
|
-
# key6: value6,
|
250
|
-
# ...
|
251
|
-
# }
|
252
|
-
# ]
|
253
|
-
# }
|
254
|
-
# }
|
255
|
-
```
|
256
|
-
|
257
|
-
* Get a list of student ids of all students of a given status **(all pages - uses recursion)**
|
258
|
-
|
259
|
-
```ruby
|
260
|
-
# def all_student_ids_by_status(status)
|
261
|
-
|
262
|
-
@oa = OpenApply::Client.new
|
263
|
-
@answer = @oa.student_ids_by_status('applied')
|
264
|
-
|
265
|
-
# answer format is:
|
266
|
-
# { student_ids: [95, 160, 240] }
|
267
|
-
```
|
268
|
-
|
269
|
-
* Get all student data of all students of a given status **(all pages - uses recursion)**
|
270
|
-
|
271
|
-
```ruby
|
272
|
-
# def all_students_all_data_by_status(status)
|
273
|
-
|
274
|
-
@oa = OpenApply::Client.new
|
275
|
-
@answer = @oa.students_details_by_status('enrolled')
|
276
|
-
|
277
|
-
# TODO: add correct info
|
278
|
-
# answer formats include:
|
279
|
-
# { students:
|
280
|
-
# [
|
281
|
-
# { id: value1,
|
282
|
-
# key2: value2,
|
283
|
-
# custom_fields: {
|
284
|
-
# key3: value3,
|
285
|
-
# key4: value4
|
286
|
-
# }
|
287
|
-
# },
|
288
|
-
# { id: valueX,
|
289
|
-
# key2: valueY,
|
290
|
-
# custom_fields: {
|
291
|
-
# key3: valueZ,
|
292
|
-
# key4: valueA
|
293
|
-
# }
|
294
|
-
# }
|
295
|
-
# ],
|
296
|
-
# guardians: [
|
297
|
-
# {
|
298
|
-
# id: value5,
|
299
|
-
# custom_fields: {
|
300
|
-
# key6: value6,
|
301
|
-
# ...
|
302
|
-
# },
|
303
|
-
# {
|
304
|
-
# id: value6,
|
305
|
-
# custom_fields: {
|
306
|
-
# key6: value7,
|
307
|
-
# ...
|
308
|
-
# },
|
309
|
-
# ]
|
310
|
-
# }
|
311
|
-
```
|
312
|
-
|
313
|
-
|
314
|
-
* Get all student data of all students of a given status **(all pages - uses recursion)**
|
315
|
-
|
316
|
-
```ruby
|
317
|
-
# FLATTEN RECORDS
|
318
|
-
# def all_students_all_data_by_status(status,true)
|
319
|
-
|
320
|
-
@oa = OpenApply::Client.new
|
321
|
-
@answer = @oa.students_details_by_status('enrolled',true)
|
322
|
-
|
323
|
-
# answer formats include:
|
324
|
-
# { students:
|
325
|
-
# [
|
326
|
-
# { id: value1,
|
327
|
-
# name: kid_1,
|
328
|
-
# key3: value3,
|
329
|
-
# key4: value4
|
330
|
-
# },
|
331
|
-
# { id: valueX,
|
332
|
-
# name: kid_2,
|
333
|
-
# key3: valueZ,
|
334
|
-
# key4: valueA
|
335
|
-
# }
|
336
|
-
# ],
|
337
|
-
# guardians: [
|
338
|
-
# { id: value5,
|
339
|
-
# name: guardian_1
|
340
|
-
# key6: value6,
|
341
|
-
# ...
|
342
|
-
# },
|
343
|
-
# { id: value6,
|
344
|
-
# name: guardian_2
|
345
|
-
# key6: value7,
|
346
|
-
# ...
|
347
|
-
# },
|
348
|
-
# ]
|
349
|
-
# }
|
350
|
-
```
|
351
|
-
|
352
|
-
#### Custom URL (GET) API calls
|
353
|
-
|
354
|
-
* Get student summary info of students with a custom query - supporting the description here: https://dev.faria.co/oa/#responses **(one page - no recursion)**
|
355
|
-
|
356
|
-
```ruby
|
357
|
-
# def custom_student_summaries(status=nil, since_id=nil, since_date=nil, count=self.record_count)
|
358
|
-
|
359
|
-
@oa = OpenApply::Client.new
|
360
|
-
# status -- return records matching this status
|
361
|
-
# since_id -- return records with ids after this id
|
362
|
-
# since_date (format: 'YYYY-MM-DD') -- return records updated after this date
|
363
|
-
# count (>= 1) -- is the number of records to return
|
364
|
-
@answer = @oa.students_custom('applied',240,nil,3)
|
365
|
-
@answer = @oa.students_custom('applied',nil,'2015-09-12',3)
|
366
|
-
|
367
|
-
# answer formats include:
|
368
|
-
# { students:
|
369
|
-
# [
|
370
|
-
# { id: value1,
|
371
|
-
# name: kid_1,
|
372
|
-
# ...,
|
373
|
-
# custom_fields: {
|
374
|
-
# key3: value3,
|
375
|
-
# key4: value4
|
376
|
-
# }
|
377
|
-
# },
|
378
|
-
# { id: valueX,
|
379
|
-
# name: kid_2,
|
380
|
-
# ...,
|
381
|
-
# custom_fields: {
|
382
|
-
# key3: valueZ,
|
383
|
-
# key4: valueA
|
384
|
-
# }
|
385
|
-
# }
|
386
|
-
# ],
|
387
|
-
# linked: {}
|
388
|
-
# parents: [
|
389
|
-
# {
|
390
|
-
# id: value5,
|
391
|
-
# name: parent_1,
|
392
|
-
# ...,
|
393
|
-
# custom_fields: {
|
394
|
-
# key6: value6,
|
395
|
-
# ...
|
396
|
-
# },
|
397
|
-
# {
|
398
|
-
# id: value6,
|
399
|
-
# name: parent_2,
|
400
|
-
# ...,
|
401
|
-
# custom_fields: {
|
402
|
-
# key6: value7,
|
403
|
-
# ...
|
404
|
-
# },
|
405
|
-
# ]
|
406
|
-
# }
|
407
|
-
# meta: {
|
408
|
-
# page: 3,
|
409
|
-
# per_page": "2"
|
410
|
-
# }
|
411
|
-
# }
|
412
|
-
```
|
413
|
-
|
414
|
-
* Get a response to a custom url query - this is the lowest level access
|
415
|
-
|
416
|
-
```ruby
|
417
|
-
# def oa_answer( url, options={} )
|
418
|
-
|
419
|
-
url = "api/v1/students?since_id=269&auth_token=demo_site_api_key"
|
420
|
-
|
421
|
-
@oa = OpenApply::Client.new
|
422
|
-
@oa_answer = @oa.oa_answer( url )
|
423
|
-
|
424
|
-
# answer format like:
|
425
|
-
#<HTTParty::Response:0x7f851fa20408 parsed_response="{\"payments\":[]}", @response=#<Net::HTTPOK 200 readbody=true>, @headers={}>
|
426
|
-
#
|
427
|
-
# access data using something like:
|
428
|
-
return { error: "no answer" } unless @oa_answer.responds_to? 'response'
|
429
|
-
return { error: "no answer" } unless (@oa_answer.response).responds_to? 'body'
|
430
|
-
return JSON.parse( @api_answer.response.body, symbolize_names: true )
|
431
|
-
|
432
|
-
# answer formats include:
|
433
|
-
# { student:
|
434
|
-
# { id: value1,
|
435
|
-
# key2: value2,
|
436
|
-
# custom_fields: {
|
437
|
-
# key3: value3,
|
438
|
-
# key4: value4
|
439
|
-
# }
|
440
|
-
# },
|
441
|
-
# linked: {
|
442
|
-
# parents: [
|
443
|
-
# id: value5,
|
444
|
-
# custom_fields: {
|
445
|
-
# key6: value6,
|
446
|
-
# ...
|
447
|
-
# }
|
448
|
-
# ]
|
449
|
-
# }
|
450
|
-
# }
|
451
|
-
# or
|
452
|
-
# {
|
453
|
-
# payments: [
|
454
|
-
# {key1: value1, key2: value2},
|
455
|
-
# {key1: value3, key2: value3}
|
456
|
-
# ],
|
457
|
-
# }
|
458
|
-
# or
|
459
|
-
# {
|
460
|
-
# students: [
|
461
|
-
# {id: value1, key2: value2, custom_fields: {key3: value3, key4: value4} },
|
462
|
-
# {id: value3, key2: value3, custom_fields: {key3: value3, key5: value5} }
|
463
|
-
# ],
|
464
|
-
# linked: {
|
465
|
-
# parents: [
|
466
|
-
# id: value5,
|
467
|
-
# custom_fields: {
|
468
|
-
# key6: value6,
|
469
|
-
# ...
|
470
|
-
# }
|
471
|
-
# ]
|
472
|
-
# }
|
473
|
-
# meta: {
|
474
|
-
# page: 3,
|
475
|
-
# per_page": "10"
|
476
|
-
# }
|
477
|
-
# }
|
478
|
-
```
|
479
|
-
|
480
|
-
#### Group queries with recursion (by since_date)
|
481
|
-
not done (just code stubs)- not yet needed
|
482
|
-
|
483
|
-
#### Group queries with recursion (by since_id)
|
484
|
-
not done (just code stubs)- not yet needed
|
485
|
-
|
486
|
-
#### See Examples Folder
|
487
|
-
|
488
|
-
for an actual complete code examples
|
489
|
-
|
490
268
|
## Development
|
491
269
|
|
492
270
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|