lib/ps_utilities/connection.rb
# gets API auth token and puts in header HASH for future requests with PS server
# @return [Hash] - of auth token and time to live from powerschol server
# {'access_token' => "addsfabe-aads-4444-bbbb-444411ffffbb",
#  'token_type' => "Bearer",
#  'expires_in' => "2504956"
#  'token_expires' => (Time.now + 3600)}
# @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
gets API auth token and puts in header HASH for future requests with PS server
gets API auth token and puts in header HASH for future requests with PS server
def authenticate
      ps_url   = base_uri + auth_path
      response = HTTParty.post( ps_url,
                                { headers: auth_headers,
                                  body: 'grant_type=client_credentials'} )
      if response.code.to_s.eql? "200"
        @auth_info = response.parsed_response
        @auth_info['token_expires'] = Time.now + response.parsed_response['expires_in'].to_i
        @headers[:headers].merge!('Authorization' => 'Bearer ' + auth_info['access_token'])
        return auth_info
      else
        raise AuthError.new("No Auth Token Returned", ps_url, client )
      end
    end
def authenticate ps_url = base_uri + auth_path response = HTTParty . post ( ps_url , { headers : auth_headers , body : 'grant_type=client_credentials' } ) if response . code . to_s . eql? "200" @auth_info = response . parsed_response @auth_info [ 'token_expires' ] = Time . now + response . parsed_response [ 'expires_in' ] . to_i @headers [ :headers ] . merge! ( 'Authorization' => 'Bearer ' + auth_info [ 'access_token' ] ) return auth_info else raise AuthError . new ( "No Auth Token Returned" , ps_url , client ) end end
gets API auth token and puts in header HASH for future requests with PS server
gets API auth token and puts in header HASH for future requests with PS server
# throw error if - error returned -- nothing else will work
of auth token and time to live from powerschol server {'access_token' => "addsfabe-aads-4444-bbbb-444411ffffbb", 'token_type' => "Bearer", 'expires_in' => "2504956" 'token_expires' => (Time.now + 3600)}
of auth token and time to live from powerschol server { ' access_token ' = > " addsfabe - aads - 4444 - bbbb - 444411ffffbb " ' token_type ' = > " Bearer " ' expires_in ' = > " 2504956 " ' token_expires ' = > ( Time . now + 3600 ) }
Hash
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
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