Skip to content

Commit d2d1284

Browse files
committed
Merge branch 'feature/data-request-result' into develop
2 parents a4736eb + e2fcc9a commit d2d1284

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+147
-67
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ cache:
77
- Pods
88
before_install:
99
- export LANG=en_US.UTF-8
10-
- rvm get head
11-
- brew update
1210
- brew tap homebrew/bundle
1311
- brew bundle
1412
install:
@@ -19,7 +17,6 @@ before_script:
1917
script:
2018
- bundle exec scan
2119
after_success:
22-
- make coverage
2320
- bash <(curl -s https://codecov.io/bash)
2421
notifications:
2522
email: false

iCookTV.xcodeproj/project.pbxproj

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
B543C3EF1CD1FD0B008C512B /* GroundControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B543C3EE1CD1FD0B008C512B /* GroundControl.swift */; };
3434
B543C3F11CD21530008C512B /* Tracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = B543C3F01CD21530008C512B /* Tracker.swift */; };
3535
B543C3F31CD34419008C512B /* Video+PlayerItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B543C3F21CD34419008C512B /* Video+PlayerItem.swift */; };
36+
B546053A1DDB482A00208D37 /* DataRequest+Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = B54605391DDB482A00208D37 /* DataRequest+Result.swift */; };
3637
B5501BE31CD74206001C3281 /* TrackableNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5501BE21CD74206001C3281 /* TrackableNavigationController.swift */; };
3738
B5501BE91CD8ACEC001C3281 /* Trackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5501BE81CD8ACEC001C3281 /* Trackable.swift */; };
3839
B55BF7E71DC5B7F400EE20BD /* Reusable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B55BF7E61DC5B7F400EE20BD /* Reusable.swift */; };
@@ -111,6 +112,7 @@
111112
B543C3EE1CD1FD0B008C512B /* GroundControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroundControl.swift; sourceTree = "<group>"; };
112113
B543C3F01CD21530008C512B /* Tracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tracker.swift; sourceTree = "<group>"; };
113114
B543C3F21CD34419008C512B /* Video+PlayerItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Video+PlayerItem.swift"; sourceTree = "<group>"; };
115+
B54605391DDB482A00208D37 /* DataRequest+Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DataRequest+Result.swift"; sourceTree = "<group>"; };
114116
B5501BE21CD74206001C3281 /* TrackableNavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TrackableNavigationController.swift; sourceTree = "<group>"; };
115117
B5501BE81CD8ACEC001C3281 /* Trackable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Trackable.swift; sourceTree = "<group>"; };
116118
B55BF7E61DC5B7F400EE20BD /* Reusable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reusable.swift; sourceTree = "<group>"; };
@@ -183,34 +185,33 @@
183185
name = Frameworks;
184186
sourceTree = "<group>";
185187
};
186-
B53E39791CA1494600EB1EEE /* Extension */ = {
188+
B53E39791CA1494600EB1EEE /* Extensions */ = {
187189
isa = PBXGroup;
188190
children = (
189191
B52EC3B01CB26F1B0072762C /* CGRect+Grid.swift */,
192+
B54605391DDB482A00208D37 /* DataRequest+Result.swift */,
190193
B53E39771CA1494000EB1EEE /* UIColor+TV.swift */,
191194
B52EC3B21CB3A02E0072762C /* UIFont+TV.swift */,
192195
B5C85D031CA97981000AE0CF /* UIImage+Grid.swift */,
193196
B56D0E251CBC0C1900B92F73 /* UIViewController+Alert.swift */,
194197
B543C3F21CD34419008C512B /* Video+PlayerItem.swift */,
195198
);
196-
name = Extension;
199+
path = Extensions;
197200
sourceTree = "<group>";
198201
};
199-
B543C3EB1CD1E93B008C512B /* Protocol */ = {
202+
B543C3EB1CD1E93B008C512B /* Protocols */ = {
200203
isa = PBXGroup;
201204
children = (
202205
B5C79B151DBFBCF80069837A /* BlurBackgroundPresentable.swift */,
203-
B52BD6741D5F94320023D4E9 /* DataCollection.swift */,
204206
B5EE174F1DC509B8009DA1AE /* DataFetching.swift */,
205207
B55BF7E81DC5C3C400EE20BD /* DropdownMenuPresentable.swift */,
206208
B50A202A1DC4B53C00ACBF1B /* LoadingIndicatorPresentable.swift */,
207209
B543C3E91CD1E85E008C512B /* OverlayViewPresentable.swift */,
208210
B55BF7E61DC5B7F400EE20BD /* Reusable.swift */,
209-
B516E78A1D54D73B00A3FCB9 /* SourceType.swift */,
210211
B5501BE81CD8ACEC001C3281 /* Trackable.swift */,
211212
B5EFE6C11DC600FF00236D1A /* VideosGridLayout.swift */,
212213
);
213-
name = Protocol;
214+
path = Protocols;
214215
sourceTree = "<group>";
215216
};
216217
B5761A541CCF555D008CCC08 /* Supporting Files */ = {
@@ -234,38 +235,40 @@
234235
name = "Supporting Files";
235236
sourceTree = "<group>";
236237
};
237-
B5A614FD1CCA0884004A3CD5 /* Classes */ = {
238+
B5A614FD1CCA0884004A3CD5 /* Sources */ = {
238239
isa = PBXGroup;
239240
children = (
240-
B5AAAE5D1C85DD1D002DDFC8 /* Controller */,
241-
B53E39791CA1494600EB1EEE /* Extension */,
242-
B5D036581D54E96900B80CFC /* Helper */,
243-
B5AAAE5B1C85DD0A002DDFC8 /* Model */,
244-
B543C3EB1CD1E93B008C512B /* Protocol */,
245-
B5AAAE5C1C85DD16002DDFC8 /* View */,
241+
B5AAAE5D1C85DD1D002DDFC8 /* Controllers */,
242+
B53E39791CA1494600EB1EEE /* Extensions */,
243+
B5D036581D54E96900B80CFC /* Helpers */,
244+
B5AAAE5B1C85DD0A002DDFC8 /* Models */,
245+
B543C3EB1CD1E93B008C512B /* Protocols */,
246+
B5AAAE5C1C85DD16002DDFC8 /* Views */,
246247
B5F7BF4B1BA9C95F00A75099 /* AppDelegate.swift */,
247248
B50BFC041CC88FA3004F853D /* Debug.swift */,
248249
B51A95381CCF1C5100E5ED97 /* iCookTVKeys.swift */,
249250
B5AEEE311C82D4BC001CF112 /* Metrics.swift */,
250251
);
251-
name = Classes;
252+
name = Sources;
252253
sourceTree = "<group>";
253254
};
254-
B5AAAE5B1C85DD0A002DDFC8 /* Model */ = {
255+
B5AAAE5B1C85DD0A002DDFC8 /* Models */ = {
255256
isa = PBXGroup;
256257
children = (
257258
B52BD6761D5FA2570023D4E9 /* CategoriesCollection.swift */,
258259
B594CB3A1D53998900CB5630 /* CategoriesDataSource.swift */,
259260
B56D68E81CA564B00097D5D7 /* Category.swift */,
261+
B52BD6741D5F94320023D4E9 /* DataCollection.swift */,
260262
B52BD6781D6024D30023D4E9 /* DataSource.swift */,
263+
B516E78A1D54D73B00A3FCB9 /* SourceType.swift */,
261264
B5BA618A1C7748B900548B38 /* Video.swift */,
262265
B52BD6721D5F910D0023D4E9 /* VideosCollection.swift */,
263266
B58E906C1D5F806600AC184D /* VideosDataSource.swift */,
264267
);
265-
name = Model;
268+
path = Models;
266269
sourceTree = "<group>";
267270
};
268-
B5AAAE5C1C85DD16002DDFC8 /* View */ = {
271+
B5AAAE5C1C85DD16002DDFC8 /* Views */ = {
269272
isa = PBXGroup;
270273
children = (
271274
B5A8F7081CA259120069F836 /* CategoryCell.swift */,
@@ -277,10 +280,10 @@
277280
B5C591141CA04BA50096B985 /* SectionHeaderView.swift */,
278281
B5BA61881C77431400548B38 /* VideoCell.swift */,
279282
);
280-
name = View;
283+
path = Views;
281284
sourceTree = "<group>";
282285
};
283-
B5AAAE5D1C85DD1D002DDFC8 /* Controller */ = {
286+
B5AAAE5D1C85DD1D002DDFC8 /* Controllers */ = {
284287
isa = PBXGroup;
285288
children = (
286289
B53E397A1CA14B4200EB1EEE /* CategoriesViewController.swift */,
@@ -290,18 +293,18 @@
290293
B5BA618C1C774BC400548B38 /* VideoPlayerController.swift */,
291294
B5DCF9331C985E1600D19FC0 /* VideosViewController.swift */,
292295
);
293-
name = Controller;
296+
path = Controllers;
294297
sourceTree = "<group>";
295298
};
296-
B5D036581D54E96900B80CFC /* Helper */ = {
299+
B5D036581D54E96900B80CFC /* Helpers */ = {
297300
isa = PBXGroup;
298301
children = (
299302
B58DE38A1CB8B54200C00266 /* CoverBuilder.swift */,
300303
B543C3EE1CD1FD0B008C512B /* GroundControl.swift */,
301304
B53115921CC69E7C00E75292 /* HistoryManager.swift */,
302305
B543C3F01CD21530008C512B /* Tracker.swift */,
303306
);
304-
name = Helper;
307+
path = Helpers;
305308
sourceTree = "<group>";
306309
};
307310
B5F7BF3F1BA9C95F00A75099 = {
@@ -313,7 +316,10 @@
313316
BAB05330A45C8FC69E4F49F5 /* Pods */,
314317
B5F7BF491BA9C95F00A75099 /* Products */,
315318
);
319+
indentWidth = 2;
316320
sourceTree = "<group>";
321+
tabWidth = 4;
322+
usesTabs = 0;
317323
};
318324
B5F7BF491BA9C95F00A75099 /* Products */ = {
319325
isa = PBXGroup;
@@ -327,7 +333,7 @@
327333
B5F7BF4A1BA9C95F00A75099 /* iCookTV */ = {
328334
isa = PBXGroup;
329335
children = (
330-
B5A614FD1CCA0884004A3CD5 /* Classes */,
336+
B5A614FD1CCA0884004A3CD5 /* Sources */,
331337
B5A614FC1CCA0848004A3CD5 /* Supporting Files */,
332338
B5F7BF521BA9C95F00A75099 /* Assets.xcassets */,
333339
);
@@ -367,9 +373,9 @@
367373
buildConfigurationList = B5F7BF621BA9C95F00A75099 /* Build configuration list for PBXNativeTarget "iCookTV" */;
368374
buildPhases = (
369375
24D096314DA4D14E4EDFA5EB /* [CP] Check Pods Manifest.lock */,
376+
B52DFA9C1CF8006E005B9D67 /* Run Swiftlint */,
370377
B5BA3B4A1CF6D19800B0A022 /* Run R.swift Script */,
371378
B5F7BF441BA9C95F00A75099 /* Sources */,
372-
B52DFA9C1CF8006E005B9D67 /* Swiftlint */,
373379
B5F7BF451BA9C95F00A75099 /* Frameworks */,
374380
B5F7BF461BA9C95F00A75099 /* Resources */,
375381
B51A95351CCDFFEB00E5ED97 /* Run Fabric Script */,
@@ -541,16 +547,16 @@
541547
);
542548
runOnlyForDeploymentPostprocessing = 0;
543549
shellPath = /bin/sh;
544-
shellScript = "if [ \"$CONFIGURATION\" = \"Release\" ] && [ \"$CI\" != true ]; then\n FABRIC_APIKEY=$(cat ${SRCROOT}/keys/fabric.apikey);\n FABRIC_BUILDSECRET=$(cat ${SRCROOT}/keys/fabric.buildsecret);\n ${PODS_ROOT}/Fabric/run ${FABRIC_APIKEY} ${FABRIC_BUILDSECRET};\nelse\n echo \"Skip Fabric script\"\nfi";
550+
shellScript = "sh ${SRCROOT}/scripts/set-up-fabric.sh";
545551
};
546-
B52DFA9C1CF8006E005B9D67 /* Swiftlint */ = {
552+
B52DFA9C1CF8006E005B9D67 /* Run Swiftlint */ = {
547553
isa = PBXShellScriptBuildPhase;
548554
buildActionMask = 2147483647;
549555
files = (
550556
);
551557
inputPaths = (
552558
);
553-
name = Swiftlint;
559+
name = "Run Swiftlint";
554560
outputPaths = (
555561
);
556562
runOnlyForDeploymentPostprocessing = 0;
@@ -619,6 +625,7 @@
619625
B58DE38B1CB8B54200C00266 /* CoverBuilder.swift in Sources */,
620626
B52BD6751D5F94320023D4E9 /* DataCollection.swift in Sources */,
621627
B5EE17501DC509B8009DA1AE /* DataFetching.swift in Sources */,
628+
B546053A1DDB482A00208D37 /* DataRequest+Result.swift in Sources */,
622629
B52BD6791D6024D30023D4E9 /* DataSource.swift in Sources */,
623630
B50BFC051CC88FA3004F853D /* Debug.swift in Sources */,
624631
B55BF7E91DC5C3C400EE20BD /* DropdownMenuPresentable.swift in Sources */,
File renamed without changes.
File renamed without changes.

iCookTV/LaunchViewController.swift renamed to iCookTV/Controllers/LaunchViewController.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ class LaunchViewController: UIViewController, DataFetching {
132132

133133
private func fetchCategories() {
134134
fetch(request: CategoriesDataSource.requestForCategories) { [weak self] (result: Result<[Category]>) in
135-
switch result {
136-
case let .success(categories):
137-
self?.show(categories: categories)
138-
case let .failure(error):
139-
self?.showAlert(error, retry: self?.fetchCategories)
140-
}
135+
_ = result
136+
.mapSuccess { [weak self] categories in
137+
self?.show(categories: categories)
138+
}
139+
.mapError { [weak self] error in
140+
self?.showAlert(error, retry: self?.fetchCategories)
141+
}
141142
}
142143
}
143144

File renamed without changes.
File renamed without changes.

iCookTV/VideosViewController.swift renamed to iCookTV/Controllers/VideosViewController.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,17 @@ class VideosViewController: UIViewController,
189189

190190
isLoading = (dataSource.numberOfItems == 0)
191191
fetch(request: dataSource.requestForNextPage) { [weak self] (result: Result<[Video]>) in
192-
switch result {
193-
case let .success(videos):
194-
guard let current = self else {
195-
return
192+
_ = result
193+
.mapSuccess { [weak self] videos in
194+
guard let current = self else {
195+
return
196+
}
197+
self?.dataSource.append(videos, toCollectionView: current.collectionView)
198+
self?.setOverlayViewHidden(current.dataSource.numberOfItems > 0, animated: true)
199+
}
200+
.mapError { [weak self] error in
201+
self?.showAlert(error, retry: self?.fetchNextPage)
196202
}
197-
self?.dataSource.append(videos, toCollectionView: current.collectionView)
198-
self?.setOverlayViewHidden(current.dataSource.numberOfItems > 0, animated: true)
199-
case let .failure(error):
200-
self?.showAlert(error, retry: self?.fetchNextPage)
201-
}
202203
}
203204
}
204205

File renamed without changes.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// DataRequest+Result.swift
3+
// TryTVOS
4+
//
5+
// Created by Ben on 11/15/16.
6+
// Copyright © 2016 bcylin.
7+
//
8+
// Permission is hereby granted, free of charge, to any person obtaining a copy
9+
// of this software and associated documentation files (the "Software"), to deal
10+
// in the Software without restriction, including without limitation the rights
11+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
// copies of the Software, and to permit persons to whom the Software is
13+
// furnished to do so, subject to the following conditions:
14+
//
15+
// The above copyright notice and this permission notice shall be included in all
16+
// copies or substantial portions of the Software.
17+
//
18+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
// SOFTWARE.
25+
//
26+
27+
import Foundation
28+
import Alamofire
29+
import Freddy
30+
31+
enum Result<T> {
32+
case success(T)
33+
case failure(Error)
34+
35+
func mapSuccess<U>(_ transform: (T) -> U) -> Result<U> {
36+
switch self {
37+
case .success(let value): return .success(transform(value))
38+
case .failure(let error): return .failure(error)
39+
}
40+
}
41+
42+
func mapError(_ transform: (Error) -> Void) -> Result<T> {
43+
switch self {
44+
case .success(_): break
45+
case .failure(let error): transform(error)
46+
}
47+
return self
48+
}
49+
50+
}
51+
52+
53+
////////////////////////////////////////////////////////////////////////////////
54+
55+
56+
extension DataRequest {
57+
58+
func responseJSONObject(
59+
queue: DispatchQueue? = nil,
60+
options: JSONSerialization.ReadingOptions = .allowFragments,
61+
completion: @escaping (Result<JSON>) -> Void
62+
) -> Self {
63+
let serializer = DataRequest.jsonResponseSerializer(options: options)
64+
65+
return response(queue: queue, responseSerializer: serializer) { response in
66+
guard let data = response.data else {
67+
let error = response.result.error ?? NSError(domain: "io.github.bcylin.try-tvos", code: NSURLErrorUnknown, userInfo: nil)
68+
completion(.failure(error))
69+
return
70+
}
71+
72+
do {
73+
let json = try JSON(data: data)
74+
completion(.success(json))
75+
} catch {
76+
completion(.failure(error))
77+
}
78+
}
79+
}
80+
81+
}

0 commit comments

Comments
 (0)