Class: PlatformSdk::PowerSchool::Client
- Inherits:
-
Object
- Object
- PlatformSdk::PowerSchool::Client
- Defined in:
- lib/platform_sdk/power_school/client.rb
Overview
Powerschool::Client
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Class Method Summary collapse
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(base_url:, bearer_token: nil, expansions: nil) ⇒ Client
constructor
A new instance of Client.
- #power_query(query_name) ⇒ Object
- #scrub_query(query_name) ⇒ Object
- #special_programs ⇒ Object
- #valid_power_query_names ⇒ Object
Constructor Details
#initialize(base_url:, bearer_token: nil, expansions: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/platform_sdk/power_school/client.rb', line 8 def initialize(base_url:, bearer_token: nil, expansions: nil) @bearer_token = bearer_token @bearer_token ||= PlatformSdk::PowerSchool.bearer_token @expansions = expansions || self.class.expansions @conn = Faraday.new(base_url, headers:) do |conn| conn.response :raise_error conn.request :json conn.response :json conn.adapter :net_http end end |
Instance Attribute Details
#bearer_token ⇒ Object (readonly)
Returns the value of attribute bearer_token.
6 7 8 |
# File 'lib/platform_sdk/power_school/client.rb', line 6 def bearer_token @bearer_token end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
6 7 8 |
# File 'lib/platform_sdk/power_school/client.rb', line 6 def conn @conn end |
Class Method Details
.expansions ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/platform_sdk/power_school/client.rb', line 39 def self.expansions { STUDENTS: %w[demographics addresses alerts phones school_enrollment ethnicity_race contact contact_info initial_enrollment schedule_setup fees lunch], SECTIONS: %w[term], TEACHERS: %w[addresses emails phones school_affiliations] } end |
Instance Method Details
#headers ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/platform_sdk/power_school/client.rb', line 21 def headers { "Authorization" => "Bearer #{@bearer_token}", "Content-Type" => "application/json", "Accept" => "application/json" } end |
#power_query(query_name) ⇒ Object
29 30 31 32 |
# File 'lib/platform_sdk/power_school/client.rb', line 29 def power_query(query_name) scrub_query(query_name) @conn.post("/ws/schema/query/com.strongmind.#{query_name}?pagesize=0").body["record"] end |
#scrub_query(query_name) ⇒ Object
52 53 54 |
# File 'lib/platform_sdk/power_school/client.rb', line 52 def scrub_query(query_name) raise PowerQueryNotValid unless valid_power_query_names.include?(query_name) end |
#special_programs ⇒ Object
34 35 36 37 |
# File 'lib/platform_sdk/power_school/client.rb', line 34 def special_programs records_as_json = power_query("specialprograms") records_as_json.map { |record| SpecialProgram.new(record) } end |
#valid_power_query_names ⇒ Object
48 49 50 |
# File 'lib/platform_sdk/power_school/client.rb', line 48 def valid_power_query_names %w[specialprograms edkey.attendance_get_daily_total_minutes] end |