ps_utilities 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ps_utilities/connection.rb +25 -12
- data/lib/ps_utilities/pre_built_post.rb +16 -22
- data/lib/ps_utilities/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823ebc095fd0fe70b224f173aef9a951e1d1a9acd4bf14ad037895d0832f1ef6
|
4
|
+
data.tar.gz: 23e29507f3fc51e63cc9a640377bd2e3c437fd624652f387c9931aa93b09c720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512c0c6e1b8c9d5da4426c7c5e15ee4a478c24fab18521d08371e4d1c71521a58873267a7b93f7808cacfced820914e658416cc58f1e0ba4ca91cf186709abc0
|
7
|
+
data.tar.gz: 35875ad1cee3a496c645c76f8bcedd1a689428e51642ab7cbcab8da28cd97301026dbc9f2aa884a1073d841cfcd999163e2e42afc2ce210f2a4fb70512bfff13
|
@@ -33,10 +33,11 @@ module PsUtilities
|
|
33
33
|
include PsUtilities::PreBuiltPut
|
34
34
|
include PsUtilities::PreBuiltPost
|
35
35
|
|
36
|
-
# @param
|
37
|
-
# @param
|
36
|
+
# @param api_info: [Hash] - allows override of api settings :base_uri (overrides ENV['PS_BASE_URI']) and :auth_path (overrides ENV['PS_ATUH_ENDPOINT'])
|
37
|
+
# @param client_info: [Hash] - allows override of client login values :client_id (overrides ENV['PS_CLIENT_ID']) & :client_secret (overrides ENV['PS_CLIENT_SECRET'])
|
38
38
|
# @note preference is to use environment variables to initialize your server.
|
39
|
-
def initialize( header_info: {}, api_info: {}, client_info: {})
|
39
|
+
# def initialize( header_info: {}, api_info: {}, client_info: {})
|
40
|
+
def initialize( api_info: {}, client_info: {})
|
40
41
|
@version = "v#{PsUtilities::Version::VERSION}"
|
41
42
|
@client = client_defaults.merge(client_info)
|
42
43
|
@client_id = client[:client_id]
|
@@ -44,7 +45,8 @@ module PsUtilities
|
|
44
45
|
@api_data = api_defaults.merge(api_info)
|
45
46
|
@base_uri = api_data[:base_uri]
|
46
47
|
@auth_path = api_data[:auth_endpoint]
|
47
|
-
@headers = header_defaults
|
48
|
+
@headers = header_defaults # Auth key is added when authenticate is executed
|
49
|
+
# @headers['Authorization'] = header_info['Authorization'] if header_info['Authorization']
|
48
50
|
|
49
51
|
raise ArgumentError, "missing client_secret" if client_secret.nil? or client_secret.empty?
|
50
52
|
raise ArgumentError, "missing client_id" if client_id.nil? or client_id.empty?
|
@@ -78,8 +80,10 @@ module PsUtilities
|
|
78
80
|
"#{auth_info['access_token']}"
|
79
81
|
end
|
80
82
|
|
81
|
-
#
|
82
|
-
#
|
83
|
+
# Direct API access
|
84
|
+
# @param verb [Symbol] hmtl verbs (:delete, :get, :patch, :post, :put)
|
85
|
+
# @param options [Hash] allowed keys are {query: {}, body: {}} - uses :query for gets, and use :body for put and post
|
86
|
+
# @return [HTTParty] - useful things to access include: obj.parsed_response (to access returned data) & obj.code to be sure the response was successful "200"
|
83
87
|
def api(verb, api_path, options={})
|
84
88
|
count = 0
|
85
89
|
retries = 3
|
@@ -97,6 +101,8 @@ module PsUtilities
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
104
|
+
# by this code sends and recieves json data - only overide if building your own data and sending directly via the API methods :get, :put, :post, etc.
|
105
|
+
# @note do not override these Settings - if using the pre-build commands
|
100
106
|
def header_defaults
|
101
107
|
{ headers:
|
102
108
|
{ 'User-Agent' => "PsUtilities - #{version}",
|
@@ -106,11 +112,18 @@ module PsUtilities
|
|
106
112
|
}
|
107
113
|
end
|
108
114
|
|
109
|
-
#
|
115
|
+
# gets API auth token and puts in header HASH for future requests with PS server
|
116
|
+
# @return [Hash] - of auth token and time to live from powerschol server
|
117
|
+
# {'access_token' => "addsfabe-aads-4444-bbbb-444411ffffbb",
|
118
|
+
# 'token_type' => "Bearer",
|
119
|
+
# 'expires_in' => "2504956"
|
120
|
+
# 'token_expires' => (Time.now + 3600)}
|
121
|
+
# @note - to enable PS API - In PowerSchool go to System>System Settings>Plugin Management Configuration>your plugin>Data Provider Configuration to manually check plugin expiration date
|
110
122
|
def authenticate
|
111
123
|
ps_url = base_uri + auth_path
|
112
|
-
response = HTTParty.post(ps_url,
|
113
|
-
|
124
|
+
response = HTTParty.post( ps_url,
|
125
|
+
{ headers: auth_headers,
|
126
|
+
body: 'grant_type=client_credentials'} )
|
114
127
|
if response.code.to_s.eql? "200"
|
115
128
|
@auth_info = response.parsed_response
|
116
129
|
@auth_info['token_expires'] = Time.now + response.parsed_response['expires_in'].to_i
|
@@ -142,8 +155,8 @@ module PsUtilities
|
|
142
155
|
|
143
156
|
def encode64_client(credentials = client)
|
144
157
|
ps_auth_text = [ credentials[:client_id], credentials[:client_secret] ].join(':')
|
145
|
-
Base64.encode64(ps_auth_text).
|
146
|
-
# Base64.encode64(ps_auth_text).
|
158
|
+
Base64.encode64(ps_auth_text).gsub(/\n/, '')
|
159
|
+
# Base64.encode64(ps_auth_text).chomp
|
147
160
|
end
|
148
161
|
|
149
162
|
def client_defaults
|
@@ -153,7 +166,7 @@ module PsUtilities
|
|
153
166
|
end
|
154
167
|
|
155
168
|
def api_defaults
|
156
|
-
{ base_uri: ENV['
|
169
|
+
{ base_uri: ENV['PS_BASE_URI'],
|
157
170
|
auth_endpoint: ENV['PS_AUTH_ENDPOINT'] || '/oauth/access_token',
|
158
171
|
}
|
159
172
|
end
|
@@ -3,11 +3,12 @@ module PsUtilities
|
|
3
3
|
module PreBuiltPost
|
4
4
|
|
5
5
|
# this method CREATES or INSERTS a new student into PowerSchool
|
6
|
-
# @param params (Array of Hashes) - kids with their attributes
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# @param params (Array of Hashes) - kids with their attributes use format:
|
7
|
+
# one kid
|
8
|
+
# params: { students: [{dcid: 7531, student_id: 23456, email: "kid1@las.ch"}] }
|
9
|
+
#
|
9
10
|
# or multiple students (with ps and your school's database extensions)
|
10
|
-
#
|
11
|
+
# params: { students:
|
11
12
|
# [ { dcid: 9753, student_id: 65432 },
|
12
13
|
# { dcid: 7531, student_id: 23456, email: "kid@las.ch",
|
13
14
|
# u_studentsuserfields: {transcriptaddrcity: "Bex"},
|
@@ -30,9 +31,9 @@ module PsUtilities
|
|
30
31
|
# ]
|
31
32
|
# }
|
32
33
|
# }
|
33
|
-
# @note create_students REQUIRED params are: :
|
34
|
-
# @note create_students OPTIONAL params
|
35
|
-
# @note create_students INVALID params are:
|
34
|
+
# @note create_students REQUIRED params are: :student_id (chosen by the school same as local_id within PS), :last_name, :first_name, :entry_date, :exit_date, :school_number, :grade_level
|
35
|
+
# @note create_students OPTIONAL params include: :school_id, :username, :middle_name, physical address objects, mailing address objects, demographics objects, contacts objects, schedule setup objects, intial enrollment objects (disctrict and school), :contact_info, :phone, :u_studentsuserfields (powerschool defined extensions) & :u_students_extension (school defined db extensions)
|
36
|
+
# @note create_students INVALID (ignored) params are: :id (dcid - chosen by the PS system)
|
36
37
|
def create_students(params)
|
37
38
|
action = "INSERT"
|
38
39
|
kids_api_array = build_kids_api_array(action, params)
|
@@ -45,9 +46,8 @@ module PsUtilities
|
|
45
46
|
|
46
47
|
# this updates and existing student record within PowerSchool
|
47
48
|
# (see #create_students)
|
48
|
-
# @note update_students REQUIRED params are:
|
49
|
-
# @note update_students
|
50
|
-
# @note update_students INVALID params are:
|
49
|
+
# @note update_students REQUIRED params are: **:id** (dcid) and **:student_id** (local_id)
|
50
|
+
# @note update_students INVALID (ignored) params are: :grade_level, :entry_date, :exit_date, :school_number, :school_id
|
51
51
|
def update_students(params)
|
52
52
|
action = "UPDATE"
|
53
53
|
kids_api_array = build_kids_api_array(action, params)
|
@@ -189,7 +189,7 @@ module PsUtilities
|
|
189
189
|
attribs[:name] = {}
|
190
190
|
case action
|
191
191
|
when 'INSERT'
|
192
|
-
# must be set on creation
|
192
|
+
# must be set on creation (INSERT)
|
193
193
|
attribs[:local_id] = kid[:oa_id].to_i
|
194
194
|
# to create an account both first and last name must be present
|
195
195
|
attribs[:name][:last_name] = kid[:last_name] if kid[:last_name] or kid[:first_name]
|
@@ -265,16 +265,11 @@ module PsUtilities
|
|
265
265
|
attribs[:schedule_setup][:next_school] = kid[:next_school] if kid[:next_school]
|
266
266
|
attribs[:schedule_setup][:sched_next_year_grade] = kid[:sched_next_year_grade] if kid[:sched_next_year_grade]
|
267
267
|
#
|
268
|
-
attribs[:
|
269
|
-
if kid[:
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
end
|
274
|
-
attribs[:school_enrollment][:grade_level] = kid[:grade_level] if kid[:grade_level]
|
275
|
-
attribs[:school_enrollment][:entry_date] = kid[:entry_date] if kid[:entry_date]
|
276
|
-
attribs[:school_enrollment][:exit_date] = kid[:exit_date] if kid[:exit_date]
|
277
|
-
attribs[:school_enrollment][:school_number] = kid[:school_number] if kid[:school_number]
|
268
|
+
attribs[:initial_enrollment] = {}
|
269
|
+
attribs[:initial_enrollment][:school_entry_date] = kid[:school_entry_date] if kid[:school_entry_date]
|
270
|
+
attribs[:initial_enrollment][:school_entry_grade_level] = kid[:school_entry_grade_level] if kid[:school_entry_grade_level]
|
271
|
+
attribs[:initial_enrollment][:district_entry_date] = kid[:district_entry_date] if kid[:district_entry_date]
|
272
|
+
attribs[:initial_enrollment][:district_entry_grade_level] = kid[:district_entry_grade_level] if kid[:district_entry_grade_level]
|
278
273
|
#
|
279
274
|
attribs[:contact_info] = {email: kid[:email]} if kid[:email]
|
280
275
|
attribs[:phone] = {main: {number: kid[:mobile]}} if kid[:mobile]
|
@@ -296,5 +291,4 @@ module PsUtilities
|
|
296
291
|
end
|
297
292
|
|
298
293
|
end
|
299
|
-
|
300
294
|
end
|
data/lib/ps_utilities/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ps_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Weisbecker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-06-
|
12
|
+
date: 2018-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|