openapply 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4ffbf0a9625607d27742d3d8eab1ab57802ce0f27dbfbb2ef2c5b52ec5da8d3
4
- data.tar.gz: 457741241de4a8bf32e53feb790772a96393382934d1d7808d6c7b0cb10866aa
3
+ metadata.gz: 64954bcbf3fc679a31c6bf6bd1ca661f03d592cb070ec3950c29c161f0af35da
4
+ data.tar.gz: 9d18998d1f43f23d4b95ac06f2728c740379497762c99fbb36adb33c2511ba47
5
5
  SHA512:
6
- metadata.gz: 60cd8ca6032a0f1e265eaf55e620432b8854d4e72e685235c7acaf5041a452d8506937db2da40ca038f23334a1a3b7491e0617d3df2f9bd998334c8bcbd03962
7
- data.tar.gz: 9bcf4a9a22033330c1a4f4a168b9a33afcb1dbbff07ae29c616f0bb12cca68ee8c5f2aab2558d4c5aa620b799490341b26fb5e444be255301f4ce5da8f983471
6
+ metadata.gz: e47ea0252dd955498ee453746404b76c15d35d950cd4cb01c25ebfe03275d6a331fd853fb7705c733ea64e3accb637f6d1a2f4150f292aabe4181ec91ce16119
7
+ data.tar.gz: 3326b12158e1c250e9c2598cf98de6634fefacd113c4f7d8185b8e02c60cb54da19b877c002d5a673d966b0eb37f488551e9b20d72e92c9db160b71c02b48dd7
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
3
+ # /Gemfile.lock
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ openapply (0.2.4)
5
+ httparty (~> 0.15)
6
+ json (~> 2.1)
7
+ net-scp (~> 1.2)
8
+ net-ssh (~> 4.2)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.5.2)
14
+ public_suffix (>= 2.0.2, < 4.0)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.3)
18
+ docile (1.1.5)
19
+ hashdiff (0.3.7)
20
+ httparty (0.15.6)
21
+ multi_xml (>= 0.5.2)
22
+ json (2.1.0)
23
+ multi_xml (0.6.0)
24
+ net-scp (1.2.1)
25
+ net-ssh (>= 2.6.5)
26
+ net-ssh (4.2.0)
27
+ public_suffix (3.0.1)
28
+ rake (10.5.0)
29
+ rspec (3.7.0)
30
+ rspec-core (~> 3.7.0)
31
+ rspec-expectations (~> 3.7.0)
32
+ rspec-mocks (~> 3.7.0)
33
+ rspec-core (3.7.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-expectations (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-mocks (3.7.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-support (3.7.0)
42
+ safe_yaml (1.0.4)
43
+ simplecov (0.15.1)
44
+ docile (~> 1.1.0)
45
+ json (>= 1.8, < 3)
46
+ simplecov-html (~> 0.10.0)
47
+ simplecov-html (0.10.2)
48
+ webmock (3.1.1)
49
+ addressable (>= 2.3.6)
50
+ crack (>= 0.3.2)
51
+ hashdiff
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.15)
58
+ openapply!
59
+ rake (~> 10.0)
60
+ rspec (~> 3.7)
61
+ simplecov (~> 0.15)
62
+ webmock (~> 3.1)
63
+
64
+ BUNDLED WITH
65
+ 1.16.0
data/README.md CHANGED
@@ -14,6 +14,9 @@ This gem allows ruby access to the OpenApply API v1 - and supports the GET featu
14
14
 
15
15
  ### CHANGE LOG
16
16
 
17
+ * **v0.2.4** - compatible with 0.2.x - 2017-11-23
18
+ - rubyzip 1.1.7 - has a serious security flaw - Axlsx and Roo cannot use rubyzip 1.2.1 -- YET (which doesn't have the flaw) - so xlsx features are disabled until rubyzip 1.2.1 can be used by both roo and axlsx. **CSV** conversions are still usable
19
+
17
20
  * **v0.2.3** - compatible with 0.2.x - 2017-11-23
18
21
  - allow detailed queries *(_by_id & _by_status)* to skip payment information
19
22
  - allow array, csv & xlsx transformations to skip payment queries (when no payment_info requested)
@@ -159,12 +162,13 @@ csv_string=@oa.students_as_csv_by_statuses(['applied','enrolled'],[:custom_field
159
162
  @oa.send_data_to_remote_server(csv_string, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
160
163
 
161
164
  # Create XLSX file
162
- @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]} )
163
- # multiple status into
164
- 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]} )
165
- #
166
- # send XLSX to a remote server as a file - using ssh-keys
167
- @oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.xlsx', '0750')
165
+ # XLSX features DISABLED UNTIL AXLSX can work with RubyZip 1.2.1
166
+ # @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]} )
167
+ # # multiple status into
168
+ # 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]} )
169
+ # #
170
+ # # send XLSX to a remote server as a file - using ssh-keys
171
+ # @oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.xlsx', '0750')
168
172
  ```
169
173
 
170
174
  #### INDIVIDUAL STUDENT QUERIES
@@ -240,14 +244,16 @@ csv=@oa.students_as_csv_by_status('applied',[:custom_fields], [:parent_guardian]
240
244
  # attributes: csv_string, srv_hostname, srv_username, srv_path_file, file_permissions(0750 - default if not specified)
241
245
  @oa.send_data_to_remote_server(csv, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
242
246
  #
243
- # Create a XLSX package
244
- @oa.students_as_xlsx_by_status('applied', nil, nil, [:id, :name], nil, {count: 2, order: :newest, keys: [:date, :amount]} )
245
- # all options
246
- 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]} )
247
+ # # Create a XLSX package
248
+ # disabled until axlsx works with rubyzip 1.2.1
247
249
  #
248
- # send CSV to a remote server as a file - using ssh-keys
249
- # attributes: csv_string, srv_hostname, srv_username, srv_path_file, file_permissions(0750 - default if not specified)
250
- @oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
250
+ # @oa.students_as_xlsx_by_status('applied', nil, nil, [:id, :name], nil, {count: 2, order: :newest, keys: [:date, :amount]} )
251
+ # # all options
252
+ # 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]} )
253
+ # #
254
+ # # send CSV to a remote server as a file - using ssh-keys
255
+ # # attributes: csv_string, srv_hostname, srv_username, srv_path_file, file_permissions(0750 - default if not specified)
256
+ # @oa.send_data_to_remote_server(xlsx, 'hostname.domain.name', 'myusername', '/home/myusername/xfer/myexport.csv', '0750')
251
257
  ```
252
258
 
253
259
  #### CUSTOM GROUP QUERIES - summary data
@@ -3,15 +3,22 @@ GEM
3
3
  specs:
4
4
  httparty (0.15.6)
5
5
  multi_xml (>= 0.5.2)
6
+ json (2.1.0)
6
7
  multi_xml (0.6.0)
7
- openapply (0.1.0)
8
+ net-scp (1.2.1)
9
+ net-ssh (>= 2.6.5)
10
+ net-ssh (4.2.0)
11
+ openapply (0.2.4)
8
12
  httparty (~> 0.15)
13
+ json (~> 2.1)
14
+ net-scp (~> 1.2)
15
+ net-ssh (~> 4.2)
9
16
 
10
17
  PLATFORMS
11
18
  ruby
12
19
 
13
20
  DEPENDENCIES
14
- openapply (~> 0.1)
21
+ openapply (~> 0.2)
15
22
 
16
23
  BUNDLED WITH
17
- 1.15.4
24
+ 1.16.0
@@ -4,13 +4,59 @@ In the terminal:
4
4
 
5
5
  ```bash
6
6
  gem install openapply
7
+ # or better still
8
+ bundle install
7
9
 
8
- # irb
9
- # or
10
+ irb
11
+ # or better still
10
12
  pry
11
13
  ```
14
+ Once in the REPL - follow the below instructions
12
15
 
13
- and run this code (or play )
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
14
60
  ```ruby
15
61
  require 'openapply'
16
62
 
@@ -58,57 +104,20 @@ csv = @oa.students_as_csv_by_status( 'applied', nil, [:parent_guardian],
58
104
  # save csv string as a file locally
59
105
  open('test_file.csv', 'w') { |f| f.puts csv }
60
106
 
61
- # get students with applied and enrolled status, flatten the custom_fields,
62
- # remove the parent_guardian (duplicate) info,
63
- # move into the xlsx file the following data: studnet id and student name
64
- # parent address (line 1) and country, and the oldest three payment amounts & dates
65
- xlsx = @oa.students_as_xlsx_by_status(['applied','accepted'], [:custom_fields],
66
- [:parent_guardian], [:id, :name],
67
- {count: 2, keys: [:address, :country]},
68
- {count: , order: :oldest, keys: [:amount, :date]})
107
+ # DISABLED UNTIL AXLSX works with RubyZip 1.2.1
69
108
  #
70
- @oa.send_data_to_remote_server( xlsx, ENV['REMOTE_HOSTNAME'],
71
- ENV['REMOTE_USERNAME'], "#{ENV['REMOTE_PATH_FILE']}.xlsx", ENV['REMOTE_PERMISSIONS'])
72
- # save as a xlsx file locally
73
- xlsx.serialize('test_file.xlsx')
74
-
75
- ```
76
-
77
- * or More advanced - multiple OA sites
78
- ```ruby
79
-
80
- # require 'pp'
81
- require 'openapply'
82
- require_relative './demo_site'
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')
83
122
 
84
- # use a class override in order to interact with multiple oa sites
85
- # or extend functionality
86
- @mine = MySite.new()
87
-
88
-
89
- # get students with applied and enrolled status, flatten no fields,
90
- # remove the parent_guardian (duplicate) info,
91
- # move into the xlsx file the following data: studnet id and student name
92
- # parent address (line 1) and country, and no payment info
93
- @mine.records_as_csv_to_file( 'applied', nil, [:parent_guardian], [:id, :name],
94
- {keys: [:address, :country]}, nil , 'test.csv' )
95
-
96
- @mine.records_as_csv_to_server( 'applied', nil, [:parent_guardian], [:id, :name],
97
- {keys: [:address, :country]}, nil )
98
-
99
- # get students with applied and enrolled status, flatten the custom_fields,
100
- # remove the parent_guardian (duplicate) info,
101
- # move into the xlsx file the following data: studnet id and student name
102
- # parent address (line 1) and country, and the oldest three payment amounts & dates
103
- @mine.records_as_xlsx_to_file( ['applied','enrolled'], [:custom_fields],
104
- [:parent_guardian], [:id, :name],
105
- {count: 2, keys: [:address, :country]},
106
- {count: 3, order: :oldest, keys: [:amount, :date]}, 'test.xlsx')
107
-
108
- @mine.records_as_xlsx_to_server(['applied','enrolled'], [:custom_fields],
109
- [:parent_guardian], [:id, :name],
110
- {count: 2, keys: [:address, :country]},
111
- {count: 3, order: :newest, keys: [:amount, :date]})
112
-
113
- # use cron or other similar tools to automate these processes
114
123
  ```
@@ -1,18 +1,49 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'httparty'
4
+ require 'openapply'
4
5
 
5
6
  class MySite < Openapply::Client
6
7
  include HTTParty
7
8
 
8
- # add customized site info
9
- # (say you need to use both: demo.openapply.com and my.openapply.com) --
10
- # this class defines my.openapply.com and its special needs
11
- localized_url = ENV['MY_BASE_URI']
12
- base_uri localized_url
9
+ # Defines OpenApply domain name from ENV-VARS
10
+ API_URL = ENV['MY_API_BASE_URI']
13
11
 
12
+ # Defines the OpenApply path from ENV-VARS - default is 5 seconds
13
+ API_TIMEOUT = (ENV['MY_API_TIMEOUT'].to_i || 5)
14
+
15
+ base_uri API_URL
16
+ default_timeout API_TIMEOUT
17
+
18
+ # Makes OpenApply domain name visible:
19
+ def api_url
20
+ API_URL
21
+ end
22
+
23
+ # make OpenApply timeout visible
24
+ def api_timeout
25
+ API_TIMEOUT
26
+ end
27
+
28
+ # Defines & makes visible OpenApply secret access key with ENV-VARS
14
29
  def api_key
15
- ENV['MY_AUTH_TOKEN']
30
+ ENV['MY_API_AUTH_TOKEN']
31
+ end
32
+
33
+ # Defines and makes visib le the OpenApply path with ENV-VARS
34
+ def api_path
35
+ ENV['MY_API_PATH'] || "/api/v1/students/"
36
+ end
37
+
38
+ # Defines and makes visible the maximum records OpenApply should return
39
+ # (code default is 50 - OA default is 10 - doc says 100)
40
+ def api_records
41
+ ENV['MY_API_RECORDS'] || '50'
42
+ end
43
+
44
+ def initialize
45
+ @my_flatten_keys = [:custom_fields]
46
+ @my_reject_keys = [:parent_guardian]
16
47
  end
17
48
 
18
49
  # defines remote host to recieve openapply data
@@ -40,21 +71,22 @@ class MySite < Openapply::Client
40
71
  "#{REMOTE_PATH_FILE}.csv", REMOTE_PERMISSIONS)
41
72
  end
42
73
 
43
- def records_as_xlsx_to_file( status, flatten_keys=[],
44
- reject_keys=[], student_keys=[],
45
- guardian_info={}, payment_info={}, file )
46
- data = students_as_xlsx_by_status( status, flatten_keys, reject_keys,
47
- student_keys, guardian_info, payment_info)
48
- data.serialize(file)
49
- end
50
-
51
- def records_as_xlsx_to_server( status, flatten_keys=[],
52
- reject_keys=[], student_keys=[],
53
- guardian_info={}, payment_info={})
54
- data = students_as_xlsx_by_status( status, flatten_keys, reject_keys,
55
- student_keys, guardian_info, payment_info)
56
- send_data_to_remote_server( data, REMOTE_HOSTNAME, REMOTE_USERNAME,
57
- "#{REMOTE_PATH_FILE}.xlsx", REMOTE_PERMISSIONS)
58
- end
74
+ # DISABLED UNTIL AXLSX works with rubyzip 1.2.1 or later
75
+ # def records_as_xlsx_to_file( status, flatten_keys=[],
76
+ # reject_keys=[], student_keys=[],
77
+ # guardian_info={}, payment_info={}, file )
78
+ # data = students_as_xlsx_by_status( status, flatten_keys, reject_keys,
79
+ # student_keys, guardian_info, payment_info)
80
+ # data.serialize(file)
81
+ # end
82
+ #
83
+ # def records_as_xlsx_to_server( status, flatten_keys=[],
84
+ # reject_keys=[], student_keys=[],
85
+ # guardian_info={}, payment_info={})
86
+ # data = students_as_xlsx_by_status( status, flatten_keys, reject_keys,
87
+ # student_keys, guardian_info, payment_info)
88
+ # send_data_to_remote_server( data, REMOTE_HOSTNAME, REMOTE_USERNAME,
89
+ # "#{REMOTE_PATH_FILE}.xlsx", REMOTE_PERMISSIONS)
90
+ # end
59
91
 
60
92
  end
@@ -39,10 +39,9 @@ module Openapply
39
39
  end
40
40
 
41
41
  # make OpenApply timeout visible
42
- def api_reply_count
42
+ def api_timeout
43
43
  API_TIMEOUT
44
44
  end
45
- alias_method :api_timeout, :api_reply_count
46
45
 
47
46
  # Defines & makes visible OpenApply secret access key with ENV-VARS
48
47
  def api_key
@@ -1,5 +1,5 @@
1
1
  require 'csv'
2
- require 'axlsx'
2
+ # require 'axlsx'
3
3
  require 'net/scp'
4
4
  require 'net/ssh'
5
5
 
@@ -99,66 +99,66 @@ module Convert
99
99
  end
100
100
 
101
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)
102
+ # # XLSX CODE
103
+ # ###########
109
104
  #
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
105
  #
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
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
162
 
163
163
 
164
164
  # ARRAY CODE
@@ -147,22 +147,56 @@ module Get
147
147
  # skip loop if this key matches a value to remove
148
148
  next if reject_keys.include? key
149
149
 
150
- # put data back into hash if not to be flattened
151
- answer[key] = clean_data(val) unless flatten_keys.include? key
152
-
153
- # if current key matches a flatten value & HAS nested data values
154
- # then bring nested data to top level
155
- val.each do |k,v|
156
- # remove any nested values if they match a reject_key
157
- next if reject_keys.include? k
158
-
159
- # (prepend flatten_key_to_current_key to prevent conflicts)
160
- new_key = "#{key.to_s}_#{k.to_s}".to_sym
161
- # clean the data and add back to to top level with a new key
162
- answer[new_key] = clean_data(v)
163
- end if flatten_keys.include?(key) and
164
- not val.empty?
150
+ if flatten_keys.include? key
151
+ answer.merge!( flatten_key_vals(key, val, flatten_keys, reject_keys) )
152
+ else
153
+ # put data back into hash if not to be flattened
154
+ answer[key] = clean_data(val) unless flatten_keys.include? key
155
+ end
165
156
  end
157
+
158
+ return answer
159
+ end
160
+
161
+
162
+
163
+ def flatten_key_vals(key, val, flatten_keys, reject_keys)
164
+ if val.is_a? Array
165
+ return flatten_array_vals(key, val, flatten_keys, reject_keys)
166
+
167
+ elsif val.is_a? Hash
168
+ return flatten_hash_vals(key, val, flatten_keys, reject_keys)
169
+
170
+ else
171
+ return {}
172
+ end
173
+
174
+ end
175
+
176
+
177
+
178
+ def flatten_array_vals(key, val, flatten_keys, reject_keys)
179
+ return {} if val.empty?
180
+
181
+ return {}
182
+ end
183
+
184
+
185
+
186
+ def flatten_hash_vals(key, val, flatten_keys, reject_keys)
187
+ return {} if val.empty?
188
+
189
+ answer = {}
190
+ # un-nest a hash a to top level keys
191
+ val.each do |k,v|
192
+ # remove any nested values if they match a reject_key
193
+ next if reject_keys.include? k
194
+
195
+ # (prepend flatten_key_to_current_key to prevent conflicts)
196
+ new_key = "#{key.to_s}_#{k.to_s}".to_sym
197
+ # clean the data and add back to to top level with a new key
198
+ answer[new_key] = clean_data(v)
199
+ end if val.is_a? Hash
166
200
  return answer
167
201
  end
168
202
 
@@ -1,3 +1,3 @@
1
1
  module Openapply
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/openapply.gemspec CHANGED
@@ -32,22 +32,18 @@ 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
+ # # need this version of axlsx to match roo's rubyzip needs
36
+ # # axlsx 2.1.0.pre uses rubyzip 1.1.7 - which has a security flaw
37
+ # # using the newest version of rubyzip 1.2.1 or larger
38
+ # spec.add_dependency "axlsx", "2.1.0.pre"
39
+ # spec.add_dependency "rubyzip", "~> 1.2"
40
+ spec.add_dependency "net-ssh", "~> 4.2"
41
+ spec.add_dependency "net-scp", "~> 1.2"
39
42
 
43
+ spec.add_development_dependency "simplecov", "~> 0.15"
40
44
  spec.add_development_dependency "webmock" , "~> 3.1"
41
45
  spec.add_development_dependency "bundler", "~> 1.15"
42
46
  spec.add_development_dependency "rake", "~> 10.0"
43
47
  spec.add_development_dependency "rspec", "~> 3.7"
44
- spec.add_development_dependency "roo", "~> 2.7"
45
- # spec.add_development_dependency "rspec", "~> 3.0"
46
- spec.add_development_dependency "simplecov", "~> 0.15"
47
- # spec.add_development_dependency "rspec-nc", "~> 3.0"
48
- # spec.add_development_dependency "guard", "~> 2.14"
49
- # spec.add_development_dependency "guard-rspec", "~> 4.7"
50
- # spec.add_development_dependency "pry", "~> 0.11"
51
- # spec.add_development_dependency "pry-remote", "~> 0.1"
52
- # spec.add_development_dependency "pry-nav", "~> 0.2"
48
+
53
49
  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.2.3
4
+ version: 0.2.4
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-11-23 00:00:00.000000000 Z
11
+ date: 2017-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: axlsx
42
+ name: net-ssh
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.0.pre
47
+ version: '4.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.0.pre
54
+ version: '4.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: net-ssh
56
+ name: net-scp
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.2'
61
+ version: '1.2'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '1.2'
69
69
  - !ruby/object:Gem::Dependency
70
- name: net-scp
70
+ name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
76
- type: :runtime
75
+ version: '0.15'
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: '1.2'
82
+ version: '0.15'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -136,34 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.7'
139
- - !ruby/object:Gem::Dependency
140
- name: roo
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '2.7'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '2.7'
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.15'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.15'
167
139
  description:
168
140
  email:
169
141
  - btihen@gmail.com
@@ -176,6 +148,7 @@ files:
176
148
  - ".travis.yml"
177
149
  - CODE_OF_CONDUCT.md
178
150
  - Gemfile
151
+ - Gemfile.lock
179
152
  - LICENSE.txt
180
153
  - README.md
181
154
  - Rakefile
@@ -213,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
186
  version: '0'
214
187
  requirements: []
215
188
  rubyforge_project:
216
- rubygems_version: 2.7.1
189
+ rubygems_version: 2.7.3
217
190
  signing_key:
218
191
  specification_version: 4
219
192
  summary: Access OpenApply's API with Ruby