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
Custom ParameterEncodings #90
Comments
Hi there! Got your email too. I'll take a look as soon as I can. Happy holidays! |
Would strongly recommend taking a look at the Eidolon source code to see if it has something that you're looking for. |
Hmm. Eidolon uses the default parameter encoding, so it won't be much help. I'm trying out your sample code now and I'll let you know what I find. |
OK, I think I've got things working. First, the OK, so now for some Swift stuff. The syntax surrounding closures as variables is ... not intuitive 😄 I played around with things until I got the following to work: let xmlParameterEncoding: (URLRequestConvertible, [String: AnyObject]?) -> (NSURLRequest, NSError?) = { convertible, parameters -> (NSURLRequest, NSError?) in
//this is just to get things working
return (convertible.URLRequest, nil)
}
let closure = { (target: EyeQEndPoints, method: Moya.Method, parameters: [String: AnyObject]) -> Endpoint< EyeQEndPoints> in
return Endpoint< EyeQEndPoints>(URL: url(target), sampleResponse: .Success(200, target.sampleData), method: method, parameters: parameters, parameterEncoding: Moya.ParameterEncoding.Custom(xmlParameterEncoding))
}
let abcd = MoyaProvider(endpointsClosure: closure ) A few important notes: the But that should do it! Let me know if I can clarify anything. |
Thank you for the response. I figured that out shortly after I created the ticket. |
Awesome! I'll close this. Feel free to reopen or open a new issue if you have other questions. |
I have been working with this framework on iOS and am having a compile issue when adding custom parameterEncodings. I was wondering if you could help me out.
My EyeQEndPoints enum does not implement URLRequestConvertible which I believe is ok.
I declare the custom closure as follows:
let xmlParameterEncoding:(URLRequestConvertible, [String: AnyObject]?) -> (NSURLRequest, NSError?) = {(URLRequest, parameters) in {
//this is just to get things working
return (NSURLRequest.URLRequest, nil)
}
In the endpointsClosure, I set the custom closure:
let endpointsClosure = { (target: EyeQEndPoints, method: Moya.Method, parameters: [String: AnyObject]) -> Endpoint in
return Endpoint(URL: url(target), sampleResponse: EndpointSampleResponse.Success(200, target.sampleData), method: method, parameters: parameters, parameterEncoding: .Custom(xmlParameterEncoding))
}
The compiler throws an error on .Custom(xmlParameterEncoding) of
error: type 'URLRequestConvertible' does not conform to protocol 'URLRequestConvertible'
return Endpoint(URL: url(target), sampleResponse: EndpointSampleResponse.Success(200, target.sampleData), method: method, parameters: parameters, parameterEncoding: .Custom(xmlParameterEncoding))
Thanks for your help.
The text was updated successfully, but these errors were encountered: