Skip to content

Commit 06dbdf7

Browse files
add source code
1 parent dd018ad commit 06dbdf7

30 files changed

+1837
-1
lines changed

.github/workflows/build.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: macos-latest
12+
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v3
16+
17+
- name: Build
18+
run: swift build -v

.github/workflows/swiftlint.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: SwiftLint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
workflow_dispatch:
8+
9+
jobs:
10+
swiftlint:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Check out repository
15+
uses: actions/checkout@v3
16+
17+
- name: SwiftLint
18+
uses: norio-nomura/[email protected]
19+
with:
20+
args: --strict

.swiftlint.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
included:
2+
- Sources
3+
- ./Package.swift
4+
disabled_rules:
5+
todo
6+
line_length:
7+
warning: 170
8+
ignores_urls: true
9+
ignores_function_declarations: true
10+
ignores_comments: true
11+
ignores_interpolated_strings: true
12+

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1430"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "StudentVue"
18+
BuildableName = "StudentVue"
19+
BlueprintName = "StudentVue"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "NO"
27+
buildForArchiving = "NO"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "StudentVueTests"
32+
BuildableName = "StudentVueTests"
33+
BlueprintName = "StudentVueTests"
34+
ReferencedContainer = "container:">
35+
</BuildableReference>
36+
</BuildActionEntry>
37+
</BuildActionEntries>
38+
</BuildAction>
39+
<TestAction
40+
buildConfiguration = "Debug"
41+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
42+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
shouldUseLaunchSchemeArgsEnv = "YES"
44+
shouldAutocreateTestPlan = "YES">
45+
<Testables>
46+
<TestableReference
47+
skipped = "NO">
48+
<BuildableReference
49+
BuildableIdentifier = "primary"
50+
BlueprintIdentifier = "StudentVueTests"
51+
BuildableName = "StudentVueTests"
52+
BlueprintName = "StudentVueTests"
53+
ReferencedContainer = "container:">
54+
</BuildableReference>
55+
</TestableReference>
56+
</Testables>
57+
</TestAction>
58+
<LaunchAction
59+
buildConfiguration = "Debug"
60+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
61+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
62+
launchStyle = "0"
63+
useCustomWorkingDirectory = "NO"
64+
ignoresPersistentStateOnLaunch = "NO"
65+
debugDocumentVersioning = "YES"
66+
debugServiceExtension = "internal"
67+
allowLocationSimulation = "YES">
68+
</LaunchAction>
69+
<ProfileAction
70+
buildConfiguration = "Release"
71+
shouldUseLaunchSchemeArgsEnv = "YES"
72+
savedToolIdentifier = ""
73+
useCustomWorkingDirectory = "NO"
74+
debugDocumentVersioning = "YES">
75+
<MacroExpansion>
76+
<BuildableReference
77+
BuildableIdentifier = "primary"
78+
BlueprintIdentifier = "StudentVue"
79+
BuildableName = "StudentVue"
80+
BlueprintName = "StudentVue"
81+
ReferencedContainer = "container:">
82+
</BuildableReference>
83+
</MacroExpansion>
84+
</ProfileAction>
85+
<AnalyzeAction
86+
buildConfiguration = "Debug">
87+
</AnalyzeAction>
88+
<ArchiveAction
89+
buildConfiguration = "Release"
90+
revealArchiveInOrganizer = "YES">
91+
</ArchiveAction>
92+
</Scheme>

Package.resolved

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "swxmlhash",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/drmohundro/SWXMLHash",
7+
"state" : {
8+
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
9+
"version" : "7.0.1"
10+
}
11+
}
12+
],
13+
"version" : 2
14+
}

Package.swift

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version: 5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "StudentVue",
8+
platforms: [
9+
.iOS(.v13),
10+
.macOS(.v13)
11+
],
12+
products: [
13+
.library(
14+
name: "StudentVue",
15+
targets: ["StudentVue"])
16+
],
17+
dependencies: [
18+
.package(url: "https://github.com/drmohundro/SWXMLHash", from: "7.0.1")
19+
],
20+
targets: [
21+
.target(
22+
name: "StudentVue",
23+
dependencies: [
24+
"SWXMLHash"
25+
])
26+
],
27+
swiftLanguageVersions: [.v5]
28+
)

README.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
11
# StudentVue.swift
2-
Swift StudentVue library
2+
3+
![Supported Platforms](https://img.shields.io/badge/platform-ios%20%7C%20macos-lightgrey.svg?style=flat)
4+
[![MIT](https://img.shields.io/github/license/TheMoonThatRises/StudentVue.swift.svg?style=flat)](https://github.com/TheMoonThatRises/StudentVue.swift)
5+
6+
Swift library for interacting with StudentVue's api. This project was heavily influenced by [StudentVue.js](https://github.com/StudentVue/StudentVue.js) and relied on information provided by their [documentation](https://github.com/StudentVue/docs). This library is still a work in progress and if you encounter an issue, feel free to create an [issue](https://github.com/TheMoonThatRises/StudentVue.swift/issues/new) or submit a [pull request](https://github.com/TheMoonThatRises/StudentVue.swift/pulls).
7+
8+
## Installation
9+
10+
```swift
11+
.package(url: "https://github.com/TheMoonThatRises/StudentVue.swift", from: "0.0.1")
12+
```
13+
14+
## Basic usage
15+
16+
### Logging in as a student
17+
18+
To create a client instance, use
19+
20+
```swift
21+
import StudentVue
22+
23+
let client = StudentVue(domain: "something.edupoint.com", username: "123456789", password: "password")
24+
```
25+
26+
With the client initialized, you can access information by using the provided functions such as `getGradeBook`, `getClassSchedule`, `getSchoolInfo`, and many more. If one of the functions fails to parse or you want to access information in which a data structure is not created, you can call the `makeServiceRequest` and parse the XML manually.
27+
28+
```swift
29+
let gradebook = client.getGradeBook()
30+
```
31+
32+
### Static functions
33+
34+
For some functions, logging in is not required, such as getting district zip codes
35+
36+
```swift
37+
38+
import StudentVue
39+
40+
let districts = StudentVue.getDistricts(zip: "a zip code")
41+
```
42+
43+
## Todo List
44+
45+
- [ ] A website for documentation
46+
- [ ] More complete structures for returned data
47+
- [ ] Use the WSDL file to help with the data structure
48+
- [ ] Use a proper SOAP handler instead of the "hacky" solution
49+
50+
## Library Used
51+
52+
- [SWXMLHash](https://github.com/drmohundro/SWXMLHash)

Sources/StudentVue/Errors.swift

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Errors.swift
3+
//
4+
//
5+
// Created by TheMoonThatRises on 4/11/23.
6+
//
7+
8+
import Foundation
9+
10+
enum StudentVueErrors: LocalizedError {
11+
case unreachableURL(String)
12+
case emptyResponse
13+
case clientNotIntialised
14+
case soapError(String)
15+
}
16+
17+
extension StudentVueErrors {
18+
var errorDescription: String? {
19+
switch self {
20+
case .unreachableURL(let string):
21+
return "Unable to reach domain: \(string)"
22+
case .emptyResponse:
23+
return "Empty response body"
24+
case .clientNotIntialised:
25+
return "StudentVue client has not been created"
26+
case .soapError(let string):
27+
return "Soap request returned error: \(string)"
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Date+deserialize.swift
3+
//
4+
//
5+
// Created by TheMoonThatRises on 4/12/23.
6+
//
7+
8+
import Foundation
9+
import SWXMLHash
10+
11+
extension Date: XMLValueDeserialization {
12+
/// Allows for deserialization of dates from an XML element
13+
///
14+
/// - Parameter element: XMLElement where the date is parsed
15+
///
16+
/// - Throws: `XMLDeserializationError.typeConversionFailed` Unable to convert XMLElement to Date
17+
///
18+
/// - Returns: Date converted from XMLElement
19+
public static func deserialize(_ element: XMLHash.XMLElement) throws -> Date {
20+
let date = stringToDate(element.text)
21+
22+
guard let validDate = date else {
23+
throw XMLDeserializationError.typeConversionFailed(type: "Date", element: element)
24+
}
25+
26+
return validDate
27+
}
28+
29+
/// Allows for deserialization of dates from an XML attribute
30+
///
31+
/// - Parameter attribute: XMLAttribute where the date is parsed
32+
///
33+
/// - Throws: `XMLDeserializationError.typeConversionFailed` Unable to convert XMLAttribute to Date
34+
///
35+
/// - Returns: Date converted from XMLAttribute
36+
public static func deserialize(_ attribute: XMLAttribute) throws -> Date {
37+
let date = stringToDate(attribute.text)
38+
39+
guard let validDate = date else {
40+
throw XMLDeserializationError.attributeDeserializationFailed(type: "Date", attribute: attribute)
41+
}
42+
43+
return validDate
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by TheMoonThatRises on 4/16/23.
6+
//
7+
8+
import Foundation
9+
import SWXMLHash
10+
11+
extension Date {
12+
/// Formats of dates StudentVue returns
13+
private static let decodeDateFormats = ["MM/dd/yy", "MM/dd/yy HH:mm:ss", "MM/dd/yy HH:mm:ss a", "yyyy-MM-dd'T'HH:mm:ss", "HH:mm a"]
14+
15+
/// Converts String to Date using a defined array of date formats
16+
///
17+
/// - Parameter dateAsString: The date to be converted as a string
18+
///
19+
/// - Returns: Date converted from a string
20+
public static func stringToDate(_ dateAsString: String) -> Date? {
21+
let dateFormatter = DateFormatter()
22+
23+
for format in decodeDateFormats {
24+
dateFormatter.dateFormat = format
25+
26+
if let formatted = dateFormatter.date(from: dateAsString) {
27+
return formatted
28+
}
29+
}
30+
31+
return nil
32+
}
33+
}

0 commit comments

Comments
 (0)