1
1
# RxNetworkKit
2
- ![ Swift] ( https://img.shields.io/badge/Swift-5.5 -orange )
2
+ ![ Swift] ( https://img.shields.io/badge/Swift-5.3 -orange )
3
3
![ Platforms] ( https://img.shields.io/badge/Platforms-iOS%20macOS-yellowgreen )
4
4
![ iOS] ( https://img.shields.io/badge/iOS-14.0%2B-black )
5
5
![ macOS] ( https://img.shields.io/badge/macOS-11.0%2B-black )
@@ -24,11 +24,97 @@ It makes use of RxSwift's traits at request level to acheive a high level of spe
24
24
- includes a request interceptor protocol that can be implemented for request adaptation and retry on failure.
25
25
- comes with a reachability class that you can observe from anywhere for reachability status.
26
26
27
+ ## Practical Examples
28
+
29
+ ### Simple API Call:
30
+
31
+ ```
32
+ // Create 'Network Manager' instance.
33
+ let manager = NetworkManager(configuration: .default, requestInterceptor: self, eventMonitor: self)
34
+ // Create request router object.
35
+ let router = Router.default
36
+ // Make request observable sequence using request router.
37
+ let single: Single<Model> = manager.request(router)
38
+ // Subscrible to sequence and observe events.
39
+ single
40
+ .observe(on: MainScheduler.instance)
41
+ .subscribe(onSuccess: {
42
+ print("Task Response: \($0)")
43
+ print("Task Completed!")
44
+ }, onFailure: {
45
+ print("Task Failure: \($0.localizedDescription)")
46
+ }, onDisposed: {
47
+ print("Subscription is disposed!")
48
+ })
49
+ // Dispose subscription by dispose bag.
50
+ .disposed(by: disposeBag)
51
+ ```
52
+
53
+ ### Download Request:
54
+
55
+ ```
56
+ // Create 'Network Manager' instance.
57
+ let manager = NetworkManager(configuration: .default, requestInterceptor: self, eventMonitor: self)
58
+ // Create download request router object.
59
+ let router = DownloadRouter.default
60
+ // Make download request observable sequence using request router.
61
+ let downloadObservable: Observable<DownloadEvent> = manager.download(router)
62
+ // Subscrible to sequence and observe events.
63
+ downloadObservable
64
+ .observe(on: MainScheduler.instance)
65
+ .subscribe(onNext: {
66
+ switch $0 {
67
+ case .progress(let progress):
68
+ print("Download Task Progress: \(progress.fractionCompleted*100)%")
69
+ case .completedWithData(let data):
70
+ print("Download Task Completed with data: \(data).")
71
+ default: break
72
+ }
73
+ }, onError: {
74
+ print("Download Task Failure: \($0.localizedDescription)")
75
+ }, onCompleted: {
76
+ print("Download Task Completed!")
77
+ })
78
+ // Dispose subscription by dispose bag.
79
+ .disposed(by: disposeBag)
80
+ ```
81
+
82
+ ### Upload Request:
83
+
84
+ ```
85
+ // Create 'Network Manager' instance.
86
+ let manager = NetworkManager(configuration: .default, requestInterceptor: self, eventMonitor: self)
87
+ // Create upload request router object.
88
+ let router = UploadRouter.default
89
+ // Make 'UploadFile' object.
90
+ let fileData = Data()
91
+ guard let file = UploadFile(forKey: UUID().uuidString, withName: "testFile.txt", withData: fileData) else { return }
92
+ // Make upload request observable sequence using request router and uploa file object.
93
+ let uploadObservable: Observable<UploadEvent<UploadModel>> = manager.upload(router, file)
94
+ // Subscrible to sequence and observe events.
95
+ uploadObservable
96
+ .observe(on: MainScheduler.instance)
97
+ .subscribe(onNext: {
98
+ switch $0 {
99
+ case .progress(let progress):
100
+ print("Upload Task Progress: \(progress.fractionCompleted*100)%")
101
+ case .completed(let model):
102
+ print("Upload Task Completed with Response: \(model)")
103
+ }
104
+ }, onError: {
105
+ print("Upload Task Failure: \($0.localizedDescription)")
106
+ }, onCompleted: {
107
+ print("Upload Task Completed!")
108
+ })
109
+ // Dispose subscription by dispose bag.
110
+ .disposed(by: disposeBag)
111
+ ```
112
+
27
113
## Requirements
28
114
29
115
| Platform | Minimum Swift Version | Installation | Status |
30
116
| --- | --- | --- | --- |
31
- | iOS 14.0+ / macOS 11.0+ | 5.5 | [ CocoaPods] ( #cocoapods ) , [ Swift Package Manager] ( #swift-package-manager ) , [ Manual] ( #manually ) | Fully Tested |
117
+ | iOS 14.0+ / macOS 11.0+ | 5.3 | [ CocoaPods] ( #cocoapods ) , [ Swift Package Manager] ( #swift-package-manager ) , [ Manual] ( #manually ) | Fully Tested |
32
118
33
119
## Installation
34
120
@@ -39,7 +125,7 @@ It makes use of RxSwift's traits at request level to acheive a high level of spe
39
125
``` ruby
40
126
pod ' RxNetworkKitX'
41
127
```
42
- We had to postfix with 'X' as there's a pod on trunk with same name but different case 🤦♂️
128
+ P.S: We had to postfix with 'X' as there's a pod on trunk with same name but different case 🤦♂️
43
129
44
130
### Swift Package Manager
45
131
0 commit comments