Skip to content

Commit 5a68dbd

Browse files
committed
Add some comments
1 parent 2b63c9e commit 5a68dbd

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RxHttpClient is a "reactive wrapper" around NSURLSession. Under the hood it impl
1515
Now only [Carthage](https://github.com/Carthage/Carthage) supported:
1616
```
1717
github "ReactiveX/RxSwift" ~> 3.1
18-
github "Reloni/RxHttpClient"
18+
github "RxSwiftCommunity/RxHttpClient"
1919
```
2020
RxHttpClient uses RxSwift so it should be included into cartfile.
2121

RxHttpClient/HttpClient.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ import RxSwift
33

44
public final class HttpClient {
55
/// Scheduler for observing data task events
6-
internal let dataTaskScheduler =
7-
SerialDispatchQueueScheduler(qos: .utility, internalSerialQueueName: "com.RxHttpClient.HttpClient.DataTask")
6+
internal let dataTaskScheduler = SerialDispatchQueueScheduler(qos: .utility, internalSerialQueueName: "com.RxHttpClient.HttpClient.DataTask")
87
/// Default concurrent scheduler for observing observable sequence created by loadStreamData method
9-
internal let streamDataObservingScheduler =
10-
SerialDispatchQueueScheduler(qos: .utility, internalSerialQueueName: "com.RxHttpClient.HttpClient.Stream")
8+
internal let streamDataObservingScheduler = SerialDispatchQueueScheduler(qos: .utility, internalSerialQueueName: "com.RxHttpClient.HttpClient.Stream")
119
internal let sessionObserver = NSURLSessionDataEventsObserver()
1210
internal let urlSession: URLSessionType
1311

1412
public let urlRequestCacheProvider: UrlRequestCacheProviderType?
15-
16-
public let requestPlugin: RequestPluginType?
13+
14+
public let requestPlugin: RequestPluginType?
1715

1816
/**
1917
Creates an instance of HttpClient
@@ -53,7 +51,7 @@ extension HttpClient : HttpClientType {
5351
// clears cache provider before start
5452
dataCacheProvider?.clearData()
5553

56-
let useRequest = object.requestPlugin?.prepare(request: request) ?? request
54+
let useRequest = object.requestPlugin?.prepare(request: request) ?? request
5755

5856
let task = object.createStreamDataTask(request: useRequest, dataCacheProvider: dataCacheProvider)
5957

@@ -65,7 +63,7 @@ extension HttpClient : HttpClientType {
6563
task.cancel()
6664
disposable.dispose()
6765
}
68-
}.observeOn(streamDataObservingScheduler)
66+
}.subscribeOn(dataTaskScheduler).observeOn(streamDataObservingScheduler)
6967
}
7068

7169
public func createStreamDataTask(taskUid: String, request: URLRequest, dataCacheProvider: DataCacheProviderType?) -> StreamDataTaskType {

RxHttpClient/RequestPlugin/ActivityIndicatorPlugin.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ protocol UIApplicationType : class {
1515

1616
extension UIApplication : UIApplicationType { }
1717

18+
/// Plugin that shows Network activity indicator if there is active network request
1819
public final class NetworkActivityIndicatorPlugin : RequestPluginType {
1920
let application: UIApplicationType
2021

2122
var counter = 0 {
22-
didSet {
23-
application.isNetworkActivityIndicatorVisible = counter != 0
24-
}
23+
didSet { application.isNetworkActivityIndicatorVisible = counter != 0 }
2524
}
2625

27-
convenience public init(application: UIApplication) {
26+
convenience public init(application: UIApplication = UIApplication.shared) {
2827
self.init(applicationType: application)
2928
}
3029

RxHttpClient/RequestPlugin/RequestPluginType.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@
88

99
import Foundation
1010

11+
/// Plugin that receives callbacks from HttpClient and StreamDataTask
12+
/// HttpClient calls only prepare method, all onter methods are called by StreamDataTask
1113
public protocol RequestPluginType {
14+
/// HttpClient calls this method before creting actual URLSessionDataTask (and StreamDataTask)
1215
func prepare(request: URLRequest) -> URLRequest
16+
/// Called right before StreamDataTask starts underluing URLSessionDataTask
1317
func beforeSend(request: URLRequest)
18+
/// Called after StreamDataTask received didCompleteWithError event from URLSession
19+
///(and this method does not contain error)
1420
func afterSuccess(response: URLResponse?, data: Data?)
21+
/// Called after StreamDataTask received didCompleteWithError with error or if HTTPURLResponse status code is not within 200...299 range.
22+
/// Also this method is callded if StreamDataTask receives didBecomeInvalidWithError event from URLSession
1523
func afterFailure(response: URLResponse?, error: Error, data: Data?)
1624
}
1725

26+
/// Plugin that holds collection of plugins and send all events to them
1827
public final class CompositeRequestPlugin : RequestPluginType {
1928
let plugins: [RequestPluginType]
2029

RxHttpClient/StreamDataTask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ internal final class StreamDataTask {
102102
observer.onNext(StreamTaskEvents.error(error))
103103
} else {
104104
if let response = object.response as? HTTPURLResponse, !(200...299 ~= response.statusCode) {
105-
// send failure message to plugin because HTTP response cone is not within 200...299 range
105+
// send failure message to plugin because HTTP response code is not within 200...299 range
106106
object.requestPlugin?.afterFailure(response: object.response,
107107
error: error ?? HttpClientError.sessionExplicitlyInvalidated,
108108
data: object.dataCacheProvider?.getData())

0 commit comments

Comments
 (0)