moya / moya Goto Github PK
View Code? Open in Web Editor NEWNetwork abstraction layer written in Swift.
Home Page: https://moya.github.io
License: MIT License
Network abstraction layer written in Swift.
Home Page: https://moya.github.io
License: MIT License
For the last-minute hook. Using a URL request will let people use general-purpose request-signing libraries.
Thanks for this great work, but I can't use that because when i run bundle install
, it show following message
Bundler could not find compatible versions for gem "xcodeproj":
In Gemfile:
cocoapods (>= 0) ruby depends on
xcodeproj (~> 0.20.2) ruby
xcodeproj (0.20.1)
So this is a tough one that I need to figure out an abstraction for. The basic gist is as follows: You set up a MoyaProvider
with a bunch of endpoints. Cool, right? Except as of this moment, you access the API like this:
let provider = MoyaProvider(endpoints: [
Endpoint(URL: "http://rdjpg.com/300/200/", sampleResponse: {
/* doesn't matter */
})
])
...
provider.request("http://rdjpg.com/300/200/", completion: { (object: AnyObject?) -> () in
...
})
Not cool – let's avoid stringly-typedness in this library.
Is there a way to provide a compile-time check that the endpoint actually exists? Can we set up some sort of enum or token or something that you pass in when you create the endpoint, and then reuse that token later on when calling the API? It needs to be something accessible by both whoever sets up the API at app launch, likely the app delegate, and anyone else who wants to access it (view controllers, network layers, whoever).
It's tricky since I want a clear separation of this library and the app code. Since each app has a different API, this abstraction – whatever it ends up being – needs to be something defined in app code, but is used by the library.
So I need a thing that someone using this library creates, uses to register the endpoint, then uses somewhere else in order to access the API. Any thoughts?
I'm wondering maybe I've missed something, but I do not see any way to pass default parameters to each request.
Moya.defaultParameters()
exists but it is not exposed in any way to be configured
It's currently AnyObject
, just because that's the type of the object from Alamofire, but in all cases, it will be NSData
. Might open an issue over there to fix that.
It's not super clear why one would want to use Moya instead of using Alamofire itself. We should update the README.
It would be sweet if there were a way to randomly or deterministically add a short delay to stub request returns to make it a little more "real".
Pass them into the closure. Obviates the need for #5.
So right now, we send the request when the request
method is called. That is no the ReactiveCocoa way. We should be returning a multicasted signal that sends the request when it is first subscribed to, like this.
I use this framework with CocoaPods, but I can't install my app on my device via OTA install (use Fabric).
And I try to submit to iTunes Connect, I got this message.
Dear developer,
We have discovered one or more issues with your recent delivery for "". To process your delivery, the following issues must be corrected:
This bundle is invalid - The file extension must be .zip.
Any idea?
The link http://ashfurrow.com/Moya is not working. is it possible to put it on github?
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.
right now a test suite doing some networking looks like:
beforeSuite { () -> () in
// Force provider to stub responses
APIKeys.sharedKeys = APIKeys(key: "", secret: "")
Provider.sharedProvider = Provider.StubbingProvider()
}
afterSuite { () -> () in
// Reset provider
APIKeys.sharedKeys = APIKeys()
Provider.sharedProvider = Provider.DefaultProvider()
}
it("returns some data") {
setDefaultsKeys(nil, nil)
var called = false
XAppRequest(.Auctions).subscribeNext({ (object) -> Void in
called = true
})
expect(called).to(beTruthy())
}
... etc
This is fine, and it goes and access pre-rendered stubs etc. I'd like some choice, and to allow making something like this (excusing broken syntax):
let networkProvider = Provider.runtimeProvider()
beforeSuite { () -> () in
Provider.sharedProvider = networkProvider
}
afterSuite { () -> () in
Provider.sharedProvider = Provider.DefaultProvider()
}
it("returns some data") {
var called = false
networkProvider.responseString(.Auctions) {
return "{ 'foo':'bar' }"
}
XAppRequest(.Auctions).subscribeNext({ (object) -> Void in
called = true
})
expect(called).to(beTruthy())
}
with maybe the potential of returning strings, json objects and data?
Right now you can only stub successes, but if your view controller reacts to failures, there is no way to stub that.
Kind of a leaky abstraction. Just need an intermediate type to replace URLRequestConvertible
, which belongs to Alamofire.
See #90.
Known: If a request errors, it cannot be ran a second time.
Removing these lines fixes the issue.
@orta mentioned how it was kinda weird to have them all tangled up. Another test target should separate things nicely.
I may end up doing this in anger, so I'm dropping a note here in case anyone else is interested. Probably a separate project? It uses mustache templates so how hard can it be?!
It's nice for knowing that you forgot your stubbed data file though.
There's no way to attach information that is encoded into the URL of an endpoint but that is not part of the path.
See: https://github.com/artsy/eidolon/pull/95/files#r18471548
When choosing to use Moya as a submodule rather than copy its files into a project, MoyaErrorDomain is unusable outside Moya since it's private by default.
Just using a completion block and passing the data as a parameter to the closure isn't going to cut it. ReactiveCocoa to the rescue, maybe?
I get a warning like:
NSForwarding: warning: object 0x7f8943920a10 of class 'Kiosk.MoyaResponse' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector
You know, instead of sending NSData, we could send JSON or images or something. Who knows!
As @orta suggested, it'd be awesome to have a sample application demonstrating real-world use of Moya with the GitHub API.
Some really good stuff here: https://gist.github.com/chriseidhof/1fc977ffb856dbcdc113
Related to #16.
This is a new API as of iOS 7, and to be honest, I haven't taken a look at it yet. It could be really useful or something. Let's find out.
All the projects nowadays need a cool, edgy logo. Not a high priority, but when it comes to logos, I only trust the best.
We should provide some way to alter the request somehow, for authentication.
Related to #44.
The main interface can still use RACSignal
s, but we should have an extension for the MoyaProvider
class that allows developers to opt for callback blocks.
Alamofire supports four different parameter encodings. Basically, we just need to expose those options to the Endpoint
class. I'd like to do that without exposing the internals of Alamofire itself, though.
It's on trunk now.
For the Carthage/submodule users– a Moya.xcodeproj defining the Moya.framework target is something I would very much like. Putting this in as placeholder, I'm working on it.
From our use in Eidolon, we almost always call request
with the defaultParameters
we've defined on our target, since the target contains all the details necessary for the action, anyway. So why not codify that requirement?
Thoughts anyone?
Sorely missing. Now that eidolon is at a 1.0, I should have enough real-world experience to document, in detail, the different use cases and features of Moya.
Looks like it was added with ssh key for a submodule. I don't use ssh. Can it be added by http?
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Clone of '[email protected]:Alamofire/Alamofire.git' into submodule path 'submodules/Alamofire' failed
The header API for two requests on the same URL can be different when comparing POST vs GET for example.
This will be a key component after #1 is completed. For example, if a request is made to an in-flight request, we can return the promise or signal or whatever associated with that response.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.