Module: PowerAPI

Defined in:
lib/powerapi.rb,
lib/powerapi/parser.rb,
lib/powerapi/version.rb,
lib/powerapi/exception.rb,
lib/powerapi/data/section.rb,
lib/powerapi/data/student.rb,
lib/powerapi/data/assignment.rb

Defined Under Namespace

Modules: Data Classes: Exception, Parser

Constant Summary collapse

VERSION =
"1.0.2"

Class Method Summary collapse

Class Method Details

.authenticate(url, username, password, fetch_transcript = true) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/powerapi.rb', line 15

def authenticate(url, username, password, fetch_transcript=true)
  url = clean_url(url)

  soap_endpoint = url + "/pearson-rest/services/PublicPortalService"

   = Savon.client(
    endpoint: soap_endpoint,
    namespace: "http://publicportal.rest.powerschool.pearson.com/xsd",
    wsse_auth: ["pearson", "pearson"]
  )

   = .call(:login, message: { username: username, password: password, userType: 2} )

  if .body[:login_response][:return][:user_session_vo] == nil
    raise PowerAPI::Exception.new(.body[:login_response][:return][:message_v_os][:description])
  end

  session = .body[:login_response][:return][:user_session_vo]

  return PowerAPI::Data::Student.new(url, session, fetch_transcript)
end

.clean_url(url) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/powerapi.rb', line 37

def clean_url(url)
  if url[-1] == "/"
    url = url[0..-2]
  else
    url = url
  end
end

.district_lookup(code) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/powerapi.rb', line 45

def district_lookup(code)
  request = HTTPI::Request.new("https://powersource.pearsonschoolsystems.com/services/rest/remote-device/v2/get-district/" + code)
  request.headers = { "Accept" => "application/json" }

  details = HTTPI.get(request)

  if details.error?
    return false
  end

  details = JSON.parse(details.body)

  district_lookup_url(details["district"]["server"])
end

.district_lookup_url(district_server) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/powerapi.rb', line 60

def district_lookup_url(district_server)
  if district_server["sslEnabled"] == true
    url = "https://"
  else
    url = 'http://'
  end

  url += district_server["serverAddress"]

  if (district_server["sslEnabled"] == true and district_server["portNumber"] != 443) or
      (district_server["sslEnabled"] == false and district_server["portNumber"] != 80)

      url += ":" + district_server["portNumber"].to_s
  end

  url
end