powerapi 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37841ff98ae99e8c2b0dd4b89464ab7c244a000d
4
- data.tar.gz: 548bd5663509d0e6d35215ca755c5cf15eccc673
3
+ metadata.gz: 63d3c8580e2d02e887d44732b857882bc8d2e104
4
+ data.tar.gz: 1ba4b8b6720e3e4ddc9261e0c3e9467bee9a7ec6
5
5
  SHA512:
6
- metadata.gz: c776a30b3c0bafdc48b4e758ed5a46722e2ceed47e40bf9aa6bf21159b8d2fda6c45d736ecb7a310da43c9c0d1f592020d1fff6220cd69ab6de0a0f774d565f7
7
- data.tar.gz: 3586a016448f7c836d9f56db58521a1ec72357793dbdd8741b56727a89f0e13abaf380150d3d5ae124beec8ee7f4a3b2bdb504beebca111eb78b8a558858410f
6
+ metadata.gz: af346ff6b959d0172ac4356e8354c14e6f11ea5b793fa0ef531d10abf557419cfcd139e6b1690bcc40caa7a5dec414f6b9438303820b11ec2facf7da9bf4c61f
7
+ data.tar.gz: e02214d310936139690ac4830d19667b5420c53f680cf17672b27a780754c3f473609b1e1dd36eb3362fafe65299ac208709dd7b6ff85088aca487709da25338
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Build Status](https://img.shields.io/travis/powerapi/powerapi-ruby.svg?style=flat-square&branch=master)](https://travis-ci.org/powerapi/powerapi-ruby)
2
- [![Coverage Status](https://img.shields.io/coveralls/powerapi/powerapi-ruby.svg?style=flat-square)](https://coveralls.io/r/powerapi/powerapi-ruby)
2
+ [![Coverage Status](http://img.shields.io/codeclimate/coverage/github/powerapi/powerapi-ruby.svg?style=flat-square)](https://coveralls.io/r/powerapi/powerapi-ruby)
3
3
  [![Code Climate](http://img.shields.io/codeclimate/github/powerapi/powerapi-ruby.svg?style=flat-square)](https://codeclimate.com/github/powerapi/powerapi-ruby)
4
4
  [![Gem Version](https://img.shields.io/gem/v/powerapi.svg?style=flat-square)](https://rubygems.org/gems/powerapi)
5
5
 
data/lib/powerapi.rb CHANGED
@@ -2,9 +2,9 @@ require "powerapi/exception.rb"
2
2
  require "powerapi/parser.rb"
3
3
  require "powerapi/version.rb"
4
4
 
5
- require "powerapi/assignment.rb"
6
- require "powerapi/section.rb"
7
- require "powerapi/student.rb"
5
+ require "powerapi/data/assignment.rb"
6
+ require "powerapi/data/section.rb"
7
+ require "powerapi/data/student.rb"
8
8
 
9
9
  require "savon"
10
10
  require "json"
@@ -31,7 +31,7 @@ module PowerAPI
31
31
 
32
32
  session = login.body[:login_response][:return][:user_session_vo]
33
33
 
34
- return PowerAPI::Student.new(url, session, fetch_transcript)
34
+ return PowerAPI::Data::Student.new(url, session, fetch_transcript)
35
35
  end
36
36
 
37
37
  def clean_url(url)
@@ -41,4 +41,37 @@ module PowerAPI
41
41
  url = url
42
42
  end
43
43
  end
44
+
45
+ def district_lookup(code)
46
+ request = HTTPI::Request.new("https://powersource.pearsonschoolsystems.com/services/rest/remote-device/v2/get-district/" + code)
47
+ request.headers = { "Accept" => "application/json" }
48
+
49
+ details = HTTPI.get(request)
50
+
51
+ if details.error?
52
+ return false
53
+ end
54
+
55
+ details = JSON.parse(details.body)
56
+
57
+ district_lookup_url(details["district"]["server"])
58
+ end
59
+
60
+ def district_lookup_url(district_server)
61
+ if district_server["sslEnabled"] == true
62
+ url = "https://"
63
+ else
64
+ url = 'http://'
65
+ end
66
+
67
+ url += district_server["serverAddress"]
68
+
69
+ if (district_server["sslEnabled"] == true and district_server["portNumber"] != 443) or
70
+ (district_server["sslEnabled"] == false and district_server["portNumber"] != 80)
71
+
72
+ url += ":" + district_server["portNumber"].to_s
73
+ end
74
+
75
+ url
76
+ end
44
77
  end
@@ -0,0 +1,29 @@
1
+ module PowerAPI
2
+ module Data
3
+ class Assignment
4
+ def initialize(details)
5
+ @details = details
6
+ end
7
+
8
+ def category
9
+ @details[:category]["name"]
10
+ end
11
+
12
+ def description
13
+ @details[:assignment]["description"]
14
+ end
15
+
16
+ def name
17
+ @details[:assignment]["name"]
18
+ end
19
+
20
+ def percent
21
+ @details[:score]["percent"]
22
+ end
23
+
24
+ def score
25
+ @details[:score]["score"]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ module PowerAPI
2
+ module Data
3
+ class Section
4
+ def initialize(details)
5
+ @details = details
6
+
7
+ # Occasionally, a section won't have any final_grades objects
8
+ if @details[:final_grades] != nil
9
+ @final_grades = {}
10
+
11
+ @details[:final_grades].each do |final_grade|
12
+ @final_grades[
13
+ @details[:reporting_terms][final_grade["reportingTermId"]]
14
+ ] = final_grade["percent"]
15
+ end
16
+ else
17
+ @final_grades = nil
18
+ end
19
+ end
20
+
21
+ def assignments
22
+ @details[:assignments]
23
+ end
24
+
25
+ def expression
26
+ @details[:section]["expression"]
27
+ end
28
+
29
+ def final_grades
30
+ @final_grades
31
+ end
32
+
33
+ def name
34
+ @details[:section]["schoolCourseTitle"]
35
+ end
36
+
37
+ def room_name
38
+ @details[:section]["roomName"]
39
+ end
40
+
41
+ def teacher
42
+ {
43
+ :first_name => @details[:teacher]["firstName"],
44
+ :last_name => @details[:teacher]["lastName"],
45
+ :email => @details[:teacher]["email"],
46
+ :school_phone => @details[:teacher]["schoolPhone"]
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,75 @@
1
+ module PowerAPI
2
+ module Data
3
+ class Student
4
+ def initialize(soap_url, soap_session, populate=true)
5
+ @soap_url = soap_url
6
+ @soap_session = soap_session
7
+
8
+ if populate
9
+ self.populate()
10
+ end
11
+ end
12
+
13
+ def populate()
14
+ transcript = self.fetch_transcript
15
+ self.parse_transcript(transcript)
16
+ end
17
+
18
+ def fetch_transcript()
19
+ student_client = Savon.client(
20
+ endpoint: @soap_url + "/pearson-rest/services/PublicPortalServiceJSON?response=application/json",
21
+ namespace: "http://publicportal.rest.powerschool.pearson.com/xsd",
22
+ digest_auth: ["pearson", "m0bApP5"]
23
+ )
24
+
25
+ transcript_params = {
26
+ userSessionVO: {
27
+ userId: @soap_session[:user_id],
28
+ serviceTicket: @soap_session[:service_ticket],
29
+ serverInfo: {
30
+ apiVersion: @soap_session[:server_info][:api_version]
31
+ },
32
+ serverCurrentTime: "2012-12-26T21:47:23.792Z", # I really don't know.
33
+ userType: "2"
34
+ },
35
+ studentIDs: @soap_session[:student_i_ds],
36
+ qil: {
37
+ includes: "1"
38
+ }
39
+ }
40
+
41
+ transcript = student_client.call(:get_student_data, message: transcript_params).to_xml
42
+
43
+ JSON.parse(transcript)
44
+ end
45
+
46
+ def parse_transcript(transcript)
47
+ @student_data = transcript["return"]["studentDataVOs"]
48
+
49
+ @student_data["student"].delete("@type")
50
+
51
+ assignment_categories = PowerAPI::Parser.assignment_categories(@student_data["assignmentCategories"])
52
+ assignment_scores = PowerAPI::Parser.assignment_scores(@student_data["assignmentScores"])
53
+ final_grades = PowerAPI::Parser.final_grades(@student_data["finalGrades"])
54
+ reporting_terms = PowerAPI::Parser.reporting_terms(@student_data["reportingTerms"])
55
+ teachers = PowerAPI::Parser.teachers(@student_data["teachers"])
56
+
57
+ assignments = PowerAPI::Parser.assignments(@student_data["assignments"], assignment_categories, assignment_scores)
58
+
59
+ @sections = PowerAPI::Parser.sections(@student_data["sections"], assignments, final_grades, reporting_terms, teachers)
60
+
61
+ return 0
62
+ end
63
+
64
+ def sections
65
+ @sections
66
+ end
67
+
68
+ def information
69
+ if @student_data != nil
70
+ @student_data["student"]
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -8,7 +8,7 @@ module PowerAPI
8
8
  assignments[assignment["sectionid"]] = []
9
9
  end
10
10
 
11
- assignments[assignment["sectionid"]] << PowerAPI::Assignment.new({
11
+ assignments[assignment["sectionid"]] << PowerAPI::Data::Assignment.new({
12
12
  :assignment => assignment,
13
13
  :category => assignment_categories[assignment["categoryId"]],
14
14
  :score => assignment_scores[assignment["id"]],
@@ -72,7 +72,7 @@ module PowerAPI
72
72
  next
73
73
  end
74
74
 
75
- sections << PowerAPI::Section.new({
75
+ sections << PowerAPI::Data::Section.new({
76
76
  :assignments => assignments[section["id"]],
77
77
  :final_grades => final_grades[section["id"]],
78
78
  :reporting_terms => reporting_terms,
@@ -1,3 +1,3 @@
1
1
  module PowerAPI
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/powerapi.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
24
  spec.add_development_dependency "simplecov"
25
- spec.add_development_dependency "coveralls"
25
+ spec.add_development_dependency "webmock", "~> 1.20.0"
26
+ spec.add_development_dependency "codeclimate-test-reporter"
26
27
 
27
28
  spec.add_runtime_dependency "savon", "~> 2.0"
28
29
  spec.add_runtime_dependency "httpclient", "~> 2.4.0"
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe PowerAPI::Assignment do
3
+ describe PowerAPI::Data::Assignment do
4
4
  include Savon::SpecHelper
5
5
 
6
6
  before(:all) {
@@ -33,7 +33,7 @@ describe PowerAPI::Assignment do
33
33
 
34
34
  savon.expects(:get_student_data).with(message: message).returns(fixture)
35
35
 
36
- student = PowerAPI::Student.new("http://powerschool.example", @session)
36
+ student = PowerAPI::Data::Student.new("http://powerschool.example", @session)
37
37
 
38
38
  @assignment = student.sections[0].assignments[0]
39
39
  }
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe PowerAPI::Section do
3
+ describe PowerAPI::Data::Section do
4
4
  include Savon::SpecHelper
5
5
 
6
6
  before(:all) {
@@ -33,7 +33,7 @@ describe PowerAPI::Section do
33
33
 
34
34
  savon.expects(:get_student_data).with(message: message).returns(fixture)
35
35
 
36
- student = PowerAPI::Student.new("http://powerschool.example", @session)
36
+ student = PowerAPI::Data::Student.new("http://powerschool.example", @session)
37
37
 
38
38
  @section0 = student.sections[0]
39
39
  @section1 = student.sections[1]
@@ -50,10 +50,10 @@ describe PowerAPI::Section do
50
50
  ).to be(1)
51
51
  end
52
52
 
53
- it "has a PowerAPI::Assignment instance at index 0" do
53
+ it "has a PowerAPI::Data::Assignment instance at index 0" do
54
54
  expect(
55
55
  @section0.assignments[0]
56
- ).to be_an_instance_of(PowerAPI::Assignment)
56
+ ).to be_an_instance_of(PowerAPI::Data::Assignment)
57
57
  end
58
58
  end
59
59
 
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- describe PowerAPI::Student do
3
+ describe PowerAPI::Data::Student do
4
4
  include Savon::SpecHelper
5
5
 
6
6
  before(:all) {
@@ -15,7 +15,7 @@ describe PowerAPI::Student do
15
15
 
16
16
  describe "#initialize" do
17
17
  before(:each) {
18
- @student = PowerAPI::Student.new("http://powerschool.example", @session, false)
18
+ @student = PowerAPI::Data::Student.new("http://powerschool.example", @session, false)
19
19
  }
20
20
 
21
21
  after(:each) {
@@ -56,7 +56,7 @@ describe PowerAPI::Student do
56
56
 
57
57
  savon.expects(:get_student_data).with(message: message).returns(fixture)
58
58
 
59
- student = PowerAPI::Student.new("http://powerschool.example", @session, false)
59
+ student = PowerAPI::Data::Student.new("http://powerschool.example", @session, false)
60
60
 
61
61
  transcript = student.fetch_transcript["return"]["studentDataVOs"]
62
62
 
@@ -73,7 +73,7 @@ describe PowerAPI::Student do
73
73
  fixture = File.read("spec/fixtures/transcript.json")
74
74
  fixture = JSON.parse(fixture)
75
75
 
76
- @student = PowerAPI::Student.new("http://powerschool.example", @session, false)
76
+ @student = PowerAPI::Data::Student.new("http://powerschool.example", @session, false)
77
77
 
78
78
  @student.parse_transcript(fixture)
79
79
  }
@@ -0,0 +1 @@
1
+ {"district":{"id":1,"code":"SMPL","name":"Sample District","number":"SaMpLeDiStRiCt","state":"CA","city":"Lincoln","zip":96669,"server":{"apiVersion":"2.1.1","portNumber":8080,"serverAddress":"powerschool.example","sslEnabled":false},"validated":true,"remoteAuthDisabled":false,"remoteAuthMsg":""}}
@@ -0,0 +1 @@
1
+ {"district":{"id":1,"code":"SMPL","name":"Sample District","number":"SaMpLeDiStRiCt","state":"CA","city":"Lincoln","zip":96669,"server":{"apiVersion":"2.1.1","portNumber":80,"serverAddress":"powerschool.example","sslEnabled":false},"validated":true,"remoteAuthDisabled":false,"remoteAuthMsg":""}}
@@ -0,0 +1 @@
1
+ {"district":{"id":1,"code":"SMPL","name":"Sample District","number":"SaMpLeDiStRiCt","state":"CA","city":"Lincoln","zip":96669,"server":{"apiVersion":"2.1.1","portNumber":8181,"serverAddress":"powerschool.example","sslEnabled":true},"validated":true,"remoteAuthDisabled":false,"remoteAuthMsg":""}}
@@ -0,0 +1 @@
1
+ {"district":{"id":1,"code":"SMPL","name":"Sample District","number":"SaMpLeDiStRiCt","state":"CA","city":"Lincoln","zip":96669,"server":{"apiVersion":"2.1.1","portNumber":443,"serverAddress":"powerschool.example","sslEnabled":true},"validated":true,"remoteAuthDisabled":false,"remoteAuthMsg":""}}
data/spec/parser_spec.rb CHANGED
@@ -130,13 +130,13 @@ describe PowerAPI::Parser do
130
130
  it "contains a section at index 0" do
131
131
  expect(
132
132
  @sections[0]
133
- ).to be_a(PowerAPI::Section)
133
+ ).to be_a(PowerAPI::Data::Section)
134
134
  end
135
135
 
136
136
  it "contains a section at index 1" do
137
137
  expect(
138
138
  @sections[0]
139
- ).to be_a(PowerAPI::Section)
139
+ ).to be_a(PowerAPI::Data::Section)
140
140
  end
141
141
  end
142
142
 
@@ -31,7 +31,7 @@ describe PowerAPI do
31
31
 
32
32
  expect(
33
33
  PowerAPI.authenticate("http://powerschool.example", "student", "123456", false)
34
- ).to be_an_instance_of(PowerAPI::Student)
34
+ ).to be_an_instance_of(PowerAPI::Data::Student)
35
35
  end
36
36
  end
37
37
 
@@ -48,4 +48,55 @@ describe PowerAPI do
48
48
  ).to eq("https://powerschool.example")
49
49
  end
50
50
  end
51
+
52
+ describe "#district_lookup" do
53
+ it "doesn't find a district" do
54
+ stub_request(:get, /powersource.pearsonschoolsystems.com/).
55
+ to_return(status: 404, body: "", headers: {})
56
+
57
+ expect(
58
+ PowerAPI.district_lookup('SMPL')
59
+ ).to eq(false)
60
+ end
61
+
62
+ it "finds an HTTPS district" do
63
+ fixture = File.read("spec/fixtures/district/https_standard.json")
64
+ stub_request(:get, /powersource.pearsonschoolsystems.com/).
65
+ to_return(status: 200, body: fixture, headers: {})
66
+
67
+ expect(
68
+ PowerAPI.district_lookup('SMPL')
69
+ ).to eq("https://powerschool.example")
70
+ end
71
+
72
+ it "finds an nonstandard HTTPS district" do
73
+ fixture = File.read("spec/fixtures/district/https_nonstandard.json")
74
+ stub_request(:get, /powersource.pearsonschoolsystems.com/).
75
+ to_return(status: 200, body: fixture, headers: {})
76
+
77
+ expect(
78
+ PowerAPI.district_lookup('SMPL')
79
+ ).to eq("https://powerschool.example:8181")
80
+ end
81
+
82
+ it "finds an HTTP district" do
83
+ fixture = File.read("spec/fixtures/district/http_standard.json")
84
+ stub_request(:get, /powersource.pearsonschoolsystems.com/).
85
+ to_return(status: 200, body: fixture, headers: {})
86
+
87
+ expect(
88
+ PowerAPI.district_lookup('SMPL')
89
+ ).to eq("http://powerschool.example")
90
+ end
91
+
92
+ it "finds an nonstandard HTTP district" do
93
+ fixture = File.read("spec/fixtures/district/http_nonstandard.json")
94
+ stub_request(:get, /powersource.pearsonschoolsystems.com/).
95
+ to_return(status: 200, body: fixture, headers: {})
96
+
97
+ expect(
98
+ PowerAPI.district_lookup('SMPL')
99
+ ).to eq("http://powerschool.example:8080")
100
+ end
101
+ end
51
102
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "simplecov"
2
2
 
3
- # Only use Coveralls when being run in CI
3
+ # Only use CodeClimate when being run in CI
4
4
  if ENV["CI"]
5
- require "coveralls"
6
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ require "codeclimate-test-reporter"
6
+ SimpleCov.formatter = CodeClimate::TestReporter::Formatter
7
7
  end
8
8
 
9
9
  SimpleCov.start do
@@ -13,3 +13,6 @@ end
13
13
  require "powerapi"
14
14
 
15
15
  require "savon/mock/spec_helper"
16
+
17
+ require 'webmock/rspec'
18
+ WebMock.disable_net_connect!(:allow => [/localhost/, /codeclimate.com/])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powerapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henri Watson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-31 00:00:00.000000000 Z
11
+ date: 2015-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,21 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: coveralls
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.20.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.20.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - '>='
@@ -136,22 +150,26 @@ files:
136
150
  - README.md
137
151
  - Rakefile
138
152
  - lib/powerapi.rb
139
- - lib/powerapi/assignment.rb
153
+ - lib/powerapi/data/assignment.rb
154
+ - lib/powerapi/data/section.rb
155
+ - lib/powerapi/data/student.rb
140
156
  - lib/powerapi/exception.rb
141
157
  - lib/powerapi/parser.rb
142
- - lib/powerapi/section.rb
143
- - lib/powerapi/student.rb
144
158
  - lib/powerapi/version.rb
145
159
  - powerapi.gemspec
146
- - spec/assignment_spec.rb
160
+ - spec/data_assignment_spec.rb
161
+ - spec/data_section_spec.rb
162
+ - spec/data_student_spec.rb
147
163
  - spec/fixtures/authentication/failure.xml
148
164
  - spec/fixtures/authentication/success.xml
165
+ - spec/fixtures/district/http_nonstandard.json
166
+ - spec/fixtures/district/http_standard.json
167
+ - spec/fixtures/district/https_nonstandard.json
168
+ - spec/fixtures/district/https_standard.json
149
169
  - spec/fixtures/transcript.json
150
170
  - spec/parser_spec.rb
151
171
  - spec/powerapi_spec.rb
152
- - spec/section_spec.rb
153
172
  - spec/spec_helper.rb
154
- - spec/student_spec.rb
155
173
  homepage: http://powerapi.henriwatson.com/
156
174
  licenses:
157
175
  - MIT
@@ -177,12 +195,16 @@ signing_key:
177
195
  specification_version: 4
178
196
  summary: Ruby API for PowerSchool.
179
197
  test_files:
180
- - spec/assignment_spec.rb
198
+ - spec/data_assignment_spec.rb
199
+ - spec/data_section_spec.rb
200
+ - spec/data_student_spec.rb
181
201
  - spec/fixtures/authentication/failure.xml
182
202
  - spec/fixtures/authentication/success.xml
203
+ - spec/fixtures/district/http_nonstandard.json
204
+ - spec/fixtures/district/http_standard.json
205
+ - spec/fixtures/district/https_nonstandard.json
206
+ - spec/fixtures/district/https_standard.json
183
207
  - spec/fixtures/transcript.json
184
208
  - spec/parser_spec.rb
185
209
  - spec/powerapi_spec.rb
186
- - spec/section_spec.rb
187
210
  - spec/spec_helper.rb
188
- - spec/student_spec.rb
@@ -1,27 +0,0 @@
1
- module PowerAPI
2
- class Assignment
3
- def initialize(details)
4
- @details = details
5
- end
6
-
7
- def category
8
- @details[:category]["name"]
9
- end
10
-
11
- def description
12
- @details[:assignment]["description"]
13
- end
14
-
15
- def name
16
- @details[:assignment]["name"]
17
- end
18
-
19
- def percent
20
- @details[:score]["percent"]
21
- end
22
-
23
- def score
24
- @details[:score]["score"]
25
- end
26
- end
27
- end
@@ -1,49 +0,0 @@
1
- module PowerAPI
2
- class Section
3
- def initialize(details)
4
- @details = details
5
-
6
- # Occasionally, a section won't have any final_grades objects
7
- if @details[:final_grades] != nil
8
- @final_grades = {}
9
-
10
- @details[:final_grades].each do |final_grade|
11
- @final_grades[
12
- @details[:reporting_terms][final_grade["reportingTermId"]]
13
- ] = final_grade["percent"]
14
- end
15
- else
16
- @final_grades = nil
17
- end
18
- end
19
-
20
- def assignments
21
- @details[:assignments]
22
- end
23
-
24
- def expression
25
- @details[:section]["expression"]
26
- end
27
-
28
- def final_grades
29
- @final_grades
30
- end
31
-
32
- def name
33
- @details[:section]["schoolCourseTitle"]
34
- end
35
-
36
- def room_name
37
- @details[:section]["roomName"]
38
- end
39
-
40
- def teacher
41
- {
42
- :first_name => @details[:teacher]["firstName"],
43
- :last_name => @details[:teacher]["lastName"],
44
- :email => @details[:teacher]["email"],
45
- :school_phone => @details[:teacher]["schoolPhone"]
46
- }
47
- end
48
- end
49
- end
@@ -1,73 +0,0 @@
1
- module PowerAPI
2
- class Student
3
- def initialize(soap_url, soap_session, populate=true)
4
- @soap_url = soap_url
5
- @soap_session = soap_session
6
-
7
- if populate
8
- self.populate()
9
- end
10
- end
11
-
12
- def populate()
13
- transcript = self.fetch_transcript
14
- self.parse_transcript(transcript)
15
- end
16
-
17
- def fetch_transcript()
18
- student_client = Savon.client(
19
- endpoint: @soap_url + "/pearson-rest/services/PublicPortalServiceJSON?response=application/json",
20
- namespace: "http://publicportal.rest.powerschool.pearson.com/xsd",
21
- digest_auth: ["pearson", "m0bApP5"]
22
- )
23
-
24
- transcript_params = {
25
- userSessionVO: {
26
- userId: @soap_session[:user_id],
27
- serviceTicket: @soap_session[:service_ticket],
28
- serverInfo: {
29
- apiVersion: @soap_session[:server_info][:api_version]
30
- },
31
- serverCurrentTime: "2012-12-26T21:47:23.792Z", # I really don't know.
32
- userType: "2"
33
- },
34
- studentIDs: @soap_session[:student_i_ds],
35
- qil: {
36
- includes: "1"
37
- }
38
- }
39
-
40
- transcript = student_client.call(:get_student_data, message: transcript_params).to_xml
41
-
42
- JSON.parse(transcript)
43
- end
44
-
45
- def parse_transcript(transcript)
46
- @student_data = transcript["return"]["studentDataVOs"]
47
-
48
- @student_data["student"].delete("@type")
49
-
50
- assignment_categories = PowerAPI::Parser.assignment_categories(@student_data["assignmentCategories"])
51
- assignment_scores = PowerAPI::Parser.assignment_scores(@student_data["assignmentScores"])
52
- final_grades = PowerAPI::Parser.final_grades(@student_data["finalGrades"])
53
- reporting_terms = PowerAPI::Parser.reporting_terms(@student_data["reportingTerms"])
54
- teachers = PowerAPI::Parser.teachers(@student_data["teachers"])
55
-
56
- assignments = PowerAPI::Parser.assignments(@student_data["assignments"], assignment_categories, assignment_scores)
57
-
58
- @sections = PowerAPI::Parser.sections(@student_data["sections"], assignments, final_grades, reporting_terms, teachers)
59
-
60
- return 0
61
- end
62
-
63
- def sections
64
- @sections
65
- end
66
-
67
- def information
68
- if @student_data != nil
69
- @student_data["student"]
70
- end
71
- end
72
- end
73
- end