Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
whats-open-ios
Commits
ceb47a47
Commit
ceb47a47
authored
Sep 05, 2017
by
Eyad Hasan
Browse files
Added an object for our special schedules
parent
fbe27cce
Changes
2
Hide whitespace changes
Inline
Side-by-side
WhatsOpen/WhatsOpen/Object Model/examplejson.swift
View file @
ceb47a47
...
...
@@ -15,6 +15,7 @@ class Facility: Object {
dynamic
var
category
=
Categories
()
let
facilityTags
=
List
<
FacilityTags
>
()
dynamic
var
mainSchedule
=
MainSchedule
()
dynamic
var
specialSchedule
=
SpecialSchedule
()
...
...
@@ -56,6 +57,18 @@ class MainSchedule: Object {
}
class
SpecialSchedule
:
Object
{
dynamic
var
id
=
0
let
openTimes
=
List
<
OpenTimes
>
()
dynamic
var
lastModified
=
""
dynamic
var
name
=
""
dynamic
var
validStart
=
""
dynamic
var
validEnd
=
""
dynamic
var
twentyFourHours
=
false
}
class
OpenTimes
:
Object
{
dynamic
var
schedule
=
0
dynamic
var
lastModified
=
""
...
...
@@ -66,6 +79,8 @@ class OpenTimes: Object {
}
/**struct OpenTimes: CreatableFromJSON { // TODO: Rename this struct
let endDay: Int
let endTime: Date
...
...
WhatsOpen/WhatsOpen/SRCTNetworkController.swift
View file @
ceb47a47
...
...
@@ -8,11 +8,14 @@
import
UIKit
import
Foundation
import
RealmSwift
class
SRCTNetworkController
:
NSObject
{
//Use this for testing with the new API, might make it possible to get stuff moving pre official release
//https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json
public
static
func
performDownload
(
completion
:
@escaping
(
_
result
:
Array
<
Facility
>
)
->
Void
)
{
let
realm
=
try!
Realm
()
let
requestURL
:
NSURL
=
NSURL
(
string
:
"https://api.srct.gmu.edu/whatsopen/v2/facilities/?format=json"
)
!
let
urlRequest
:
NSMutableURLRequest
=
NSMutableURLRequest
(
url
:
requestURL
as
URL
)
let
session
=
URLSession
.
shared
...
...
@@ -27,15 +30,13 @@ class SRCTNetworkController: NSObject {
//var schedules = Array
//Finish this, and fix the function
try!
realm
.
write
{
let
json
=
try
?
JSONSerialization
.
jsonObject
(
with
:
dataN
,
options
:
[])
if
let
schedule
=
json
as?
[
String
:
Any
]{
if
let
currentSchedule
=
schedule
[
"main_schedule"
]
as?
Array
{
schedule
.
append
(
currentSchedule
)
}
realm
.
create
(
Facility
.
self
,
value
:
json
!
,
update
:
true
)
}
}
...
...
@@ -45,7 +46,7 @@ class SRCTNetworkController: NSObject {
}
print
(
schedules
)
print
(
Facility
.
self
)
task
.
resume
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment