New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a method to return DataResponse from DataRequest.responseString() #116
Add a method to return DataResponse from DataRequest.responseString() #116
Conversation
0cdfb79
to
5797953
Compare
Can we merge this? |
I'm not entirely sure we'd want to overload responseString this way. responseJSON only has one meaning - and @sunshinejr Any chance you have thoughts on this? |
Hm, I'm not sure about this one. How about making it a |
Ended up ditching RxAlamofire as its become rather out of date and surfaces no data operations. Just wrapped this response method in an observable manually and saved a Framework import. |
If the op of this PR wants to go with |
Since the merge of PR #79, Should I rename both of them to A further issue with both of these methods is that they don't return the DataResponse on error, which is important for the main use-case (metrics and error logging). I'm not sure how to implement this though: wrap the error and the DataResponse into a new error type, or call |
5797953
to
482bbfe
Compare
I have rebased this branch on top of master, and I've also updated the function names to distinguish them from the regular response functions. I would love to see this merged. :) As an additional feature, the observables returned by these functions could also return the DataResponse on error. I'm not sure how to go about doing this. Would it be OK to emit the DataResponse as an error instead of the error? The following code: if let error = response.result.error {
observer.on(.error(error))
} would become: if let _ = response.result.error {
observer.on(response)
} Subscribers would then need to extract the error themselves. Alternatively, I could create a new error case that contains both the error and the response, or I could emit a tuple with both the error and the data response. |
482bbfe
to
839b72c
Compare
Hey @philippelatulippe - we follow semantic versioning, we can't make breaking changes like you did to the API without bumping a major version, and I wouldn't want to bump a major version for something to minor. |
Thanks for responding so quick, it wasn't my intention to make a breaking change to the API, renaming |
839b72c
to
b97473e
Compare
I've pushed a change to my commit which only introduces a new function, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with a few tiny notes.
Also wondering if it might be better as a Single but I don't mind too much.
Sources/RxAlamofire.swift
Outdated
|
||
- parameter encoding: Type of the string encoding, **default:** `nil` | ||
|
||
- returns: An instance of `Observable<SDataResponse<String>>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- returns: An instance of `Observable<SDataResponse<String>>` | |
- returns: An instance of `Observable<DataResponse<String>>` |
Sources/RxAlamofire.swift
Outdated
@@ -848,6 +852,34 @@ extension Reactive where Base: DataRequest { | |||
return result(responseSerializer: DataRequest.dataResponseSerializer()) | |||
} | |||
|
|||
/** | |||
Returns an `Observable` of a DataResponse<String> for the current request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns an `Observable` of a DataResponse<String> for the current request. | |
Returns an `Observable` of a `DataResponse<String>` for the current request. |
Would appreciate a second set of eyes if you have a minute @sunshinejr :) |
Allows access to metrics (NSURLSessionTaskMetrics) for those who need the response as a string, not JSON.
b97473e
to
f8b38cc
Compare
I pushed the changes based on the review suggestions. The tests seem to have failed because someone registered |
@philippelatulippe able to resolve the conflicts with master branch and update the PR? |
This is similar to PR #79 except for
responseString()
instead ofresponseJSON()
. I wrote it to work identically to the code in that pull request.It allows access to metrics (NSURLSessionTaskMetrics mentioned in issue #76 ) for those who need the response as a string, not JSON.