Toggl Swift is a wrapper of Toggl-api-v8, which is dedicatedly writeen by pure Swift and No Dependency.
It's obvious that we don't want to introduce any unnecessary dependency, such as Alamofire, Moya to your project π¨βπ»
This project is actively under development. We don't consider it ready for production use.
- Foundation of Toggl Swift
- Support Authentication APIs
- Partital complete Unit Tests for all components
- macOS Example app
- Support Carthage
- Client, Group, Tag, Task, ... APIs
- Report APIs
- RxSwift Extension
Toggl Swift
is designed in the flexibility manner. It's so easy in order to provide your own URLSession, Serializer, Plugins.
We've inspired the idea from Moya, which means that we abstract the nasty Networking layer by introducing the APIRoute
enum.
By using this approach, there are positive benefits.
- Hide the complexity of URLSession or Alamofire behind the scene from the client.
- Use API Route enum as a first-citizen by defining clearly the routes.
- Hide the business logic and strengthen readability and testable.
public enum APIRoute {
case loginEmail(LoginEmailParameter)
case loginAPIToken(LoginTokenParameter)
case loginWithSession(LoginTokenParameter)
case project
case ...
}
NetworkService
is capable of injecting your custom classes. Rather than one god class has really big responsibilities, it dedicatedly delegates to other guys, who are really good at it. For instance, Fetchable
, Serializable
, PluginType
, ValidatorType
, ...
Therefore, it's super flexible to you to integrate to your own app.
public final class NetworkService: NetworkServiceType {
// MARK: - Variable
private let fetcher: Fetchable
private let serializer: Serializable
private let plugins: [PluginType]
private let statusCodeValidator: ValidatorType // future
}
We have provided 1 sample macOS projects in the repository.
- Clone Toggl Swift
- Open
DesktopWorksapce.xcworkspace
- Make sure we're choosing Desktop-Toggl
- Run and Happy coding π¨βπ»
- Swift 4.2
Make the following entry in your Cartfile:
github "NghiaTranUIT/Toggl-Swift"
Then run carthage update
.
If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.
- Download the latest
TogglCore.framework
from Release - Add
TogglCore.framework
to your project - Happy coding! π
// Define your URLSession
let urlSession = URLSession(configuration: .default)
// JSON Serializer
// Or XML, Thrift, ... by adopting the Serializable protocol
let jsonSerializer = JSONSerializer()
// Plugings
let plugins = [LoggerPlugin()]
// Initialize
let network = NetworkService(fetcher: urlSession, serializer: jsonSerializer, plugins: plugins)
// Param
let param = LoginEmailParameter(email: "[email protected]", password: "Toggl")
// Login with Email and password
network.request(APIRoute.loginEmail(param), type: User.self) { (result) in
switch result {
case .error(let error):
// Show Error Alert here
break
case .success(let user):
// Get the user
print(user.fullName)
break
}
}
We provide many convenience extensions to you in order to integrate your app seamlessly.
/// Convenience extension
extension NetworkServiceType {
/// Login with email and password
public func login(email: String, password: String, complete: @escaping (Result<User>) -> Void)
/// Login with API token
public func login(apiToken: String, complete: @escaping (Result<User>) -> Void)
/// Login with session
public func loginSession(apiToken: String, complete: @escaping (Result<User>) -> Void)
}
Then we can call the login func directly.
network.login(email: "[email protected]", password: "Toggl") { (result) in
switch result {
case .error(let error):
// Show Error Alert here
break
case .success(let user):
// Get the user
print(user.fullName)
break
}
}
Toggl Swift
is released under an MIT license. See LICENSE for more information.