WolMo - Networking iOS is a framework which provides an easy customizable HTTP request for iOS commonly used at Wolox.
Carthage is a dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
brew update
brew install carthage
To download wolmo-networking-iOS, add this to your Cartfile:
github "Wolox/wolmo-networking-ios" ~> 2.0.0
Bootstrap the project and then drag it to your workspace.
The framework provides an easy way to build HTTP repositories to perform requests to a given API based on Alamofire. The authentication method is based in a token provided in the HTTP header under the key Authorization.
The framework allows to create agile HTTP repositories by extending AbstractRepository. A simple example of this can be found in the class DemoRepository.
In case a custom repository should fetch a single or a collection of models, they must implement Decodable (see Argo). This way they can be automatically decoded by the framework. Check User or the entity Book.
In case the entity is too complex, it's possible to get the error: Expression was too complex to be solved in reasonable time. In this case check this Argo issue for a workaround.
Every implemented repository is thought to return a Result instance (see Result) in which the value is typed in the expected response type, and the error is always a RepositoryError.
The basic and expected errors are implemented, and a way to add custom errors related to the project itself is provided. In order to add new errors it should be necessary to create a new enum which implements the protocol CustomRepositoryErrorType as done in EntityRepository and match the expected status code in the HTTP response with each custom error. An example of this can be found in EntityRepository in the function fetchCustomFailingEntity.
Also, a custom DecodeError (see Argo) can be sent manually. An example can be found in EntityRepository in the function fetchEntities. This is useful in case the response body does not match exactly the return type and some kind of decoding needs to be manually performed.
In case you get a DecodeError, the framework offers a way to perform an action (for example reporting the error using a third party service to notify about a mismatch between API and the client).
To do this provide a closure decodedErrorHandler in DecodedErrorHandler. Check DecodedExtension. This closure receives the Argo.DecodeError and returns Void.
When creating a repository instance it expects an instance of NetworkingConfiguration, which is the struct intended to be the only place where the API settings are configured.
The properties configurable from there are:
useSecureConnection: Bool:trueforhttpsandfalseforhttp. In case this is disabled, the proper exception must be added toInfo.plistfile in the project.domainURL: String: API domain.port: String: API port.subdomainURL: String: API subdomain (optional parameter). This URL must start with/as required byURLComponents.usePinningCertificate: Bool: enables SSL Pinning (false by default) (see next section).timeout: The timeout of the requests in seconds. It defaults to 75 seconds.secondsBetweenPolls: For polling requests, seconds between one polling and the next. It defaults to 1 second.maximumPollingRetries: Maximum retries until a polling request gives timeout. If it's not set then it will use timeout/secondsBetweenPollsencodeAsURL: Methods to be encoded as URL. The remaining methods will be encoded as JSON.
If enabling SSL pinning a valid .der certificate must be provided. It needs to be added to the project and be present in "copy bundle resources" phase. The framework will automatically look for any certificate provided in bundle and use it.
AlamofireNetworkActivityLogger (see AlamofireNetworkActivityLogger) can be enabled by doing NetworkActivityLogger.shared.startLogging(). This will log in the console every request and response made depending on the logLevel, which can be selected by assigning the property NetworkActivityLogger.shared.level with a value of NetworkActivityLoggerLevel. By default, it enables it in debug.
Check NetworkingDemoLauncher for an example.
NetworkActivityIndicatorManager (see NetworkActivityIndicatorManager) is available to be enabled directly by doing NetworkActivityIndicatorManager.shared.isEnabled = true to automatically manage the visibility of the network activity indicator.
Check NetworkingDemoLauncher for an example.
git clone git@github.com:Wolox/wolmo-networking-ios.git
cd wolmo-networking-ios
script/bootstrap
- Fork it
- Bootstrap using the forked repository (instead of
Wolox/wolmo-networking-ios.git,your-user/wolmo-networking-ios.git) - Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Run tests (
./script/test) - Push your branch (
git push origin my-new-feature) - Create a new Pull Request
This project is maintained by Pablo Giorgi and it is written by Wolox.
WolMo - Core iOS is available under the MIT license.
Copyright (c) 2016 Pablo Giorgi <pablo.giorgi@wolox.com.ar>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
