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
- #delete(path, params = nil) ⇒ Object
 - #get(path, params = nil, expansions = nil) ⇒ Object
 - #headers ⇒ Object
 - 
  
    
      #initialize(base_url:, bearer_token: nil, expansions: nil)  ⇒ Client 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Client.
 - #post(path, params = nil) ⇒ Object
 - #power_query(query_name, page_size: 0, params: nil) ⇒ Object
 - #put(path, params = nil) ⇒ 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
      57 58 59 60 61 62 63 64  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 57 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
#delete(path, params = nil) ⇒ Object
      48 49 50  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 48 def delete(path, params = nil) @conn.delete(path, params).body end  | 
  
#get(path, params = nil, expansions = nil) ⇒ Object
      34 35 36 37 38  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 34 def get(path, params = nil, expansions = nil) params ||= {} if expansions params[:expansions] = expansions.join(",") if expansions @conn.get(path, params).body end  | 
  
#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  | 
  
#post(path, params = nil) ⇒ Object
      40 41 42  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 40 def post(path, params = nil) @conn.post(path, params).body end  | 
  
#power_query(query_name, page_size: 0, params: nil) ⇒ Object
      29 30 31 32  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 29 def power_query(query_name, page_size: 0, params: nil) scrub_query(query_name) @conn.post("/ws/schema/query/com.strongmind.#{query_name}?pagesize=#{page_size}", params).body["record"] end  | 
  
#put(path, params = nil) ⇒ Object
      44 45 46  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 44 def put(path, params = nil) @conn.put(path, params).body end  | 
  
#scrub_query(query_name) ⇒ Object
      70 71 72  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 70 def scrub_query(query_name) raise PowerQueryNotValid unless valid_power_query_names.include?(query_name) end  | 
  
#special_programs ⇒ Object
      52 53 54 55  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 52 def special_programs records_as_json = power_query("specialprograms") records_as_json.map { |record| SpecialProgram.new(record) } end  | 
  
#valid_power_query_names ⇒ Object
      66 67 68  | 
    
      # File 'lib/platform_sdk/power_school/client.rb', line 66 def valid_power_query_names %w[attendance_daily_total specialprograms edkey.attendance_get_daily_total_minutes pitcrew.edkey.attendance_get_bulk] end  |