ps_utilities 1.0.0 → 1.0.1

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: 30083f1244c4e8ea1a53ab81b8f88ac3c10d177fb651218cfcbe9dca8bdc219f
4
- data.tar.gz: c7f3991b61f85c224c48ca2bb3c172b8a2b24b50d28a8e14e1b80e9e5f831c4d
3
+ metadata.gz: 823ebc095fd0fe70b224f173aef9a951e1d1a9acd4bf14ad037895d0832f1ef6
4
+ data.tar.gz: 23e29507f3fc51e63cc9a640377bd2e3c437fd624652f387c9931aa93b09c720
5
5
  SHA512:
6
- metadata.gz: 848cfcbb6cf7b71d1e205ac04c21ac14a7b75be92b47db43effa58d6d455ac5b20a90e0d022070e0f9c0e4e1925599fca75493ec5a8f30047205b13a758fbae3
7
- data.tar.gz: f72b28802331533bb855536a2dcbf1ece95bab2fc3a4d09b7aeca883b4a1003c9d3ef1d2d403dd86d55b64ff5e641467f84125b86766370f8e10de41cdda0f66
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 attributes: [Hash] - options include: { base_uri: ENV['PS_BASE_URL'], auth_endpoint: (ENV['PS_AUTH_ENDPOINT'] || '/oauth/access_token'), client_id: ENV['PS_CLIENT_ID'], client_secret: ENV['PS_CLIENT_SECRET'] }
37
- # @param headers: [Hash] - allows to change from json to xml (only do this if you are doing direct api calls and not using pre-built calls) returns and use a different useragent: { 'User-Agent' => "PsUtilities - #{version}", 'Accept' => 'application/json', 'Content-Type' => 'application/json'}
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.merge(header_info)
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
- # verb = :delete, :get, :patch, :post, :put
82
- # options = {query: {}, body: {}} - get uses :query, put and post use :body
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
- # In PowerSchool go to System>System Settings>Plugin Management Configuration>your plugin>Data Provider Configuration to manually check plugin expiration date
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, {headers: auth_headers,
113
- body: 'grant_type=client_credentials'})
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).chomp
146
- # Base64.encode64(ps_auth_text).gsub(/\n/, '')
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['PS_BASE_URL'],
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
- # example student entry
8
- # @param params: { student: {dcid: 7531, student_id: 23456, email: "kid@las.ch"} }
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
- # @param params: { students:
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: :id
34
- # @note create_students OPTIONAL params are:
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: :last_name, :first_name, :entry_date, :exit_date, :school_number, :grade_level
49
- # @note update_students OPTIONAL params are: :
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[:school_enrollment] = {}
269
- if kid[:enroll_status_code]
270
- attribs[:school_enrollment][:enroll_status_code] = kid[:enroll_status_code]
271
- elsif kid[:status_code]
272
- attribs[:school_enrollment][:status_code] = kid[:status_code]
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
@@ -1,5 +1,5 @@
1
1
  module PsUtilities
2
2
  module Version
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
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.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-28 00:00:00.000000000 Z
12
+ date: 2018-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty