Sha256: 4e4fb8eb1b69ba57407967342c4e10ed82c85a0d2e119923f7eb21ed781f2193
Contents?: true
Size: 1.64 KB
Versions: 9
Compression:
Stored size: 1.64 KB
Contents
# frozen_string_literal: true module PlatformSdk module PowerSchool # Powerschool::Client class Client attr_reader :bearer_token, :conn 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 def headers { "Authorization" => "Bearer #{@bearer_token}", "Content-Type" => "application/json", "Accept" => "application/json" } end def power_query(query_name) scrub_query(query_name) @conn.post("/ws/schema/query/com.strongmind.#{query_name}?pagesize=0").body["record"] end def special_programs records_as_json = power_query("specialprograms") records_as_json.map { |record| SpecialProgram.new(record) } end 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 def valid_power_query_names %w[specialprograms] end def scrub_query(query_name) raise PowerQueryNotValid unless valid_power_query_names.include?(query_name) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems