Skip to content

Commit 30454fc

Browse files
Not quite there..
1 parent c022936 commit 30454fc

18 files changed

+158
-330
lines changed

Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ end
2525
target 'TodaysReactiveMenuWatch Extension' do
2626
platform :watchos, '2.0'
2727

28-
shared_pods
28+
#shared_pods
2929
end

Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ SPEC CHECKSUMS:
3535
Result: caef80340451e1f07492fa1e89117f83613bce24
3636
Unbox: af6e75fddb73ee790c80114bf7b6edef56a0dcd8
3737

38-
PODFILE CHECKSUM: 460989c6e469c36b41a979594279a9baf138d00c
38+
PODFILE CHECKSUM: 88d712ec84df97988fafe5fd9b2bc48abd1a925e
3939

40-
COCOAPODS: 1.0.0.beta.2
40+
COCOAPODS: 1.0.0.beta.3

TodaysReactiveMenu.xcodeproj/project.pbxproj

-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
3A29EB401BB828B10053207C /* ComplicationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A29EB3F1BB828B10053207C /* ComplicationController.swift */; };
1919
3A29EB421BB828B10053207C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3A29EB411BB828B10053207C /* Assets.xcassets */; };
2020
3A29EB461BB828B10053207C /* TodaysReactiveMenuWatch.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 3A29EB241BB828B10053207C /* TodaysReactiveMenuWatch.app */; };
21-
3A3F776F1C57DF9F003AE95E /* Formattable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A492DC61C57D87F0017209A /* Formattable.swift */; };
22-
3A3F77701C57DFA2003AE95E /* Archivable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A492DC41C57D72E0017209A /* Archivable.swift */; };
2321
3A492DC51C57D72E0017209A /* Archivable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A492DC41C57D72E0017209A /* Archivable.swift */; };
2422
3A492DC71C57D87F0017209A /* Formattable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A492DC61C57D87F0017209A /* Formattable.swift */; };
2523
3A4C49C71C552FF50002FC01 /* MenuService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A7B52741B13071100C0F539 /* MenuService.swift */; };
@@ -30,17 +28,14 @@
3028
3A7B52791B13071D00C0F539 /* UIKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A7B52781B13071D00C0F539 /* UIKitExtensions.swift */; };
3129
3A7B527B1B13072900C0F539 /* TodaysMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A7B527A1B13072900C0F539 /* TodaysMenuViewController.swift */; };
3230
3A7B527D1B13073000C0F539 /* TodaysMenuViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A7B527C1B13073000C0F539 /* TodaysMenuViewModel.swift */; };
33-
3A80207B1B602AD200AED403 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3A80207A1B602AD200AED403 /* GoogleService-Info.plist */; };
3431
3A9912921BBC4F1A0064777E /* WatchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A9912911BBC4F1A0064777E /* WatchService.swift */; };
3532
3AB0EE8F1B120DCD0065C13F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB0EE8E1B120DCD0065C13F /* AppDelegate.swift */; };
3633
3AB0EE961B120DCD0065C13F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3AB0EE951B120DCD0065C13F /* Images.xcassets */; };
3734
3AB0EE991B120DCD0065C13F /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3AB0EE971B120DCD0065C13F /* LaunchScreen.xib */; };
3835
3AB0EEA51B120DCD0065C13F /* TodaysReactiveMenuTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AB0EEA41B120DCD0065C13F /* TodaysReactiveMenuTests.swift */; };
3936
3ABD432C1BE2AD3900B13DC8 /* PhoneService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3ABD432B1BE2AD3900B13DC8 /* PhoneService.swift */; };
4037
3AC7ACF31BE0A605000149DF /* MenuStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC7ACF21BE0A605000149DF /* MenuStorage.swift */; };
41-
3AC7ACF51BE0A886000149DF /* Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A7B52721B1306FF00C0F539 /* Menu.swift */; };
4238
3AC7C2AD1C593F61008A4B3F /* RemoteResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC7C2AC1C593F61008A4B3F /* RemoteResource.swift */; };
43-
3AC7C2AE1C594E90008A4B3F /* RemoteResource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AC7C2AC1C593F61008A4B3F /* RemoteResource.swift */; };
4439
55F0E732BC11408D70458C55 /* Pods_TodaysReactiveMenuTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5AEB36F9D95371D2F64BFCE3 /* Pods_TodaysReactiveMenuTests.framework */; };
4540
CD993281339459990EDD4A2A /* Pods_TodaysReactiveMenu.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BE023256D3802D1984B7F121 /* Pods_TodaysReactiveMenu.framework */; };
4641
/* End PBXBuildFile section */
@@ -534,7 +529,6 @@
534529
files = (
535530
3AB0EE991B120DCD0065C13F /* LaunchScreen.xib in Resources */,
536531
3AB0EE961B120DCD0065C13F /* Images.xcassets in Resources */,
537-
3A80207B1B602AD200AED403 /* GoogleService-Info.plist in Resources */,
538532
);
539533
runOnlyForDeploymentPostprocessing = 0;
540534
};
@@ -708,16 +702,12 @@
708702
3ABD432C1BE2AD3900B13DC8 /* PhoneService.swift in Sources */,
709703
3AC7ACF31BE0A605000149DF /* MenuStorage.swift in Sources */,
710704
3A29EB3C1BB828B10053207C /* NotificationController.swift in Sources */,
711-
3AC7ACF51BE0A886000149DF /* Menu.swift in Sources */,
712-
3A3F77701C57DFA2003AE95E /* Archivable.swift in Sources */,
713705
3A29EB3A1BB828B10053207C /* ExtensionDelegate.swift in Sources */,
714706
3A29EB401BB828B10053207C /* ComplicationController.swift in Sources */,
715707
3A29EB381BB828B10053207C /* InterfaceController.swift in Sources */,
716708
3A6C4D6A1C55174E00346F3B /* WatchService.swift in Sources */,
717-
3A3F776F1C57DF9F003AE95E /* Formattable.swift in Sources */,
718709
3A4C49C71C552FF50002FC01 /* MenuService.swift in Sources */,
719710
3A29EB3E1BB828B10053207C /* GlanceController.swift in Sources */,
720-
3AC7C2AE1C594E90008A4B3F /* RemoteResource.swift in Sources */,
721711
);
722712
runOnlyForDeploymentPostprocessing = 0;
723713
};

TodaysReactiveMenu.xcworkspace/xcshareddata/xcschemes/TodaysReactiveMenu.xcscheme

-101
This file was deleted.

TodaysReactiveMenu.xcworkspace/xcshareddata/xcschemes/TodaysReactiveMenuTests.xcscheme

-56
This file was deleted.

TodaysReactiveMenu/GoogleService-Info.plist

-24
This file was deleted.

TodaysReactiveMenu/Model/Archivable.swift

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extension Archivable where Self: Formattable {
4848
return
4949
}
5050

51+
print("menu loaded")
5152
observer.sendNext(data)
5253
observer.sendCompleted()
5354
}

TodaysReactiveMenu/Model/Menu.swift

+71-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,68 @@ final class Menu: Unboxable, Archivable, Formattable {
2929
}
3030

3131

32+
// MARK: - Helpers -
33+
34+
extension Menu {
35+
36+
private func dateFormatter() -> NSDateFormatter {
37+
let dateFormatter = NSDateFormatter()
38+
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
39+
return dateFormatter
40+
}
41+
42+
enum FetchMenuError: ErrorType {
43+
case UnknownError
44+
case APIError
45+
case CacheError
46+
}
47+
48+
static func fetchTodaysMenuFromCacheOrRemote(menuAPI: RemoteAPI) -> SignalProducer<Menu, FetchMenuError> {
49+
50+
let cacheSharedIdentifier = "menu"
51+
52+
// Download latest menu and deserialize into a menu instance.
53+
let fetchMenuFromRemote = menuAPI.latestMenu()
54+
.mapError { _ in
55+
return FetchMenuError.APIError
56+
}
57+
.flatMap(.Latest) { JSON in
58+
return Menu.deserializeFromJSON(JSON)
59+
.mapError { error in
60+
return FetchMenuError.APIError
61+
}
62+
}
63+
64+
let fetchMenuFromCache = Menu.loadUsingIdentifier(cacheSharedIdentifier)
65+
.mapError { _ in
66+
return FetchMenuError.CacheError
67+
}
68+
69+
let fetchMenuFromCacheOrRemote = fetchMenuFromCache
70+
.flatMap(.Latest) { menu in
71+
return menu.isTodaysMenu() ? SignalProducer<Menu, FetchMenuError>(value: menu) : fetchMenuFromRemote
72+
}
73+
.flatMapError { error in
74+
return (error == FetchMenuError.CacheError) ? fetchMenuFromRemote : SignalProducer<Menu, FetchMenuError>(error: error)
75+
}
76+
77+
return fetchMenuFromCacheOrRemote
78+
.flatMap(.Latest) { menu in
79+
return menu.saveUsingIdentifier(cacheSharedIdentifier)
80+
.map { _ in
81+
return menu
82+
}
83+
.flatMapError { _ in
84+
return SignalProducer<Menu, FetchMenuError>(value: menu)
85+
}
86+
}
87+
}
88+
89+
}
90+
91+
92+
// MARK: - Unboxable extension -
93+
3294
extension Menu {
3395

3496
// Unbox extension.
@@ -41,7 +103,13 @@ extension Menu {
41103
self.servedAt = unboxer.unbox("serving_date", formatter: self.dateFormatter())
42104
}
43105

44-
// Formattable extension
106+
}
107+
108+
109+
// MARK: - Formattable extension -
110+
111+
extension Menu {
112+
45113
func serialize() -> SignalProducer<[String: AnyObject], FormattableError> {
46114
return SignalProducer<[String: AnyObject], FormattableError>(value: [
47115
"link": self.link,
@@ -52,10 +120,5 @@ extension Menu {
52120
])
53121
}
54122

55-
private func dateFormatter() -> NSDateFormatter {
56-
let dateFormatter = NSDateFormatter()
57-
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
58-
return dateFormatter
59-
}
60-
61-
}
123+
}
124+

TodaysReactiveMenu/Model/RemoteResource.swift

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct TodaysMenuAPI: RemoteAPI {
4646
return
4747
}
4848

49+
print("menu downloaded")
4950
observer.sendNext(JSON.first!)
5051
observer.sendCompleted()
5152

TodaysReactiveMenu/Service/MenuService.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Copyright (c) 2015 steffendsommer. All rights reserved.
77
//
88

9-
import ReactiveCocoa
10-
import Alamofire
11-
import Unbox
9+
//import ReactiveCocoa
10+
//import Alamofire
11+
//import Unbox
1212

1313

1414
//#if DEBUG

TodaysReactiveMenu/Service/WatchService.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WatchService: NSObject, WCSessionDelegate {
2323
}
2424
}
2525

26-
func sendMenu(menu: Menu) {
26+
// func sendMenu(menu: Menu) {
2727

2828
// // Make sure that the session is up and running.
2929
// if (sessionStarted) {
@@ -35,6 +35,6 @@ class WatchService: NSObject, WCSessionDelegate {
3535
// }
3636
// }
3737

38-
}
38+
// }
3939

4040
}

0 commit comments

Comments
 (0)