
[](https://travis-ci.org/Daltron/Spartan)
[](http://cocoapods.org/pods/Spartan)
[](http://cocoapods.org/pods/Spartan)
[](http://cocoapods.org/pods/Spartan)
## Written in Swift 4.2
Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under the hood, Spartan makes request to the Spotify Web API. Those requests are then turned into clean, friendly, and easy to use objects.
### What this library allows you to do:
- ✅ Make any request that the Spotify Web API allows.
### What this library doesn't do:
- ❌ Authorization flows that help provide you with an authorization token. The [Spotify iOS SDK](https://github.com/spotify/ios-sdk) can help assist you with that.
## Requirements
- iOS 9.0+ / macOS 10.11+
- xCode 9.0+
## Installation
### CocoaPods
To integrate Spartan into your xCode project using CocoaPods, specify it in your `Podfile`:
```ruby
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0' # If you targeting iOS
platform :osx, '10.11' # If you targeting macOS
use_frameworks!
pod 'Spartan'
```
Then, run the following command:
```bash
$ pod install
```
This will download any library dependencies you do not already have in your project.
## Usage
### Spartan Properties
#### Authorization Token
```swift
public static var authorizationToken: String?
```
This is the token that is included with each request that requires OAuth authentication. If the request you make requires OAuth and this in nil, invalid, or expired, the request will fail. This can be left `nil` if you do not plan on making any requests that require OAuth authentication.
Each time your token is refreshed, simply update it:
```swift
Spartan.authorizationToken = newToken
```
#### Logging
```swift
public static var loggingEnabled: Bool = true
```
When enabled, before each request starts and after each request finishes, helpful statements will be printed to the console.
A successful request will look something like this:
```swift
🔵 [SpartanRequestLogger] GET https://api.spotify.com/v1/me
⚪️ [SpartanRequestLogger] GET https://api.spotify.com/v1/me (200 OK) 0.140969038009644 seconds
```
While a failed/invalid request will look something like this:
```swift
🔵 [SpartanRequestLogger] GET https://api.spotify.com/v1/me
🔴 [SpartanRequestLogger] GET https://api.spotify.com/v1/me (401 Unauthorized) 0.81086003780365 seconds
```
This can be enabled/disabled at any time anywhere in your code simply by:
```swift
Spartan.loggingEnabled = true/false
```
## Core
For more information on each request, please click the link associated with it. Spotify provides excellent documentation for each api request that they support. Spartan supports almost all query parameter fields that Spotify allows.
### PagingObject
Quite a few requests return a `PagingObject`. This is an offset based paging object that is a container for a set of objects. It contains a key called items whose value is an array of the requested objects. It can be used to get the previous set of items or the next set of items for a future call.
For example:
```swift
_ = Spartan.search(query: "Five for Fighting", type: .track, success: { (pagingObject: PagingObject