openapply 0.2.10 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +7 -7
- data/.travis.yml.bak +18 -0
- data/CHANGE_LOG.md +50 -0
- data/Gemfile.lock +6 -4
- data/MM +0 -0
- data/README.md +26 -200
- data/lib/openapply/client.rb +13 -39
- data/lib/openapply/get_many_students.rb +125 -0
- data/lib/openapply/get_one_student.rb +65 -0
- data/lib/openapply/version.rb +1 -1
- data/openapply.gemspec +9 -39
- metadata +17 -18
- data/examples/demo/Gemfile +0 -6
- data/examples/demo/Gemfile.lock +0 -24
- data/examples/demo/README.md +0 -123
- data/examples/demo/demo_site.rb +0 -92
- data/lib/openapply/convert_to_array.rb +0 -215
- data/lib/openapply/convert_to_csv.rb +0 -59
- data/lib/openapply/convert_to_xlsx.rb +0 -80
- data/lib/openapply/get_student.rb +0 -219
- data/lib/openapply/get_students.rb +0 -209
- data/lib/openapply/send_to_remote.rb +0 -61
@@ -0,0 +1,125 @@
|
|
1
|
+
module Get
|
2
|
+
|
3
|
+
# @note Get all student details matching the criteria in params
|
4
|
+
# @param params[:status] - (String or Array of Strings) - list the status wanted
|
5
|
+
# @param params[:since_id] - (Integer) - get all ids matching the criteria LARGER than the given number
|
6
|
+
# @param params[:since_date] - (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
7
|
+
# @param params[:count] - (Integer) - The number of customers to return - large numbers need a large timeout
|
8
|
+
# @param options[:get_payments] (Boolean) - get student payments
|
9
|
+
def many_students_details( params, options={} )
|
10
|
+
ids = many_students_ids( params )
|
11
|
+
return {error: "need an array of ids"} unless ids[:ids]
|
12
|
+
return many_students_details_by_ids( ids[:ids], options )
|
13
|
+
end
|
14
|
+
|
15
|
+
# @note Get all student details matching the criteria in params
|
16
|
+
# @param ids - (Array of Integers) - list ids wanted to lookup
|
17
|
+
# @param options[:get_payments] (Boolean) - get student payments
|
18
|
+
def many_students_details_by_ids( ids, options={} )
|
19
|
+
return {error: 'no ids provided'} if ids.nil? or ids.empty?
|
20
|
+
students = []
|
21
|
+
guardians = []
|
22
|
+
ids = [ids] unless ids.is_a? Array
|
23
|
+
ids.each do |id|
|
24
|
+
response = one_student_details_by_id( id, options )
|
25
|
+
# pp response
|
26
|
+
students << response[:student]
|
27
|
+
guardians << response[:guardians]
|
28
|
+
end
|
29
|
+
return {
|
30
|
+
students: students,
|
31
|
+
guardians: guardians,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
# @note Get all student ids matching the criteria in params
|
36
|
+
# @param params[:status] - (String or Array of Strings) - list the status wanted
|
37
|
+
# @param params[:since_id] - (Integer) - get all ids matching the criteria LARGER than the given number
|
38
|
+
# @param params[:since_date] - (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
39
|
+
# @param params[:count] - (Integer) - The number of customers to return - large numbers need a large timeout
|
40
|
+
def many_students_ids( params )
|
41
|
+
response = many_students_summaries( params )
|
42
|
+
ids = response[:students].map{ |kid| kid[:id] }
|
43
|
+
{ ids: ids }
|
44
|
+
end
|
45
|
+
|
46
|
+
# @note Get all student ids & guardian ids with associated last updated timestamp (matching the criteria in params)
|
47
|
+
# @param params[:status] - (String or Array of Strings) - list the status wanted
|
48
|
+
# @param params[:since_id] - (Integer) - get all ids matching the criteria LARGER than the given number
|
49
|
+
# @param params[:since_date] - (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
50
|
+
# @param params[:count] - (Integer) - The number of customers to return - large numbers need a large timeout
|
51
|
+
def many_ids_updated_time( params )
|
52
|
+
response = many_students_summaries( params )
|
53
|
+
kids = response[:students].map{ |kid| {kid[:id] => kid[:updated_at]} }
|
54
|
+
rents = response[:guardians].map{ |rent| {rent[:id] => rent[:updated_at]} }
|
55
|
+
{ ids_updated_at:
|
56
|
+
{
|
57
|
+
students: kids,
|
58
|
+
guardians: rents,
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
# @note Get all student summaries matching the criteria in params
|
64
|
+
# @param params[:status] - (String or Array of Strings) - list the status wanted
|
65
|
+
# @param params[:since_id] - (Integer) - get all ids matching the criteria LARGER than the given number
|
66
|
+
# @param params[:since_date] - (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
67
|
+
# @param params[:count] - (Integer) - The number of customers to return - large numbers need a large timeout
|
68
|
+
def many_students_summaries( params={} )
|
69
|
+
# status=nil,since_id=nil,since_date=nil,count=api_records)
|
70
|
+
return {error: 'no query provided'} if params.empty?
|
71
|
+
|
72
|
+
students = []
|
73
|
+
guardians = []
|
74
|
+
|
75
|
+
count = params[:count]
|
76
|
+
count ||= api_records()
|
77
|
+
since_date = params[:since_date]
|
78
|
+
statuses = params[:status]
|
79
|
+
statuses = [statuses] if not statuses.nil? and
|
80
|
+
statuses.is_a? String
|
81
|
+
statuses.each do |status|
|
82
|
+
|
83
|
+
# these values need to be reset for each status loop
|
84
|
+
page_number = nil
|
85
|
+
since_id = params[:since_id]
|
86
|
+
|
87
|
+
# loop until all pages recieved
|
88
|
+
while page_number.nil? or page_number > 1
|
89
|
+
url = url_for_many_students_summaries(status, since_id, since_date, count)
|
90
|
+
answer = oa_answer( url )
|
91
|
+
break if answer.nil? or answer[:students].empty?
|
92
|
+
|
93
|
+
students += answer[:students]
|
94
|
+
guardians += answer[:linked][:parents]
|
95
|
+
|
96
|
+
last_student = answer[:students].last
|
97
|
+
since_id = last_student[:id]
|
98
|
+
# since_id = (answer[:students].last)[:id]
|
99
|
+
page_number = answer[:meta][:pages]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return {
|
103
|
+
students: students,
|
104
|
+
guardians: guardians,
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
# @note Get url to query for student summaries matching the criteria in params
|
109
|
+
# @param status - (String or Array of Strings) - list the status wanted
|
110
|
+
# @param since_id - (Integer) - get all ids matching the criteria LARGER than the given number
|
111
|
+
# @param since_date - (String) - all records updated after the given date (YYYY-MM-DD) or Date and Time (YYYY-MM-DD HH:MM:SS) - 24 hour clock (not sure about timeszone)
|
112
|
+
# @param count - (Integer) - The number of customers to return - large numbers need a large timeout
|
113
|
+
def url_for_many_students_summaries(status=nil, since_id=nil,
|
114
|
+
since_date=nil, count=api_records)
|
115
|
+
url_options = []
|
116
|
+
url_options << "status=#{status}" unless status.to_s.eql? ""
|
117
|
+
url_options << "since_id=#{since_id}" unless since_id.to_s.eql? ""
|
118
|
+
url_options << "since_date=#{since_date}" unless since_date.to_s.eql? ""
|
119
|
+
url_options << "count=#{count}"
|
120
|
+
url_options << "auth_token=#{api_key}"
|
121
|
+
|
122
|
+
return "#{api_path}?#{url_options.join('&')}"
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# SINGLE STUDENT API GET CALLS
|
2
|
+
##############################
|
3
|
+
|
4
|
+
module Get
|
5
|
+
|
6
|
+
# @note Get all student details matching the associated id
|
7
|
+
# @param ids - (Integer) - ids of student to lookup
|
8
|
+
# @param options[:get_payments] (Boolean) - get student payments (or not)
|
9
|
+
def one_student_details_by_id( id, options={} )
|
10
|
+
|
11
|
+
get_payments = options[:get_payments] unless options.nil? or options.empty?
|
12
|
+
get_payments ||= true if get_payments.nil?
|
13
|
+
|
14
|
+
# get full student record and guardian information
|
15
|
+
student_info = one_student_record_by_id( "#{id}" )
|
16
|
+
|
17
|
+
# be sure there is student data to process -- if not return an empty record
|
18
|
+
return {student: {id: id, empty: []}} if student_info.nil? or
|
19
|
+
student_info[:student].nil?
|
20
|
+
student_info[:student].empty?
|
21
|
+
student = []
|
22
|
+
# extract the student info
|
23
|
+
student = student_info[:student] unless student_info[:student].nil?
|
24
|
+
|
25
|
+
guardians = []
|
26
|
+
# extract guardian information
|
27
|
+
guardians = student_info[:linked][:parents].dup unless
|
28
|
+
student_info[:linked].nil? or
|
29
|
+
student_info[:linked].empty? or
|
30
|
+
student_info[:linked][:parents].nil?
|
31
|
+
payments = []
|
32
|
+
# get student payment records
|
33
|
+
payment_info = one_student_payments_by_id("#{id}") if get_payments.eql? true
|
34
|
+
# extract payment information
|
35
|
+
payments = payment_info[:payments].dup unless payment_info.nil? or
|
36
|
+
payment_info[:payments].nil?
|
37
|
+
# organize the student details
|
38
|
+
return {
|
39
|
+
student:
|
40
|
+
{ id: id,
|
41
|
+
record: student,
|
42
|
+
payments: payments,
|
43
|
+
guardians: guardians,
|
44
|
+
},
|
45
|
+
guardians: guardians,
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
# @note Get one student's primary record matching the associated id
|
50
|
+
# @param ids - (Integer) - ids of student to lookup
|
51
|
+
# @param options - http options
|
52
|
+
def one_student_record_by_id(id, options ={})
|
53
|
+
url = "#{api_path}#{id}?auth_token=#{api_key}"
|
54
|
+
return oa_answer( url, options )
|
55
|
+
end
|
56
|
+
|
57
|
+
# @note Get one student's details matching the associated id
|
58
|
+
# @param ids - (Integer) - ids of student to lookup
|
59
|
+
# @param options - http options
|
60
|
+
def one_student_payments_by_id(id, options={})
|
61
|
+
url = "#{api_path}#{id}/payments?auth_token=#{api_key}"
|
62
|
+
return oa_answer( url, options )
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/openapply/version.rb
CHANGED
data/openapply.gemspec
CHANGED
@@ -7,22 +7,16 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "openapply"
|
8
8
|
spec.version = Openapply::VERSION
|
9
9
|
spec.authors = ["Bill Tihen"]
|
10
|
-
spec.email = ["btihen@
|
10
|
+
spec.email = ["btihen@las.ch"]
|
11
11
|
|
12
12
|
spec.summary = %q{Access OpenApply's API with Ruby}
|
13
|
-
|
14
|
-
|
13
|
+
spec.description = %q{Access to OpenApply's API and extra utilities that
|
14
|
+
accomplish common needs -- such as recursively query
|
15
|
+
for all students of a given status or change-date
|
16
|
+
until all needed records are recieved.}
|
17
|
+
spec.homepage = "https://github.com/las-it/openapply"
|
15
18
|
spec.license = "MIT"
|
16
19
|
|
17
|
-
# # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# # to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata["allowed_push_host"] = "http://rubygems.org"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
# "public gem pushes."
|
24
|
-
# end
|
25
|
-
|
26
20
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
21
|
f.match(%r{^(test|spec|features)/})
|
28
22
|
end
|
@@ -34,37 +28,13 @@ Gem::Specification.new do |spec|
|
|
34
28
|
spec.add_dependency "json" , "~> 2.1"
|
35
29
|
spec.add_dependency "net-ssh", "~> 4.2"
|
36
30
|
spec.add_dependency "net-scp", "~> 1.2"
|
37
|
-
|
38
|
-
# # need this version of axlsx to match roo's rubyzip needs
|
39
|
-
# # axlsx 2.1.0.pre uses rubyzip 1.1.7 - which has a security flaw
|
40
|
-
# # using the newest version of rubyzip 1.2.1 or larger
|
41
|
-
# # https://github.com/randym/axlsx/issues/501
|
42
|
-
# gem 'axlsx', git: 'https://github.com/randym/axlsx',
|
43
|
-
# branch: 'master'
|
44
|
-
# https://github.com/straydogstudio/axlsx_rails/issues/77
|
45
|
-
# gem 'axlsx', git: 'https://github.com/randym/axlsx.git',
|
46
|
-
# ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
|
47
|
-
# spec.add_dependency 'axlsx', git: 'https://github.com/randym/axlsx', branch: 'master'
|
48
|
-
# spec.add_dependency 'axlsx', "2.1.0.pre", git: 'https://github.com/randym/axlsx', branch: 'master'
|
49
|
-
# # https://github.com/randym/axlsx/issues/234
|
50
|
-
# # spec.add_dependency 'zip-zip'
|
51
31
|
#
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
# don't use official release - use above
|
56
|
-
# spec.add_dependency "axlsx", "2.1.0.pre"
|
57
|
-
# spec.add_dependency "rubyzip", "~> 1.2"
|
58
|
-
# spec.add_runtime_dependency "axlsx", "2.1.0.pre"
|
59
|
-
# spec.add_runtime_dependency "rubyzip", "~> 1.2"
|
60
|
-
|
61
|
-
spec.add_development_dependency "simplecov", "~> 0.15"
|
62
|
-
spec.add_development_dependency "webmock" , "~> 3.2"
|
32
|
+
# spec.add_development_dependency "simplecov", "~> 0.15"
|
33
|
+
spec.add_development_dependency 'codacy-coverage', '~> 1.1'
|
34
|
+
spec.add_development_dependency "webmock", "~> 3.2"
|
63
35
|
spec.add_development_dependency "bundler", "~> 1.15"
|
64
|
-
# spec.add_development_dependency "rake", "~> 10.0"
|
65
36
|
spec.add_development_dependency "rake", "~> 12.3"
|
66
37
|
spec.add_development_dependency "rspec", "~> 3.7"
|
67
38
|
spec.add_development_dependency "pry", "~> 0.11"
|
68
|
-
# spec.add_development_dependency "roo", "~> 2.7"
|
69
39
|
|
70
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapply
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -67,19 +67,19 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: codacy-coverage
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,9 +150,13 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0.11'
|
153
|
-
description:
|
153
|
+
description: |-
|
154
|
+
Access to OpenApply's API and extra utilities that
|
155
|
+
accomplish common needs -- such as recursively query
|
156
|
+
for all students of a given status or change-date
|
157
|
+
until all needed records are recieved.
|
154
158
|
email:
|
155
|
-
- btihen@
|
159
|
+
- btihen@las.ch
|
156
160
|
executables: []
|
157
161
|
extensions: []
|
158
162
|
extra_rdoc_files: []
|
@@ -161,30 +165,25 @@ files:
|
|
161
165
|
- ".gitignore"
|
162
166
|
- ".rspec"
|
163
167
|
- ".travis.yml"
|
168
|
+
- ".travis.yml.bak"
|
169
|
+
- CHANGE_LOG.md
|
164
170
|
- CODE_OF_CONDUCT.md
|
165
171
|
- Gemfile
|
166
172
|
- Gemfile.lock
|
167
173
|
- LICENSE.txt
|
174
|
+
- MM
|
168
175
|
- README.md
|
169
176
|
- Rakefile
|
170
177
|
- bin/console
|
171
178
|
- bin/setup
|
172
|
-
- examples/demo/Gemfile
|
173
|
-
- examples/demo/Gemfile.lock
|
174
|
-
- examples/demo/README.md
|
175
|
-
- examples/demo/demo_site.rb
|
176
179
|
- lib/openapply.rb
|
177
180
|
- lib/openapply/client.rb
|
178
|
-
- lib/openapply/
|
179
|
-
- lib/openapply/
|
180
|
-
- lib/openapply/convert_to_xlsx.rb
|
181
|
-
- lib/openapply/get_student.rb
|
182
|
-
- lib/openapply/get_students.rb
|
181
|
+
- lib/openapply/get_many_students.rb
|
182
|
+
- lib/openapply/get_one_student.rb
|
183
183
|
- lib/openapply/put.rb
|
184
|
-
- lib/openapply/send_to_remote.rb
|
185
184
|
- lib/openapply/version.rb
|
186
185
|
- openapply.gemspec
|
187
|
-
homepage: https://github.com/
|
186
|
+
homepage: https://github.com/las-it/openapply
|
188
187
|
licenses:
|
189
188
|
- MIT
|
190
189
|
metadata: {}
|
data/examples/demo/Gemfile
DELETED
data/examples/demo/Gemfile.lock
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
httparty (0.15.6)
|
5
|
-
multi_xml (>= 0.5.2)
|
6
|
-
json (2.1.0)
|
7
|
-
multi_xml (0.6.0)
|
8
|
-
net-scp (1.2.1)
|
9
|
-
net-ssh (>= 2.6.5)
|
10
|
-
net-ssh (4.2.0)
|
11
|
-
openapply (0.2.4)
|
12
|
-
httparty (~> 0.15)
|
13
|
-
json (~> 2.1)
|
14
|
-
net-scp (~> 1.2)
|
15
|
-
net-ssh (~> 4.2)
|
16
|
-
|
17
|
-
PLATFORMS
|
18
|
-
ruby
|
19
|
-
|
20
|
-
DEPENDENCIES
|
21
|
-
openapply (~> 0.2)
|
22
|
-
|
23
|
-
BUNDLED WITH
|
24
|
-
1.16.0
|
data/examples/demo/README.md
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
## Usage
|
2
|
-
|
3
|
-
In the terminal:
|
4
|
-
|
5
|
-
```bash
|
6
|
-
gem install openapply
|
7
|
-
# or better still
|
8
|
-
bundle install
|
9
|
-
|
10
|
-
irb
|
11
|
-
# or better still
|
12
|
-
pry
|
13
|
-
```
|
14
|
-
Once in the REPL - follow the below instructions
|
15
|
-
|
16
|
-
### Standard Usage - multiple classes accomodates multiple OpenApply Sites
|
17
|
-
```ruby
|
18
|
-
|
19
|
-
require 'pp'
|
20
|
-
require 'date'
|
21
|
-
require_relative './demo_site'
|
22
|
-
|
23
|
-
# use a class override in order to interact with multiple oa sites
|
24
|
-
# or extend functionality
|
25
|
-
@my = MySite.new()
|
26
|
-
|
27
|
-
|
28
|
-
# get students with applied and enrolled status, flatten no fields,
|
29
|
-
# remove the parent_guardian (duplicate) info,
|
30
|
-
# move into the xlsx file the following data: studnet id and student name
|
31
|
-
# parent address (line 1) and country, and no payment info
|
32
|
-
@my.records_as_csv_to_file('applied', nil, [:parent_guardian],
|
33
|
-
[:id, :name],
|
34
|
-
{keys: [:address, :country]}, nil , "test-#{Date.today}.csv" )
|
35
|
-
|
36
|
-
@my.records_as_csv_to_server( 'applied', nil, [:parent_guardian],
|
37
|
-
[:id, :name],
|
38
|
-
{keys: [:address, :country]}, nil )
|
39
|
-
|
40
|
-
# DISABLED UNTIL AXLSX works with RubyZip 1.2.1
|
41
|
-
# # get students with applied and enrolled status, flatten the custom_fields,
|
42
|
-
# # remove the parent_guardian (duplicate) info,
|
43
|
-
# # move into the xlsx file the following data: studnet id and student name
|
44
|
-
# # parent address (line 1) and country, and the oldest three payment amounts & dates
|
45
|
-
# @my.records_as_xlsx_to_file( ['applied','enrolled'], [:custom_fields],
|
46
|
-
# [:parent_guardian], [:id, :name],
|
47
|
-
# {count: 2, keys: [:address, :country]},
|
48
|
-
# {count: 3, order: :oldest, keys: [:amount, :date]}, "test-#{Date.today}.xlsx")
|
49
|
-
#
|
50
|
-
# @my.records_as_xlsx_to_server(['applied','enrolled'], [:custom_fields],
|
51
|
-
# [:parent_guardian], [:id, :name],
|
52
|
-
# {count: 2, keys: [:address, :country]},
|
53
|
-
# {count: 3, order: :newest, keys: [:amount, :date]})
|
54
|
-
|
55
|
-
# use cron or other similar tools to automate these processes
|
56
|
-
```
|
57
|
-
|
58
|
-
|
59
|
-
### Basic Usage using the gem directly - can only access one site
|
60
|
-
```ruby
|
61
|
-
require 'openapply'
|
62
|
-
|
63
|
-
# BASIC USAGE (see readme)
|
64
|
-
# use the .rbenv-vars for a simple setup
|
65
|
-
@oa = Openapply::Client.new()
|
66
|
-
|
67
|
-
# see settings
|
68
|
-
@oa.api_url
|
69
|
-
@oa.api_key
|
70
|
-
@oa.base_path
|
71
|
-
@oa.api_timeout
|
72
|
-
@oa.api_reply_count
|
73
|
-
|
74
|
-
|
75
|
-
# student summarys with applied status
|
76
|
-
summaries = @oa.students_by_status('applied')
|
77
|
-
student_ids = @oa.student_ids_by_status('applied')
|
78
|
-
|
79
|
-
ids = student_ids[:student_ids]
|
80
|
-
|
81
|
-
|
82
|
-
# first student details - return data as is
|
83
|
-
details = @oa.student_details_by_id(ids.first)
|
84
|
-
|
85
|
-
# last applied student details - custom fields -
|
86
|
-
# top level & duplicate :parent removed
|
87
|
-
flattened = @oa.student_details_by_id(ids.last, [:custom_fields], [:parent_guardian])
|
88
|
-
|
89
|
-
# get first 5 records with status applied with student_ids greater than the last
|
90
|
-
# two records (which should return last six students) - but response is limited to 5
|
91
|
-
# updated after 5th of Nov 2016
|
92
|
-
custom = @oa.students_query('applied', ids[-7] , '2016-11-05', 5)
|
93
|
-
|
94
|
-
|
95
|
-
# get students with applied and enrolled status, flatten no fields,
|
96
|
-
# remove the parent_guardian (duplicate) info,
|
97
|
-
# move into the xlsx file the following data: studnet id and student name
|
98
|
-
# parent address (line 1) and country, and no payment info
|
99
|
-
csv = @oa.students_as_csv_by_status( 'applied', nil, [:parent_guardian],
|
100
|
-
[:id, :name], {keys: [:address, :country]}, nil )
|
101
|
-
#
|
102
|
-
@oa.send_data_to_remote_server( csv, ENV['REMOTE_HOSTNAME'],
|
103
|
-
ENV['REMOTE_USERNAME'], "#{ENV['REMOTE_PATH_FILE']}.csv", ENV['REMOTE_PERMISSIONS'])
|
104
|
-
# save csv string as a file locally
|
105
|
-
open('test_file.csv', 'w') { |f| f.puts csv }
|
106
|
-
|
107
|
-
# DISABLED UNTIL AXLSX works with RubyZip 1.2.1
|
108
|
-
#
|
109
|
-
# # get students with applied and enrolled status, flatten the custom_fields,
|
110
|
-
# # remove the parent_guardian (duplicate) info,
|
111
|
-
# # move into the xlsx file the following data: studnet id and student name
|
112
|
-
# # parent address (line 1) and country, and the oldest three payment amounts & dates
|
113
|
-
# xlsx = @oa.students_as_xlsx_by_status(['applied','accepted'], [:custom_fields],
|
114
|
-
# [:parent_guardian], [:id, :name],
|
115
|
-
# {count: 2, keys: [:address, :country]},
|
116
|
-
# {count: , order: :oldest, keys: [:amount, :date]})
|
117
|
-
# #
|
118
|
-
# @oa.send_data_to_remote_server( xlsx, ENV['REMOTE_HOSTNAME'],
|
119
|
-
# ENV['REMOTE_USERNAME'], "#{ENV['REMOTE_PATH_FILE']}.xlsx", ENV['REMOTE_PERMISSIONS'])
|
120
|
-
# # save as a xlsx file locally
|
121
|
-
# xlsx.serialize('test_file.xlsx')
|
122
|
-
|
123
|
-
```
|