Skip to content

Commit

Permalink
add source code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMoonThatRises committed Apr 19, 2023
1 parent dd018ad commit 06dbdf7
Show file tree
Hide file tree
Showing 30 changed files with 1,837 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build

on:
push:
pull_request:

workflow_dispatch:

jobs:
build:
runs-on: macos-latest

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Build
run: swift build -v
20 changes: 20 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: SwiftLint

on:
push:
pull_request:

workflow_dispatch:

jobs:
swiftlint:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v3

- name: SwiftLint
uses: norio-nomura/[email protected]
with:
args: --strict
12 changes: 12 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
included:
- Sources
- ./Package.swift
disabled_rules:
todo
line_length:
warning: 170
ignores_urls: true
ignores_function_declarations: true
ignores_comments: true
ignores_interpolated_strings: true

7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>
<true/>
</dict>
</plist>
92 changes: 92 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/StudentVue.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StudentVue"
BuildableName = "StudentVue"
BlueprintName = "StudentVue"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StudentVueTests"
BuildableName = "StudentVueTests"
BlueprintName = "StudentVueTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StudentVueTests"
BuildableName = "StudentVueTests"
BlueprintName = "StudentVueTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "StudentVue"
BuildableName = "StudentVue"
BlueprintName = "StudentVue"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash",
"state" : {
"revision" : "4d0f62f561458cbe1f732171e625f03195151b60",
"version" : "7.0.1"
}
}
],
"version" : 2
}
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "StudentVue",
platforms: [
.iOS(.v13),
.macOS(.v13)
],
products: [
.library(
name: "StudentVue",
targets: ["StudentVue"])
],
dependencies: [
.package(url: "https://github.com/drmohundro/SWXMLHash", from: "7.0.1")
],
targets: [
.target(
name: "StudentVue",
dependencies: [
"SWXMLHash"
])
],
swiftLanguageVersions: [.v5]
)
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# StudentVue.swift
Swift StudentVue library

![Supported Platforms](https://img.shields.io/badge/platform-ios%20%7C%20macos-lightgrey.svg?style=flat)
[![MIT](https://img.shields.io/github/license/TheMoonThatRises/StudentVue.swift.svg?style=flat)](https://github.com/TheMoonThatRises/StudentVue.swift)

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).

## Installation

```swift
.package(url: "https://github.com/TheMoonThatRises/StudentVue.swift", from: "0.0.1")
```

## Basic usage

### Logging in as a student

To create a client instance, use

```swift
import StudentVue

let client = StudentVue(domain: "something.edupoint.com", username: "123456789", password: "password")
```

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.

```swift
let gradebook = client.getGradeBook()
```

### Static functions

For some functions, logging in is not required, such as getting district zip codes

```swift

import StudentVue

let districts = StudentVue.getDistricts(zip: "a zip code")
```

## Todo List

- [ ] A website for documentation
- [ ] More complete structures for returned data
- [ ] Use the WSDL file to help with the data structure
- [ ] Use a proper SOAP handler instead of the "hacky" solution

## Library Used

- [SWXMLHash](https://github.com/drmohundro/SWXMLHash)
30 changes: 30 additions & 0 deletions Sources/StudentVue/Errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Errors.swift
//
//
// Created by TheMoonThatRises on 4/11/23.
//

import Foundation

enum StudentVueErrors: LocalizedError {
case unreachableURL(String)
case emptyResponse
case clientNotIntialised
case soapError(String)
}

extension StudentVueErrors {
var errorDescription: String? {
switch self {
case .unreachableURL(let string):
return "Unable to reach domain: \(string)"
case .emptyResponse:
return "Empty response body"
case .clientNotIntialised:
return "StudentVue client has not been created"
case .soapError(let string):
return "Soap request returned error: \(string)"
}
}
}
45 changes: 45 additions & 0 deletions Sources/StudentVue/Extensions/Date+deserialize.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Date+deserialize.swift
//
//
// Created by TheMoonThatRises on 4/12/23.
//

import Foundation
import SWXMLHash

extension Date: XMLValueDeserialization {
/// Allows for deserialization of dates from an XML element
///
/// - Parameter element: XMLElement where the date is parsed
///
/// - Throws: `XMLDeserializationError.typeConversionFailed` Unable to convert XMLElement to Date
///
/// - Returns: Date converted from XMLElement
public static func deserialize(_ element: XMLHash.XMLElement) throws -> Date {
let date = stringToDate(element.text)

guard let validDate = date else {
throw XMLDeserializationError.typeConversionFailed(type: "Date", element: element)
}

return validDate
}

/// Allows for deserialization of dates from an XML attribute
///
/// - Parameter attribute: XMLAttribute where the date is parsed
///
/// - Throws: `XMLDeserializationError.typeConversionFailed` Unable to convert XMLAttribute to Date
///
/// - Returns: Date converted from XMLAttribute
public static func deserialize(_ attribute: XMLAttribute) throws -> Date {
let date = stringToDate(attribute.text)

guard let validDate = date else {
throw XMLDeserializationError.attributeDeserializationFailed(type: "Date", attribute: attribute)
}

return validDate
}
}
33 changes: 33 additions & 0 deletions Sources/StudentVue/Extensions/Date+stringToDate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// File.swift
//
//
// Created by TheMoonThatRises on 4/16/23.
//

import Foundation
import SWXMLHash

extension Date {
/// Formats of dates StudentVue returns
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"]

/// Converts String to Date using a defined array of date formats
///
/// - Parameter dateAsString: The date to be converted as a string
///
/// - Returns: Date converted from a string
public static func stringToDate(_ dateAsString: String) -> Date? {
let dateFormatter = DateFormatter()

for format in decodeDateFormats {
dateFormatter.dateFormat = format

if let formatted = dateFormatter.date(from: dateAsString) {
return formatted
}
}

return nil
}
}
Loading

0 comments on commit 06dbdf7

Please sign in to comment.