openapply 0.2.8 → 0.2.9
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/Gemfile +2 -0
- data/Gemfile.lock +9 -1
- data/README.md +8 -9
- data/lib/openapply/client.rb +15 -6
- data/lib/openapply/{convert.rb → convert_to_array.rb} +15 -177
- data/lib/openapply/convert_to_csv.rb +59 -0
- data/lib/openapply/convert_to_xlsx.rb +80 -0
- data/lib/openapply/send_to_remote.rb +61 -0
- data/lib/openapply/version.rb +1 -1
- data/openapply.gemspec +4 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0be02e1d15d91a8728fd5976a12bf17b0891c659646cba982ad30ee4eb19733
|
4
|
+
data.tar.gz: f4260bbd1314883afee1986b1123090cd29c20b93292f423789f0b8f69aba14b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e2e549759e97d3c07ce54de63f74c57a2f141f865031789521caf117adc7c844c6335c982f71b177671ef2134f2906f52a4ba16423bae0a03672f8fc66b053
|
7
|
+
data.tar.gz: ac1d72e8f5f1a264d276bd41c950a5108517bc36af448b7d3b8462083d696cc4fdd301ce1e3741aa179aae5df5cbc81c73581367e84fcbfbb848dfed99dc655b
|
data/Gemfile
CHANGED
@@ -7,6 +7,8 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
|
7
7
|
# ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
|
8
8
|
|
9
9
|
# https://github.com/randym/axlsx/issues/501
|
10
|
+
# https://github.com/straydogstudio/axlsx_rails/issues/77
|
11
|
+
# gem 'axlsx', "2.1.0.pre", git: 'https://github.com/randym/axlsx', branch: 'master'
|
10
12
|
# gem 'axlsx', git: 'https://github.com/randym/axlsx', branch: 'master'
|
11
13
|
# gem 'axlsx', git: 'https://github.com/randym/axlsx.git', ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
|
12
14
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
openapply (0.2.
|
4
|
+
openapply (0.2.9)
|
5
5
|
httparty (~> 0.15)
|
6
6
|
json (~> 2.1)
|
7
7
|
net-scp (~> 1.2)
|
@@ -22,15 +22,21 @@ GEM
|
|
22
22
|
multi_xml (>= 0.5.2)
|
23
23
|
json (2.1.0)
|
24
24
|
method_source (0.9.0)
|
25
|
+
mini_portile2 (2.3.0)
|
25
26
|
multi_xml (0.6.0)
|
26
27
|
net-scp (1.2.1)
|
27
28
|
net-ssh (>= 2.6.5)
|
28
29
|
net-ssh (4.2.0)
|
30
|
+
nokogiri (1.8.1)
|
31
|
+
mini_portile2 (~> 2.3.0)
|
29
32
|
pry (0.11.3)
|
30
33
|
coderay (~> 1.1.0)
|
31
34
|
method_source (~> 0.9.0)
|
32
35
|
public_suffix (3.0.1)
|
33
36
|
rake (10.5.0)
|
37
|
+
roo (2.7.1)
|
38
|
+
nokogiri (~> 1)
|
39
|
+
rubyzip (~> 1.1, < 2.0.0)
|
34
40
|
rspec (3.7.0)
|
35
41
|
rspec-core (~> 3.7.0)
|
36
42
|
rspec-expectations (~> 3.7.0)
|
@@ -44,6 +50,7 @@ GEM
|
|
44
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
45
51
|
rspec-support (~> 3.7.0)
|
46
52
|
rspec-support (3.7.0)
|
53
|
+
rubyzip (1.2.1)
|
47
54
|
safe_yaml (1.0.4)
|
48
55
|
simplecov (0.15.1)
|
49
56
|
docile (~> 1.1.0)
|
@@ -63,6 +70,7 @@ DEPENDENCIES
|
|
63
70
|
openapply!
|
64
71
|
pry (~> 0.11)
|
65
72
|
rake (~> 10.0)
|
73
|
+
roo (~> 2.7)
|
66
74
|
rspec (~> 3.7)
|
67
75
|
simplecov (~> 0.15)
|
68
76
|
webmock (~> 3.1)
|
data/README.md
CHANGED
@@ -5,24 +5,23 @@ This gem allows ruby access to the OpenApply API v1 - and supports the GET featu
|
|
5
5
|
|
6
6
|
### Still TODO
|
7
7
|
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
8
|
+
* allow flattening to work with arrays?
|
9
|
+
* allow flattening and reject to work at 2 levels of depth?
|
10
|
+
* make tests for scp / ssh (at least data type conversions)?
|
11
11
|
* write PUTS methods - *currently api only allows status update*
|
12
12
|
* write a recursive custom query - when results are more than one page
|
13
|
-
*
|
13
|
+
* allow flattening and reject to work at any depth (with recursion)?
|
14
14
|
* speed up response when returning large number of records? - **looks like API**
|
15
15
|
|
16
16
|
|
17
17
|
### CHANGE LOG
|
18
18
|
|
19
|
-
* **v0.2.9** - compatible with 0.2.x - 2017-12
|
20
|
-
-
|
21
|
-
-
|
22
|
-
- allow flattening and reject to work at any depth (with recursion?)
|
19
|
+
* **v0.2.9** - compatible with 0.2.x - 2017-12-13 *(https://github.com/straydogstudio/axlsx_rails/issues/77)*
|
20
|
+
- separated convert (& its dependencies) into separate modules that can be loaded on need in the next version (0.3.x)
|
21
|
+
- hash to array now handles both student_details and student_summaries (this also allows conversion then to csv)
|
23
22
|
|
24
23
|
* **v0.2.8** - compatible with 0.2.x - 2017-12-11 *(https://github.com/randym/axlsx/issues/234)*
|
25
|
-
- axlsx - passes tests - but won't
|
24
|
+
- axlsx - passes tests - but won't properly install inside another project (even using gem install ./openapply-0.2.7) - will look for a solution
|
26
25
|
|
27
26
|
* **v0.2.7** - compatible with 0.2.x - 2017-12-10
|
28
27
|
- safely re-enabled axlsx by using the master branch and upgradeing rubyzip
|
data/lib/openapply/client.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
|
2
|
+
require "openapply/convert_to_array"
|
3
|
+
# require "openapply/convert_to_xlsx"
|
4
|
+
require "openapply/convert_to_csv"
|
5
|
+
require "openapply/send_to_remote"
|
1
6
|
require "openapply/get_students"
|
2
7
|
require "openapply/get_student"
|
3
|
-
require "openapply/convert"
|
4
|
-
require "openapply/client"
|
8
|
+
# require "openapply/convert"
|
9
|
+
# require "openapply/client"
|
5
10
|
require "openapply/put"
|
6
11
|
require 'httparty'
|
7
12
|
|
@@ -14,12 +19,16 @@ module Openapply
|
|
14
19
|
|
15
20
|
# PUT api calls
|
16
21
|
include Put
|
17
|
-
|
18
22
|
# GET api calls
|
19
23
|
include Get
|
20
|
-
|
21
24
|
# Convert student data to various formats
|
22
|
-
include
|
25
|
+
include ConvertToArray
|
26
|
+
# AXLSX files
|
27
|
+
include ConvertToCsv
|
28
|
+
# AXLSX files
|
29
|
+
# include ConvertToXlsx
|
30
|
+
# Send To Remote ssh
|
31
|
+
include SendToRemote
|
23
32
|
|
24
33
|
# Library for API calls to OpenApply
|
25
34
|
include HTTParty
|
@@ -56,7 +65,7 @@ module Openapply
|
|
56
65
|
# Defines and makes visible the maximum records OpenApply should return
|
57
66
|
# (code default is 50 - OA default is 10 - doc says 100)
|
58
67
|
def api_records
|
59
|
-
ENV['
|
68
|
+
ENV['OA_RECORD_COUNT'] || '50'
|
60
69
|
end
|
61
70
|
|
62
71
|
# Does the actual api call to OpenApply & handles API timeouts gracefully
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'csv'
|
1
|
+
# require 'csv'
|
2
2
|
# require 'axlsx'
|
3
3
|
require 'net/scp'
|
4
4
|
require 'net/ssh'
|
@@ -6,7 +6,8 @@ require 'net/ssh'
|
|
6
6
|
# CODE THAT TRANSFORMS STUDENT DATA
|
7
7
|
###################################
|
8
8
|
|
9
|
-
module
|
9
|
+
module ConvertToArray
|
10
|
+
|
10
11
|
|
11
12
|
# Queries by status to get a list of students details of a given status
|
12
13
|
# and converts the result to an array with headers (based on keys sent)
|
@@ -45,122 +46,6 @@ module Convert
|
|
45
46
|
|
46
47
|
|
47
48
|
|
48
|
-
# CSV CODE
|
49
|
-
##########
|
50
|
-
|
51
|
-
# Queries by status to get a list of students details of a given status
|
52
|
-
# and converts the result to a CSV string with headers (based on keys sent)
|
53
|
-
#
|
54
|
-
# ==== Attributes
|
55
|
-
# * +status+ - hash to convert to an array
|
56
|
-
# * +flatten_keys+ - an array of keys to bring to the top level
|
57
|
-
# (with this key prepened) -- default (blank does nothing)
|
58
|
-
# * +reject_keys+ - an array of keys to remove from the data -- default (blank does nothing)
|
59
|
-
# * +student_keys+ - [:id, :name] - include student record keys
|
60
|
-
# * +guardian_info+ - include guardian record info {count: 2, keys: [:id, :name]}
|
61
|
-
# * +payment_info+ - include payment info {count: 2, order: :newest, keys: [:date, :amount]}
|
62
|
-
# * guardian & payment info options:
|
63
|
-
# count: 2 -- how many parent or payment records to return)
|
64
|
-
# keys: [:id, :date] -- an array of keys of data to return
|
65
|
-
# order: :newest -- the order to return payments :newest (most recent first - default) or :oldest
|
66
|
-
def students_as_csv_by_status( status,
|
67
|
-
flatten_keys=[], reject_keys=[],
|
68
|
-
student_keys=[],
|
69
|
-
guardian_info={}, payment_info={})
|
70
|
-
#
|
71
|
-
check = check_details_keys_validity(flatten_keys, reject_keys)
|
72
|
-
return check unless check.nil? # or check[:error].nil?
|
73
|
-
# check = check_header_keys_validity(student_keys, guardian_info, payment_info)
|
74
|
-
# return check unless check.nil?
|
75
|
-
#
|
76
|
-
students_array = students_as_array_by_status( status,
|
77
|
-
flatten_keys, reject_keys,
|
78
|
-
student_keys, guardian_info, payment_info )
|
79
|
-
#
|
80
|
-
return students_array if students_array.is_a? Hash
|
81
|
-
#
|
82
|
-
student_csv_txt = students_array_to_csv( students_array )
|
83
|
-
end
|
84
|
-
alias_method :students_as_csv_by_statuses, :students_as_csv_by_status
|
85
|
-
|
86
|
-
# Given an array convert to CSV string
|
87
|
-
#
|
88
|
-
# ==== Attributes
|
89
|
-
# +array+ - expects a hash of students_details (should be flattened to use custom fields)
|
90
|
-
def students_array_to_csv(array)
|
91
|
-
return "" if array.nil? or array.empty?
|
92
|
-
# https://stackoverflow.com/questions/4822422/output-array-to-csv-in-ruby
|
93
|
-
csv_string = CSV.generate do |csv|
|
94
|
-
array.each do |row|
|
95
|
-
csv << row
|
96
|
-
end
|
97
|
-
end
|
98
|
-
return csv_string
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
# # XLSX CODE
|
103
|
-
# ###########
|
104
|
-
#
|
105
|
-
#
|
106
|
-
# # Queries by status to get a list of students details of a given status
|
107
|
-
# # and converts the result to a XLSX Object (Axlsx::Package) with headers
|
108
|
-
# # (based on keys sent)
|
109
|
-
# #
|
110
|
-
# # ==== Attributes
|
111
|
-
# # * +status+ - hash to convert to an array
|
112
|
-
# # * +flatten_keys+ - an array of keys to bring to the top level
|
113
|
-
# # (with this key prepened) -- default (blank does nothing)
|
114
|
-
# # * +reject_keys+ - an array of keys to remove from the data -- default (blank does nothing)
|
115
|
-
# # * +student_keys+ - [:id, :name] - include student record keys
|
116
|
-
# # * +guardian_info+ - include guardian record info {count: 2, keys: [:id, :name]}
|
117
|
-
# # * +payment_info+ - include payment info {count: 2, order: :newest, keys: [:date, :amount]}
|
118
|
-
# # * guardian & payment info options:
|
119
|
-
# # count: 2 -- how many parent or payment records to return)
|
120
|
-
# # keys: [:id, :date] -- an array of keys of data to return
|
121
|
-
# # order: :newest -- the order to return payments :newest (most recent first - default) or :oldest
|
122
|
-
# def students_as_xlsx_by_status( status,
|
123
|
-
# flatten_keys=[], reject_keys=[],
|
124
|
-
# student_keys=[],
|
125
|
-
# guardian_info={}, payment_info={})
|
126
|
-
# #
|
127
|
-
# check = check_details_keys_validity(flatten_keys, reject_keys)
|
128
|
-
# return check unless check.nil? # or check[:error].nil?
|
129
|
-
# # check = check_header_keys_validity(student_keys, guardian_info, payment_info)
|
130
|
-
# # return check unless check.nil?
|
131
|
-
# #
|
132
|
-
# students_array = students_as_array_by_status( status,
|
133
|
-
# flatten_keys, reject_keys,
|
134
|
-
# student_keys, guardian_info, payment_info )
|
135
|
-
# #
|
136
|
-
# return students_array if students_array.is_a? Hash
|
137
|
-
# #
|
138
|
-
# students_xlsx = students_array_to_xlsx( students_array )
|
139
|
-
#
|
140
|
-
# # example how to save the xlsx object as a file
|
141
|
-
# # students_xlsx.serialize("spec/data/xlsx/students_from_oa.xlsx")
|
142
|
-
#
|
143
|
-
# return students_xlsx
|
144
|
-
# end
|
145
|
-
# alias_method :students_as_xlsx_by_statuses, :students_as_xlsx_by_status
|
146
|
-
#
|
147
|
-
|
148
|
-
# # Given an array convert to XLSX Object (Axlsx::Package)
|
149
|
-
# #
|
150
|
-
# # ==== Attributes
|
151
|
-
# # +array+ - expects a hash of students_details (should be flattened to use custom fields)
|
152
|
-
# def students_array_to_xlsx(student_array)
|
153
|
-
# xlsx_obj = Axlsx::Package.new do |p|
|
154
|
-
# p.workbook.add_worksheet(:name => "Students from OpenApply") do |sheet|
|
155
|
-
# student_array.each{ |r| sheet.add_row r }
|
156
|
-
# end
|
157
|
-
# # to save the xlsx object as a file
|
158
|
-
# # p.serialize("spec/data/xlsx/students_from_oa.xlsx")
|
159
|
-
# end
|
160
|
-
# return xlsx_obj
|
161
|
-
# end
|
162
|
-
|
163
|
-
|
164
49
|
# ARRAY CODE
|
165
50
|
############
|
166
51
|
|
@@ -190,9 +75,18 @@ module Convert
|
|
190
75
|
# next if student.nil? or student.empty? or
|
191
76
|
# student[:record].nil? or student[:record].empty?
|
192
77
|
|
193
|
-
|
194
|
-
|
195
|
-
|
78
|
+
# when student summary data
|
79
|
+
if student[:record].nil?
|
80
|
+
kid_record = student
|
81
|
+
guardians = []
|
82
|
+
payments = []
|
83
|
+
end
|
84
|
+
# when student detailed data
|
85
|
+
if student[:record]
|
86
|
+
kid_record = student[:record]
|
87
|
+
guardians = student[:guardians]
|
88
|
+
payments = student[:payments]
|
89
|
+
end
|
196
90
|
|
197
91
|
# inject student record info into the array
|
198
92
|
student_keys.each{ |key| row << kid_record[key] }
|
@@ -283,62 +177,6 @@ module Convert
|
|
283
177
|
return headers
|
284
178
|
end
|
285
179
|
|
286
|
-
# XFER CODE
|
287
|
-
###########
|
288
|
-
|
289
|
-
# Send a string to convert to a file on a remote server
|
290
|
-
# setup using ssh keys - not sure how to test - use at own risk
|
291
|
-
#
|
292
|
-
# === Attributes
|
293
|
-
# * +data+ - object to be converted to a file on a remote system --
|
294
|
-
# object can be a CSV String, Axlsx::Package or File object to be transfered
|
295
|
-
# * +srv_hostname+ - fqdn or IP address of the remote host
|
296
|
-
# * +srv_hostname+ - username to access the remote host
|
297
|
-
# * +srv_path_file+ - full path and file name of the file on the remote host
|
298
|
-
# * +file_permissions+ - permissions to make the file on the remote host (default is: 0750)
|
299
|
-
# * +options+ - allow ssh start options to be passed in
|
300
|
-
def send_data_to_remote_server( data, srv_hostname, srv_username,
|
301
|
-
srv_path_file, srv_file_permissions="0750",
|
302
|
-
ssl_options={}
|
303
|
-
)
|
304
|
-
# be sure its a file type that can be sent
|
305
|
-
return "Unrecognized Object" unless known_transfer_object?(data)
|
306
|
-
|
307
|
-
# Prep data as necessary for scp
|
308
|
-
# https://www.safaribooksonline.com/library/view/ruby-cookbook/0596523696/ch06s15.html
|
309
|
-
# convert the string to a stringio object (which can act as a file)
|
310
|
-
# xfer = data.to_stream() if data.is_a? Axlsx::Package
|
311
|
-
xfer = data if data.is_a? StringIO
|
312
|
-
xfer = StringIO.new( data ) if data.is_a? String
|
313
|
-
xfer = data if data.is_a? File
|
314
|
-
|
315
|
-
# http://www.rubydoc.info/github/delano/net-scp/Net/SCP
|
316
|
-
# send the stringio object to the remote host via scp
|
317
|
-
Net::SCP.start(srv_hostname, srv_username, ssl_options) do |scp|
|
318
|
-
# asynchronous upload; call returns immediately
|
319
|
-
channel = scp.upload( xfer, srv_path_file )
|
320
|
-
channel.wait
|
321
|
-
end
|
322
|
-
# ensure file has desired permissions (via remote ssh command)
|
323
|
-
Net::SSH.start(srv_hostname, srv_username, ssl_options) do |ssh|
|
324
|
-
# Capture all stderr and stdout output from a remote process
|
325
|
-
output = ssh.exec!("chmod #{srv_file_permissions} #{srv_path_file}")
|
326
|
-
end
|
327
|
-
end
|
328
|
-
alias_method :send_string_to_server_file, :send_data_to_remote_server
|
329
|
-
|
330
|
-
# Check that the data to transfer is of a known data type
|
331
|
-
#
|
332
|
-
# === Attributes
|
333
|
-
# * +data+ - is it an Axlsx::Package, Sting, StringIO or a File class?
|
334
|
-
def known_transfer_object?( data )
|
335
|
-
# return true if data.is_a? Axlsx::Package
|
336
|
-
return true if data.is_a? StringIO
|
337
|
-
return true if data.is_a? String
|
338
|
-
return true if data.is_a? File
|
339
|
-
return false
|
340
|
-
end
|
341
|
-
|
342
180
|
# Check header info before processing
|
343
181
|
#
|
344
182
|
# === Attributes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
# CODE THAT TRANSFORMS STUDENT DATA
|
4
|
+
###################################
|
5
|
+
|
6
|
+
module ConvertToCsv
|
7
|
+
|
8
|
+
|
9
|
+
# Queries by status to get a list of students details of a given status
|
10
|
+
# and converts the result to a CSV string with headers (based on keys sent)
|
11
|
+
#
|
12
|
+
# ==== Attributes
|
13
|
+
# * +status+ - hash to convert to an array
|
14
|
+
# * +flatten_keys+ - an array of keys to bring to the top level
|
15
|
+
# (with this key prepened) -- default (blank does nothing)
|
16
|
+
# * +reject_keys+ - an array of keys to remove from the data -- default (blank does nothing)
|
17
|
+
# * +student_keys+ - [:id, :name] - include student record keys
|
18
|
+
# * +guardian_info+ - include guardian record info {count: 2, keys: [:id, :name]}
|
19
|
+
# * +payment_info+ - include payment info {count: 2, order: :newest, keys: [:date, :amount]}
|
20
|
+
# * guardian & payment info options:
|
21
|
+
# count: 2 -- how many parent or payment records to return)
|
22
|
+
# keys: [:id, :date] -- an array of keys of data to return
|
23
|
+
# order: :newest -- the order to return payments :newest (most recent first - default) or :oldest
|
24
|
+
def students_as_csv_by_status( status,
|
25
|
+
flatten_keys=[], reject_keys=[],
|
26
|
+
student_keys=[],
|
27
|
+
guardian_info={}, payment_info={})
|
28
|
+
#
|
29
|
+
check = check_details_keys_validity(flatten_keys, reject_keys)
|
30
|
+
return check unless check.nil? # or check[:error].nil?
|
31
|
+
# check = check_header_keys_validity(student_keys, guardian_info, payment_info)
|
32
|
+
# return check unless check.nil?
|
33
|
+
#
|
34
|
+
students_array = students_as_array_by_status( status,
|
35
|
+
flatten_keys, reject_keys,
|
36
|
+
student_keys, guardian_info, payment_info )
|
37
|
+
#
|
38
|
+
return students_array if students_array.is_a? Hash
|
39
|
+
#
|
40
|
+
student_csv_txt = students_array_to_csv( students_array )
|
41
|
+
end
|
42
|
+
alias_method :students_as_csv_by_statuses, :students_as_csv_by_status
|
43
|
+
|
44
|
+
# Given an array convert to CSV string
|
45
|
+
#
|
46
|
+
# ==== Attributes
|
47
|
+
# +array+ - expects a hash of students_details (should be flattened to use custom fields)
|
48
|
+
def students_array_to_csv(array)
|
49
|
+
return "" if array.nil? or array.empty?
|
50
|
+
# https://stackoverflow.com/questions/4822422/output-array-to-csv-in-ruby
|
51
|
+
csv_string = CSV.generate do |csv|
|
52
|
+
array.each do |row|
|
53
|
+
csv << row
|
54
|
+
end
|
55
|
+
end
|
56
|
+
return csv_string
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'axlsx'
|
2
|
+
|
3
|
+
# CODE THAT TRANSFORMS STUDENT DATA INTO XLSX DATA
|
4
|
+
##################################################
|
5
|
+
|
6
|
+
module ConvertToXlsx
|
7
|
+
|
8
|
+
# XLSX CODE
|
9
|
+
###########
|
10
|
+
|
11
|
+
# Queries by status to get a list of students details of a given status
|
12
|
+
# and converts the result to a XLSX Object (Axlsx::Package) with headers
|
13
|
+
# (based on keys sent)
|
14
|
+
#
|
15
|
+
# ==== Attributes
|
16
|
+
# * +status+ - hash to convert to an array
|
17
|
+
# * +flatten_keys+ - an array of keys to bring to the top level
|
18
|
+
# (with this key prepened) -- default (blank does nothing)
|
19
|
+
# * +reject_keys+ - an array of keys to remove from the data -- default (blank does nothing)
|
20
|
+
# * +student_keys+ - [:id, :name] - include student record keys
|
21
|
+
# * +guardian_info+ - include guardian record info {count: 2, keys: [:id, :name]}
|
22
|
+
# * +payment_info+ - include payment info {count: 2, order: :newest, keys: [:date, :amount]}
|
23
|
+
# * guardian & payment info options:
|
24
|
+
# count: 2 -- how many parent or payment records to return)
|
25
|
+
# keys: [:id, :date] -- an array of keys of data to return
|
26
|
+
# order: :newest -- the order to return payments :newest (most recent first - default) or :oldest
|
27
|
+
def students_as_xlsx_by_status( status,
|
28
|
+
flatten_keys=[], reject_keys=[],
|
29
|
+
student_keys=[],
|
30
|
+
guardian_info={}, payment_info={})
|
31
|
+
#
|
32
|
+
check = check_details_keys_validity(flatten_keys, reject_keys)
|
33
|
+
return check unless check.nil? # or check[:error].nil?
|
34
|
+
# check = check_header_keys_validity(student_keys, guardian_info, payment_info)
|
35
|
+
# return check unless check.nil?
|
36
|
+
#
|
37
|
+
students_array = students_as_array_by_status( status,
|
38
|
+
flatten_keys, reject_keys,
|
39
|
+
student_keys, guardian_info, payment_info )
|
40
|
+
#
|
41
|
+
return students_array if students_array.is_a? Hash
|
42
|
+
#
|
43
|
+
students_xlsx = students_array_to_xlsx( students_array )
|
44
|
+
|
45
|
+
# example how to save the xlsx object as a file
|
46
|
+
# students_xlsx.serialize("spec/data/xlsx/students_from_oa.xlsx")
|
47
|
+
|
48
|
+
return students_xlsx
|
49
|
+
end
|
50
|
+
alias_method :students_as_xlsx_by_statuses, :students_as_xlsx_by_status
|
51
|
+
|
52
|
+
|
53
|
+
# Given an array convert to XLSX Object (Axlsx::Package)
|
54
|
+
#
|
55
|
+
# ==== Attributes
|
56
|
+
# +array+ - expects a hash of students_details (should be flattened to use custom fields)
|
57
|
+
def students_array_to_xlsx(student_array)
|
58
|
+
xlsx_obj = Axlsx::Package.new do |p|
|
59
|
+
p.workbook.add_worksheet(:name => "Students from OpenApply") do |sheet|
|
60
|
+
student_array.each{ |r| sheet.add_row r }
|
61
|
+
end
|
62
|
+
# to save the xlsx object as a file
|
63
|
+
# p.serialize("spec/data/xlsx/students_from_oa.xlsx")
|
64
|
+
end
|
65
|
+
return xlsx_obj
|
66
|
+
end
|
67
|
+
|
68
|
+
def send_xlsx_to_remote_server( data, srv_hostname, srv_username,
|
69
|
+
srv_path_file, srv_file_permissions="0750",
|
70
|
+
ssl_options={}
|
71
|
+
)
|
72
|
+
return false unless data.is_a? Axlsx::Package
|
73
|
+
xfer = data.to_stream() if data.is_a? Axlsx::Package
|
74
|
+
send_data_to_remote_server( xfer, srv_hostname, srv_username,
|
75
|
+
srv_path_file, srv_file_permissions,
|
76
|
+
ssl_options
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'net/scp'
|
2
|
+
require 'net/ssh'
|
3
|
+
|
4
|
+
# CODE THAT TRANSFORMS STUDENT DATA
|
5
|
+
###################################
|
6
|
+
|
7
|
+
module SendToRemote
|
8
|
+
|
9
|
+
# Send a string to convert to a file on a remote server
|
10
|
+
# setup using ssh keys - not sure how to test - use at own risk
|
11
|
+
#
|
12
|
+
# === Attributes
|
13
|
+
# * +data+ - object to be converted to a file on a remote system --
|
14
|
+
# object can be a CSV String, Axlsx::Package or File object to be transfered
|
15
|
+
# * +srv_hostname+ - fqdn or IP address of the remote host
|
16
|
+
# * +srv_hostname+ - username to access the remote host
|
17
|
+
# * +srv_path_file+ - full path and file name of the file on the remote host
|
18
|
+
# * +file_permissions+ - permissions to make the file on the remote host (default is: 0750)
|
19
|
+
# * +options+ - allow ssh start options to be passed in
|
20
|
+
def send_data_to_remote_server( data, srv_hostname, srv_username,
|
21
|
+
srv_path_file, srv_file_permissions="0750",
|
22
|
+
ssl_options={}
|
23
|
+
)
|
24
|
+
# be sure its a file type that can be sent
|
25
|
+
return "Unrecognized Object" unless known_transfer_object?(data)
|
26
|
+
|
27
|
+
# Prep data as necessary for scp
|
28
|
+
# https://www.safaribooksonline.com/library/view/ruby-cookbook/0596523696/ch06s15.html
|
29
|
+
# convert the string to a stringio object (which can act as a file)
|
30
|
+
|
31
|
+
xfer = data if data.is_a? StringIO
|
32
|
+
xfer = StringIO.new( data ) if data.is_a? String
|
33
|
+
xfer = data if data.is_a? File
|
34
|
+
|
35
|
+
# http://www.rubydoc.info/github/delano/net-scp/Net/SCP
|
36
|
+
# send the stringio object to the remote host via scp
|
37
|
+
Net::SCP.start(srv_hostname, srv_username, ssl_options) do |scp|
|
38
|
+
# asynchronous upload; call returns immediately
|
39
|
+
channel = scp.upload( xfer, srv_path_file )
|
40
|
+
channel.wait
|
41
|
+
end
|
42
|
+
# ensure file has desired permissions (via remote ssh command)
|
43
|
+
Net::SSH.start(srv_hostname, srv_username, ssl_options) do |ssh|
|
44
|
+
# Capture all stderr and stdout output from a remote process
|
45
|
+
output = ssh.exec!("chmod #{srv_file_permissions} #{srv_path_file}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
alias_method :send_string_to_server_file, :send_data_to_remote_server
|
49
|
+
|
50
|
+
# Check that the data to transfer is of a known data type
|
51
|
+
#
|
52
|
+
# === Attributes
|
53
|
+
# * +data+ - is it an Axlsx::Package, Sting, StringIO or a File class?
|
54
|
+
def known_transfer_object?( data )
|
55
|
+
return true if data.is_a? StringIO
|
56
|
+
return true if data.is_a? String
|
57
|
+
return true if data.is_a? File
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/openapply/version.rb
CHANGED
data/openapply.gemspec
CHANGED
@@ -44,7 +44,8 @@ Gem::Specification.new do |spec|
|
|
44
44
|
# https://github.com/straydogstudio/axlsx_rails/issues/77
|
45
45
|
# gem 'axlsx', git: 'https://github.com/randym/axlsx.git',
|
46
46
|
# ref: '776037c0fc799bb09da8c9ea47980bd3bf296874'
|
47
|
-
# spec.add_dependency 'axlsx',
|
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'
|
48
49
|
# # https://github.com/randym/axlsx/issues/234
|
49
50
|
# # spec.add_dependency 'zip-zip'
|
50
51
|
#
|
@@ -54,6 +55,8 @@ Gem::Specification.new do |spec|
|
|
54
55
|
# don't use official release - use above
|
55
56
|
# spec.add_dependency "axlsx", "2.1.0.pre"
|
56
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"
|
57
60
|
|
58
61
|
spec.add_development_dependency "simplecov", "~> 0.15"
|
59
62
|
spec.add_development_dependency "webmock" , "~> 3.1"
|
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.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -174,10 +174,13 @@ files:
|
|
174
174
|
- examples/demo/demo_site.rb
|
175
175
|
- lib/openapply.rb
|
176
176
|
- lib/openapply/client.rb
|
177
|
-
- lib/openapply/
|
177
|
+
- lib/openapply/convert_to_array.rb
|
178
|
+
- lib/openapply/convert_to_csv.rb
|
179
|
+
- lib/openapply/convert_to_xlsx.rb
|
178
180
|
- lib/openapply/get_student.rb
|
179
181
|
- lib/openapply/get_students.rb
|
180
182
|
- lib/openapply/put.rb
|
183
|
+
- lib/openapply/send_to_remote.rb
|
181
184
|
- lib/openapply/version.rb
|
182
185
|
- openapply.gemspec
|
183
186
|
homepage: https://github.com/btihen/openapply
|