openapply 0.2.1 → 0.2.2

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: 4b681f4a386b3ab614a6eb7c4f8b244119a687a275eb0457dc54ff0b49901204
4
- data.tar.gz: b6f98f8ca674289a607606c5c79b6e1160e45c53cf88aa038cad2aeaff32c52a
3
+ metadata.gz: 5ea03a8e3bcfc34624d8c592e83d579600f62e323f00b5fbd563b3ef1b22616b
4
+ data.tar.gz: 915c89ae39776eb48b0d0533f6ba63b496cad6efb83ffa83d6f9f62ddfad983b
5
5
  SHA512:
6
- metadata.gz: 656f153e570d7afaede6b73765637868ded3079eadac0763f17fbd1a052ec3f47c787adbefd20b634dbb8f2b8e87afebf8758bae467a9b50e02c3f850dbb4e50
7
- data.tar.gz: b4c33173f2bd17b2ab0476231bbcc4ea2cd1a49ec362c24821c34c075cdb231f8620966a2f0f214b529d9a571e61006c116d51001115bfb74880c9865ca45742
6
+ metadata.gz: 860ecaf7e6d4ad6255edd1785f30c8e51b1dfee12de0747efa78c264d71e2f39983ae46ef31938785455ed0822ef23fc5f946ebf2d0eb950f1cb03e803466afc
7
+ data.tar.gz: 926f34f47b262ac63786edafbdbd62af3dc7ba3b786d36a26d9180c3404d2f907f74e7ec18247a2a150897eb3bc6e2d97f3fd108faaf0aea1b72ab18aba98723
data/README.md CHANGED
@@ -5,29 +5,30 @@ This gem allows ruby access to the OpenApply API v1 - and supports the GET featu
5
5
 
6
6
  ### Still TODO
7
7
 
8
- * xlsx export?
9
- * test timeouts
10
8
  * write PUTS methods
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)
9
+ * write a recursive custom query
10
+ * speed response when returning large number of records
11
+ * allow flattening and reject to work at any depth (recursion?)
15
12
 
16
13
 
17
14
  ### CHANGE LOG
18
15
 
19
- * **v0.1.0** - test release -- 2017-11-01
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
16
+ * **v0.2.2** - update compatible with 0.2.x - 2017-11-21
17
+ - refactor and test url timeouts
18
+ - refactor openapply client
24
19
 
25
- * **v0.2.1** - update compatible with 0.2.0 - 2017-11-20
20
+ * **v0.2.1** - update compatible with 0.2.x - 2017-11-20
26
21
  - convert api data into an array, csv or xlsx
27
22
  - allow data flattening prep for post processing
28
23
  - allow queries to lookup students with multiple statuses
29
24
  - allow scp string object to file export (no automated tests)
30
25
 
26
+ * **v0.2.0** - first release -- **NOT** compatible with 0.1.0 -- 2017-11-07
27
+ - get student details of a give status (and pure api calls)
28
+ - recursive query until all receipt of all records received
29
+
30
+ * **v0.1.0** - test release -- 2017-11-01
31
+
31
32
  ### Installation
32
33
 
33
34
  Add this line to your application's Gemfile:
data/lib/openapply.rb CHANGED
@@ -1,129 +1,6 @@
1
- require "openapply/get_students"
2
- require "openapply/get_student"
3
- require "openapply/convert"
1
+ require "openapply/client"
4
2
  require "openapply/version"
5
- require "openapply/put"
6
- require 'httparty'
7
3
 
8
4
  module Openapply
9
5
 
10
- # OpenApply is a service to manage admissions -
11
- # this gem allows access to OpenApply API calls via HTTParty
12
- #
13
- class Client
14
-
15
- # PUT api calls
16
- include Put
17
-
18
- # GET api calls
19
- include Get
20
-
21
- # Convert student data to various formats
22
- include Convert
23
-
24
- # Library for API calls to OpenApply
25
- include HTTParty
26
-
27
- # Defines OpenApply domain name from ENV-VARS
28
- API_URL = (ENV['OA_BASE_URI'] || 'demo.openapply.com')
29
-
30
- # Defines the OpenApply path from ENV-VARS - default is 5 seconds
31
- API_TIMEOUT = (ENV['OA_TIMEOUT'].to_i || 5)
32
-
33
- base_uri API_URL
34
- default_timeout API_TIMEOUT
35
-
36
- # Defines OpenApply domain name from ENV-VARS - for example:
37
- # demo.openapply.com
38
- def api_url
39
- API_URL
40
- end
41
-
42
- # Defines http timeout from ENV-VARS - 5 sec is the default
43
- def api_reply_count
44
- API_TIMEOUT
45
- end
46
- alias_method :api_timeout, :api_reply_count
47
-
48
- # Defines OpenApply secret access key with ENV-VARS
49
- def api_key
50
- ENV['OA_AUTH_TOKEN'] || 'demo_site_api_key'
51
- end
52
-
53
- # Defines the OpenApply path with ENV-VARS - default is for api_v1
54
- # /api/v1/students/
55
- def api_path
56
- ENV['OA_API_PATH'] || "/api/v1/students/"
57
- end
58
-
59
- # Defines the maximum records OpenApply should return with each api call
60
- # with ENV-VARS - (code default is 50 - OA default is 10 - doc says 100)
61
- def api_records
62
- ENV['OA_REPLY_RECORDS'] || '50'
63
- end
64
-
65
- # Handles httparty timeout errors - tries 3x before quitting
66
- # https://stackoverflow.com/questions/26251422/handling-netreadtimeout-error-in-httparty
67
- # TODO: figure out how to test time outs
68
- def handle_timeouts
69
- max_retries = 3
70
- times_retried = 0
71
- begin
72
- yield
73
- rescue Net::ReadTimeout => error
74
- if times_retried < max_retries
75
- times_retried += 1
76
- # puts "TIMEOUT RETRY: #{times_retried} of #{max_retries} - USING: #{yield.inspect}"
77
- retry
78
- else
79
- # puts "TIME-OUT URI FAILED: #{yield.inspect}"
80
- { error: "SITE TIMEOUT - 3 FAILURES USING: #{yield.inspect}" }
81
- end
82
- end
83
- end
84
-
85
- # Does the actual api call to OpenApply
86
- #
87
- # ==== Attributes
88
- # * +url+ - this is the url to do the call
89
- # /api/v1/students/95?auth_token=demo_site_api_key
90
- # is the url passed when wanting to do the following cli api call
91
- # curl http://demo.openapply.com/api/v1/students/95?auth_token=demo_site_api_key
92
- # * +options+ - see httparty options [http://www.rubydoc.info/github/jnunemaker/httparty]
93
- def oa_api_call(url, options={})
94
- self.class.get(url, options)
95
- end
96
-
97
- # Does checks the info for validity & unpacks the json retubed to a JS formatt
98
- #
99
- # ==== Attributes
100
- # * +url+ - this is the url to do the call
101
- # /api/v1/students/95?auth_token=demo_site_api_key
102
- # is the url passed when wanting to do the following cli api call
103
- # curl http://demo.openapply.com/api/v1/students/95?auth_token=demo_site_api_key
104
- # * +options+ - see httparty options [http://www.rubydoc.info/github/jnunemaker/httparty]
105
- def oa_answer(url, options={})
106
- # puts
107
- # puts "GIVEN URL: #{ url.inspect }"
108
- return { error: 'no url given' } if url.nil? or url.to_s.eql? ""
109
- return { error: 'bad url - has space' } if url.include? " "
110
- return { error: 'bad api_path' } unless url.include? "#{api_path}"
111
- return { error: 'bad auth_token' } unless url.include? "auth_token=#{api_key}"
112
- api_answer = nil
113
-
114
- handle_timeouts do
115
- api_answer = oa_api_call(url, options)
116
- end
117
-
118
- # puts "API ANSWER: #{api_answer}"
119
- # puts "API ANSWER: #{api_answer.inspect}"
120
- return { error: 'no response' } unless api_answer.respond_to? "response"
121
- return { error: 'no response' } if api_answer.response.nil?
122
- return { error: 'no response' } if api_answer.response.to_s.eql? ""
123
- return JSON.parse(api_answer.response.body, symbolize_names: true)
124
- end
125
- # alias_method :openapply_answer, :oa_answer
126
-
127
- end # Client
128
-
129
- end # Openapply
6
+ end
@@ -0,0 +1,118 @@
1
+ require "openapply/get_students"
2
+ require "openapply/get_student"
3
+ require "openapply/convert"
4
+ require "openapply/client"
5
+ require "openapply/put"
6
+ require 'httparty'
7
+
8
+ module Openapply
9
+
10
+ # OpenApply CLIENT is a service to manage admissions -
11
+ # this gem allows access to OpenApply API calls via HTTParty
12
+ #
13
+ class Client
14
+
15
+ # PUT api calls
16
+ include Put
17
+
18
+ # GET api calls
19
+ include Get
20
+
21
+ # Convert student data to various formats
22
+ include Convert
23
+
24
+ # Library for API calls to OpenApply
25
+ include HTTParty
26
+
27
+ # Defines OpenApply domain name from ENV-VARS
28
+ API_URL = (ENV['OA_BASE_URI'] || 'demo.openapply.com')
29
+
30
+ # Defines the OpenApply path from ENV-VARS - default is 5 seconds
31
+ API_TIMEOUT = (ENV['OA_TIMEOUT'].to_i || 5)
32
+
33
+ base_uri API_URL
34
+ default_timeout API_TIMEOUT
35
+
36
+ # Makes OpenApply domain name visible:
37
+ def api_url
38
+ API_URL
39
+ end
40
+
41
+ # make OpenApply timeout visible
42
+ def api_reply_count
43
+ API_TIMEOUT
44
+ end
45
+ alias_method :api_timeout, :api_reply_count
46
+
47
+ # Defines & makes visible OpenApply secret access key with ENV-VARS
48
+ def api_key
49
+ ENV['OA_AUTH_TOKEN'] || 'demo_site_api_key'
50
+ end
51
+
52
+ # Defines and makes visib le the OpenApply path with ENV-VARS
53
+ def api_path
54
+ ENV['OA_API_PATH'] || "/api/v1/students/"
55
+ end
56
+
57
+ # Defines and makes visible the maximum records OpenApply should return
58
+ # (code default is 50 - OA default is 10 - doc says 100)
59
+ def api_records
60
+ ENV['OA_REPLY_RECORDS'] || '50'
61
+ end
62
+
63
+ # Does the actual api call to OpenApply & handles API timeouts gracefully
64
+ #
65
+ # ==== Attributes
66
+ # * +url+ - this is the url to do the call
67
+ # /api/v1/students/95?auth_token=demo_site_api_key
68
+ # is the url passed when wanting to do the following cli api call
69
+ # curl http://demo.openapply.com/api/v1/students/95?auth_token=demo_site_api_key
70
+ # * +options+ - see httparty options [http://www.rubydoc.info/github/jnunemaker/httparty]
71
+ def oa_api_call(url, options={})
72
+ # https://stackoverflow.com/questions/26251422/handling-netreadtimeout-error-in-httparty
73
+ max_retries = 3
74
+ times_retried = 0
75
+ begin
76
+ self.class.get(url, options)
77
+ rescue Net::ReadTimeout, Net::OpenTimeout => error
78
+ if times_retried < max_retries
79
+ times_retried += 1
80
+ # puts "TIMEOUT RETRY: #{times_retried} of #{max_retries} - USING: #{url.inspect}"
81
+ retry
82
+ else
83
+ # puts "TIME-OUT URI FAILED: #{url.inspect}"
84
+ { error: "no response (timeout) from URL: #{url}" }
85
+ end
86
+ end
87
+ end
88
+
89
+ # Does checks the info for validity & unpacks the json retubed to a JS formatt
90
+ #
91
+ # ==== Attributes
92
+ # * +url+ - this is the url to do the call
93
+ # /api/v1/students/95?auth_token=demo_site_api_key
94
+ # is the url passed when wanting to do the following cli api call
95
+ # curl http://demo.openapply.com/api/v1/students/95?auth_token=demo_site_api_key
96
+ # * +options+ - see httparty options [http://www.rubydoc.info/github/jnunemaker/httparty]
97
+ def oa_answer(url, options={})
98
+ # puts
99
+ # puts "GIVEN URL: #{ url.inspect }"
100
+ return { error: 'no url given' } if url.nil? or url.to_s.eql? ""
101
+ return { error: 'bad url - has space' } if url.include? " "
102
+ return { error: 'bad api_path' } unless url.include? "#{api_path}"
103
+ return { error: 'bad auth_token' } unless url.include? "auth_token=#{api_key}"
104
+ api_answer = nil
105
+
106
+ api_answer = oa_api_call(url, options)
107
+
108
+ return api_answer unless api_answer.respond_to? "response" # and not api_answer[:error].nil?
109
+ # return { error: 'no response' } unless api_answer.respond_to? "response"
110
+ return { error: 'no response' } if api_answer.response.nil?
111
+ return { error: 'no response' } if api_answer.response.to_s.eql? ""
112
+ return JSON.parse(api_answer.response.body, symbolize_names: true)
113
+ end
114
+ # alias_method :openapply_answer, :oa_answer
115
+
116
+ end # Client
117
+
118
+ end # Openapply
@@ -3,6 +3,9 @@ require 'axlsx'
3
3
  require 'net/scp'
4
4
  require 'net/ssh'
5
5
 
6
+ # CODE THAT TRANSFORMS STUDENT DATA
7
+ ###################################
8
+
6
9
  module Convert
7
10
 
8
11
  # Queries by status to get a list of students details of a given status
@@ -1,8 +1,7 @@
1
- module Get
2
-
3
- # SINGLE STUDENT CODE
4
- #####################
1
+ # SINGLE STUDENT API GET CALLS
2
+ ##############################
5
3
 
4
+ module Get
6
5
 
7
6
  # STUDENT FULL RECORD
8
7
  #####################
@@ -1,3 +1,6 @@
1
+ # MULTIPLE STUDENTS API GET CALLS
2
+ #################################
3
+
1
4
  module Get
2
5
 
3
6
  # MULTIPLE STUDENTS DETAILS (full records) - found by status (or statuses)
@@ -1,3 +1,3 @@
1
1
  module Openapply
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  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.1
4
+ version: 0.2.2
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-20 00:00:00.000000000 Z
11
+ date: 2017-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -186,6 +186,7 @@ files:
186
186
  - examples/demo/README.md
187
187
  - examples/demo/demo_site.rb
188
188
  - lib/openapply.rb
189
+ - lib/openapply/client.rb
189
190
  - lib/openapply/convert.rb
190
191
  - lib/openapply/get_student.rb
191
192
  - lib/openapply/get_students.rb