moya

Get response header with Moya

隐身守侯 提交于 2019-12-31 05:45:05
问题 I am using Moya in my swift app for network requests. I am able to get requests and map the result using Moya- Object Mapper. I have used alamofire earlier and I am familiar with how to make post, get requests and read the response headers . However, I can't seem to understand how I can do the same in Moya. I did go through the documentation but it does not say anything about reading response headers. Is there any example or tutorial where I can follow how to do a HTTP authentication and read

Construct Moya TargetType in iOS

蹲街弑〆低调 提交于 2019-12-25 09:06:03
问题 I'm trying to use Moya with RxSwift in my project I'm facing the problem with url contain "?" This TargetType I have create private extension String { var URLEscapedString: String { return self.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed)! } } enum TMDb { case discoverMovieList(page: Int) case discoverMovieDetail(moive: Movie) } extension TMDb: TargetType { var baseURL: URL { return URL(string: BASE_URL)! } var path: String { switch self { case .discoverMovieList

Moya mapper not able to mapObjects from result - Swift 3

人走茶凉 提交于 2019-12-24 10:41:15
问题 Well Hi, I am using moyamapper I've tried different libraries but I am finding the same issue with all of them I am not able to understand where I am going wrong. Now I have a method which get the result in a moya result and Its fine till her here I am using pod 'MoyaModelMapper' func getCategories() { let APIProviderClosure = APIHelper.getAPIProvider() let provider = MoyaProvider<APIType>(endpointClosure:APIProviderClosure, plugins: [NetworkLoggerPlugin(verbose: true)]) provider.request

Post request error with parameter encode when use moya and alamofire

杀马特。学长 韩版系。学妹 提交于 2019-12-12 05:42:00
问题 I use the moya make the post request,but when I send the post , the server give me an error, it can't decoding the body parameters.I use URLEncoding.default to encode the parameters like this public var parameterEncoding: ParameterEncoding { return URLEncoding.default } It will set the content-type application/x-www-form-urlencoded, and the server accept content type is same too if parameters is a dictionary like this {"a":"b"} ,that is working well, but if dictionary contained array or

Casting Moya Response error to defined type

☆樱花仙子☆ 提交于 2019-12-11 19:28:17
问题 I am using RxMoya for my networking calls and extending PremitiveSequence and Response so as to handle the error coming back. I declared a struct of Networking error which I could use to get all the error details and as such Pass the error message via the BaseResponse Model. Here is my NetwokingError struct public struct NetworkingError: Error { let httpResponse: HTTPURLResponse? let networkData: Data? let baseError: Error } For my coding, I have extended the primitive sequence as follows

How to handle the response of all types of requests in one handler, but also uniquely handle every request with Alamofire and Moya

限于喜欢 提交于 2019-12-11 01:08:54
问题 In my app I use Moya and Alamofire (And also Moya/RxSwift and Moya-ObjectMapper) libraries for all network requests and responses. I would like to handle the response of all types of requests in one handler, but also uniquely handle every request. For example for any request I can get the response "Not valid Version", I would like to avoid to check in every response if this error arrived. Is there an elegant way to handle this use case with Moya ? 回答1: Apparently that is very simple, You just

How to upload image using multipart request with Moya Swift?

本秂侑毒 提交于 2019-12-04 11:51:29
问题 I'm using Moya 10.0.1 and I'm having a problem when I'm trying to upload an image to the server. I did follow the Multipart Upload example and this is my setup code: typealias UpdateUserAvatarParameters = (userId: Int, image: UIImage) enum APITarget { case updateUserAvatar(parameters: UpdateUserAvatarParameters) } extension APITarget: TargetType { public var baseURL: URL { return URL(string: "http://domain/api")! } public var path: String { switch self { case .updateUserAvatar: return "

Handling Network error in combination with binding to tableView (Moya, RxSwift, RxCocoa)

流过昼夜 提交于 2019-12-04 10:51:11
问题 I am currently using Moya to make my network requests. I have implemented the following from one of the example projects @ https://github.com/DroidsOnRoids/RxSwiftExamples#tutorials Below I have set up restaurantSearch so that when someone enters text it makes a new request. var restaurantSearch: Observable<(String)> { return searchBar .rx_text .throttle(0.5, scheduler: MainScheduler.instance) .distinctUntilChanged() } I have a method that returns an observable of type [Restaurant] func

Handling Network error in combination with binding to tableView (Moya, RxSwift, RxCocoa)

耗尽温柔 提交于 2019-12-03 06:46:05
I am currently using Moya to make my network requests. I have implemented the following from one of the example projects @ https://github.com/DroidsOnRoids/RxSwiftExamples#tutorials Below I have set up restaurantSearch so that when someone enters text it makes a new request. var restaurantSearch: Observable<(String)> { return searchBar .rx_text .throttle(0.5, scheduler: MainScheduler.instance) .distinctUntilChanged() } I have a method that returns an observable of type [Restaurant] func restaurants() -> Observable<[Restaurant]> { return restaurantSearch .observeOn(MainScheduler.instance)

Using retryWhen to update tokens based on http error code

落爺英雄遲暮 提交于 2019-11-29 11:31:44
问题 I found this example on How to refresh oauth token using moya and rxswift which I had to alter slightly to get to compile. This code works 80% for my scenario. The problem with it is that it will run for all http errors, and not just 401 errors. What I want is to have all my other http errors passed on as errors, so that I can handle them else where and not swallow them here. With this code, if I get a HttpStatus 500 , it will run the authentication code 3 times which is obviously not what I