Skip to content

Commit e84563d

Browse files
authored
IOS-0952 :: Feature Internal :: Implement generic network datasource
1 parent 359c6b8 commit e84563d

29 files changed

+1829
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Pods/
5252
# Add this line if you want to avoid checking in source code from Carthage dependencies.
5353
Carthage/Checkouts
5454
Carthage/Build
55+
Package.resolved
5556

5657
# fastlane
5758
#

Cartfile.private

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
github "Quick/Nimble" "v10.0.0"
2-

Example/Harmony.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7676
677082F15065F4C17D69219F /* Pods-Harmony_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Harmony_Example.release.xcconfig"; path = "Target Support Files/Pods-Harmony_Example/Pods-Harmony_Example.release.xcconfig"; sourceTree = "<group>"; };
7777
79EF043A5EBB6F5787C9BD65 /* Pods-Harmony_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Harmony_Tests.release.xcconfig"; path = "Target Support Files/Pods-Harmony_Tests/Pods-Harmony_Tests.release.xcconfig"; sourceTree = "<group>"; };
78+
AEF8517528D8495A00C77B0B /* Alamofire.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Alamofire.xcframework; path = ../Carthage/Build/Alamofire.xcframework; sourceTree = "<group>"; };
7879
D22A0B9E2035C91F0026068F /* Harmony_Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Harmony_Example-Bridging-Header.h"; sourceTree = "<group>"; };
7980
D22A0BA52035CD580026068F /* TestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestHelper.swift; sourceTree = "<group>"; };
8081
D23CDCAF2253716B001C1914 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -214,6 +215,7 @@
214215
8FEB14D5F816FBF6F03E5F42 /* Frameworks */ = {
215216
isa = PBXGroup;
216217
children = (
218+
AEF8517528D8495A00C77B0B /* Alamofire.xcframework */,
217219
319D67FB913C0BB868D4BBAE /* Pods_Harmony_Example.framework */,
218220
35E50C73A54D07B7A6EC055D /* Pods_Harmony_Tests.framework */,
219221
);

Example/Harmony/Core/ApplicationProvider.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ class ApplicationDefaultModule: ApplicationComponent {
2121
private lazy var logger: Logger = DeviceConsoleLogger()
2222
private lazy var backgroundExecutor: Executor = DispatchQueueExecutor()
2323

24-
private lazy var apiClient: Session = {
25-
// Alamofire Session Manager
26-
let sessionManager = Session(interceptor: BaseURLRequestAdapter(URL(string:"https://demo3068405.mockable.io")!,
27-
[UnauthorizedStatusCodeRequestRetrier()]))
28-
return sessionManager
24+
private lazy var apiClient: URLSession = {
25+
URLSession.shared
2926
}()
3027

3128
private lazy var storage: AnyDataSource<Data> = {

Example/Harmony/Core/Features/Item/Data/ItemQuery.swift

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,23 @@
99
import Foundation
1010
import Harmony
1111

12-
struct SearchItemsQuery: Query {
12+
class SearchItemsQuery: NetworkQuery {
13+
1314
let text : String
15+
1416
init(_ text: String) {
1517
self.text = text
18+
super.init(method: .get, path: "items", params: ["name":text])
1619
}
1720
}
1821

19-
struct AllItemsQuery: KeyQuery {
20-
let key: String = "all-items"
22+
class AllItemsQuery: NetworkQuery {
23+
24+
init() {
25+
super.init(method: .get, path: "items", key: "all-items")
26+
}
2127
}
28+
29+
30+
31+

Example/Harmony/Core/Features/Item/ItemProvider.swift

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,27 @@
77
//
88

99
import Harmony
10-
import Alamofire
1110

1211
protocol ItemComponent {
1312
func itemListPresenter(view: ItemListPresenterView) -> ItemListPresenter
1413
}
1514

1615
class ItemDefaultModule: ItemComponent {
1716
private let executor: Executor
18-
private let apiClient: Session
1917
private let storage: AnyDataSource<Data>
18+
private let apiClient: URLSession
2019

21-
init(executor: Executor, apiClient: Session, storage: AnyDataSource<Data>) {
20+
init(executor: Executor, apiClient: URLSession, storage: AnyDataSource<Data>) {
2221
self.executor = executor
23-
self.apiClient = apiClient
2422
self.storage = storage
23+
self.apiClient = apiClient
2524
}
2625

2726
private lazy var networkDataSource: AnyDataSource<ItemEntity> = {
28-
let baseDataSource = ItemNetworkDataSource(self.apiClient)
29-
27+
let baseDataSource = GetNetworkDataSource<ItemEntity>(url: URL(string:"https://demo3068405.mockable.io/")!,
28+
session: apiClient,
29+
decoder: JSONDecoder())
30+
3031
// To debug the UI upon random API behavior, adding this intermediate layer
3132
let itemNetworkDataSource = DebugDataSource(DataSourceAssembler(get: baseDataSource),
3233
delay: .sync(0.5),

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ SPEC CHECKSUMS:
3838

3939
PODFILE CHECKSUM: b7ed6de1edd55522f5ced841111c3aa6c7beeab7
4040

41-
COCOAPODS: 1.11.2
41+
COCOAPODS: 1.11.3

Harmony.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ Pod::Spec.new do |s|
3333
s.ios.deployment_target = '12.0'
3434

3535
s.source_files = 'Sources/Harmony/**/*'
36-
s.frameworks = 'Security'
36+
s.frameworks = 'Security'
3737

3838
end

0 commit comments

Comments
 (0)