 }
 
 struct Spotify {
-  private static func realApiRequest(_ route: String, method: HTTPMethod? = nil, body: Data? = nil) -> JSONResponse {
+  var db: DB
+
+  var credentials: Credentials {
+    return db.credentials
+  }
+
+  init() {
+    self.db = DB.load()
+  }
+
+  private func realApiRequest(_ route: String, method: HTTPMethod? = nil, body: Data? = nil) -> JSONResponse {
     return Utils.synchronousRequest(
       "https://api.spotify.com/v1/\(route)",
-      headers: ["Authorization": "Bearer \(Credentials.load().accessToken)"],
+      headers: ["Authorization": "Bearer \(credentials.accessToken)"],
       method: method,
       body: body
     )
   }
 
-  private static func apiRequest(_ route: String, method: HTTPMethod? = nil, body: Data? = nil) -> JSONResponse {
+  mutating private func apiRequest(_ route: String, method: HTTPMethod? = nil, body: Data? = nil) -> JSONResponse {
     let initialResult = realApiRequest(route, method: method, body: body)
 
     if initialResult.0["error"] != nil {

    }
  }

  private static func refreshTokenAndSave() {
    let newToken = refreshToken()

    _ = Credentials.updateAccessToken(newToken)
  }

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

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


    }
  }

  mutating private func apiRequest(_ route: String, method: HTTPMethod? = nil, body: String? = nil) -> JSONResponse {
    return apiRequest(route, method: method, body: body?.data(using: .utf8))
  }

  mutating private func apiRequest(_ route: String, method: HTTPMethod? = nil) -> JSONResponse {
    let thisVarHelpsAvoidAmbiguity: Data? = nil
    return apiRequest(route, method: method, body: thisVarHelpsAvoidAmbiguity)
  }

  private func refreshToken() -> String {
    let auth = Utils.b64("\(credentials.clientId):\(credentials.clientSecret)")
    let (json, response, _) = Utils.synchronousRequest(
      "https://accounts.spotify.com/api/token",
