-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
120 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import Foundation | ||
|
||
enum LyricsError: Error, CustomStringConvertible { | ||
case NoCurrentTrack | ||
case MusixmatchRestricted | ||
case InvalidMusixmatchToken | ||
case DecodingError | ||
case NoSuchSong | ||
case UnknownError | ||
case InvalidSource | ||
case noCurrentTrack | ||
case musixmatchRestricted | ||
case invalidMusixmatchToken | ||
case decodingError | ||
case noSuchSong | ||
case unknownError | ||
case invalidSource | ||
|
||
var description: String { | ||
switch self { | ||
case .NoSuchSong: "no_such_song".localized | ||
case .MusixmatchRestricted: "musixmatch_restricted".localized | ||
case .InvalidMusixmatchToken: "invalid_musixmatch_token".localized | ||
case .DecodingError: "decoding_error".localized | ||
case .NoCurrentTrack: "no_current_track".localized | ||
case .UnknownError: "unknown_error".localized | ||
case .InvalidSource: "" | ||
case .noSuchSong: "no_such_song".localized | ||
case .musixmatchRestricted: "musixmatch_restricted".localized | ||
case .invalidMusixmatchToken: "invalid_musixmatch_token".localized | ||
case .decodingError: "decoding_error".localized | ||
case .noCurrentTrack: "no_current_track".localized | ||
case .unknownError: "unknown_error".localized | ||
case .invalidSource: "" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Sources/EeveeSpotify/Settings/Helpers/AnonymousTokenHelper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
struct AnonymousTokenHelper { | ||
private static let apiUrl = "https://apic.musixmatch.com" | ||
|
||
static func requestAnonymousMusixmatchToken() async throws -> String { | ||
let url = URL(string: "\(apiUrl)/ws/1.1/token.get?app_id=\(await UIDevice.current.musixmatchAppId)")! | ||
let (data, _) = try await URLSession.shared.data(from: url) | ||
|
||
guard | ||
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], | ||
let message = json["message"] as? [String: Any], | ||
let body = message["body"] as? [String: Any], | ||
let userToken = body["user_token"] as? String | ||
else { | ||
throw AnonymousTokenError.invalidResponse | ||
} | ||
|
||
return userToken | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Sources/EeveeSpotify/Settings/Models/AnonymousTokenError.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
enum AnonymousTokenError: Swift.Error { | ||
case invalidResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.