     }
   }
 
-  private static func apiRequest(_ route: String, method: HTTPMethod? = nil, body: String? = nil) -> JSONResponse {
+  mutating private func apiRequest(_ route: String, method: HTTPMethod? = nil, body: String? = nil) -> JSONResponse {
     return apiRequest(route, method: method, body: body?.data(using: .utf8))
   }
 
-  private static func apiRequest(_ route: String, method: HTTPMethod? = nil) -> JSONResponse {
+  mutating private func apiRequest(_ route: String, method: HTTPMethod? = nil) -> JSONResponse {
     let thisVarHelpsAvoidAmbiguity: Data? = nil
     return apiRequest(route, method: method, body: thisVarHelpsAvoidAmbiguity)
   }
 
-  private static func refreshToken() -> String {
-    let credentials = Credentials.load()
+  private func refreshToken() -> String {
     let auth = Utils.b64("\(credentials.clientId):\(credentials.clientSecret)")
     let (json, response, _) = Utils.synchronousRequest(
       "https://accounts.spotify.com/api/token",

}

let command = CommandLine.arguments[1]

switch (command) {
case "info":
  dump(Spotify.currentlyPlaying().json)
case "save":
  let result = Spotify.saveToLibrary()
  if result.json.count > 0 {
    dump(result.json)
  } else {

    }
  }

  mutating private func refreshTokenAndSave() {
    let newToken = refreshToken()
    var newCredentials = db.credentials
    newCredentials.accessToken = newToken

    self.db = DB.updateCredentials(newCredentials)
  }

  mutating func currentlyPlaying() -> JSONResponse {
    return apiRequest("me/player/currently-playing")
  }

  mutating func saveToLibrary() -> JSONResponse {
    let currentlyPlayingInfo = currentlyPlaying().json
    let item = currentlyPlayingInfo["item"] as! [String: Any]
    let id = item["id"] as! String
    print(item["name"] as! String)
    let body = try! JSONEncoder().encode(["ids": [id]])
    return apiRequest("me/tracks", method: .PUT, body: body)
  }
}

