Class: PsUtilities::Connection
Overview
The PsUtilities, makes it east to work with the Powerschool API
Instance Attribute Summary collapse
Instance Method Summary
collapse
#create_students, #update_students
#get_all_active_students, #get_all_matching_students, #get_one_student
Constructor Details
#initialize(api_info: {}, client_info: {}) ⇒ Connection
Note:
preference is to use environment variables to initialize your server.
def initialize( header_info: {}, api_info: {}, client_info: {})
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/ps_utilities/connection.rb', line 40
def initialize( api_info: {}, client_info: {})
@version = "v#{PsUtilities::Version::VERSION}"
@client = client_defaults.merge(client_info)
@client_id = client[:client_id]
@client_secret = client[:client_secret]
@api_data = api_defaults.merge(api_info)
@base_uri = api_data[:base_uri]
@auth_path = api_data[:auth_endpoint]
=
raise ArgumentError, "missing client_secret" if client_secret.nil? or client_secret.empty?
raise ArgumentError, "missing client_id" if client_id.nil? or client_id.empty?
raise ArgumentError, "missing auth endpoint" if auth_path.nil? or auth_path.empty?
raise ArgumentError, "missing base_uri" if base_uri.nil? or base_uri.empty?
end
|
Instance Attribute Details
#api_data ⇒ Object
28
29
30
|
# File 'lib/ps_utilities/connection.rb', line 28
def api_data
@api_data
end
|
#auth_info ⇒ Object
27
28
29
|
# File 'lib/ps_utilities/connection.rb', line 27
def auth_info
@auth_info
end
|
#auth_path ⇒ Object
27
28
29
|
# File 'lib/ps_utilities/connection.rb', line 27
def auth_path
@auth_path
end
|
#auth_token ⇒ Object
27
28
29
|
# File 'lib/ps_utilities/connection.rb', line 27
def auth_token
@auth_token
end
|
#base_uri ⇒ Object
28
29
30
|
# File 'lib/ps_utilities/connection.rb', line 28
def base_uri
@base_uri
end
|
#client ⇒ Object
29
30
31
|
# File 'lib/ps_utilities/connection.rb', line 29
def client
@client
end
|
#client_id ⇒ Object
29
30
31
|
# File 'lib/ps_utilities/connection.rb', line 29
def client_id
@client_id
end
|
#client_secret ⇒ Object
29
30
31
|
# File 'lib/ps_utilities/connection.rb', line 29
def client_secret
@client_secret
end
|
27
28
29
|
# File 'lib/ps_utilities/connection.rb', line 27
def
end
|
#version ⇒ Object
30
31
32
|
# File 'lib/ps_utilities/connection.rb', line 30
def version
@version
end
|
Instance Method Details
#run(command: nil, api_path: "", options: {}, params: {}) ⇒ Object
Note:
with no command an authenticatation check is done
this runs the various options:
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/ps_utilities/connection.rb', line 63
def run(command: nil, api_path: "", options: {}, params: {})
authenticate unless auth_valid?
case command
when nil, :authenticate
authenticate
when :delete, :get, :patch, :post, :put
api(command, api_path, options) unless api_path.empty?
else
send(command, params)
end
rescue ArgumentError => error
return {"error_message" => error.message}
end
|