-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LFMKitTests.example.swift
123 lines (103 loc) · 4.26 KB
/
LFMKitTests.example.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//
// LFMKitTests.example.swift
// LFMKit
//
// Created by @verizxn on 26/05/24.
//
import XCTest
import LFMKit
final class LFMKitTests: XCTestCase {
private let username = "YOUR_USERNAME"
private var api = LFMKitAPI(api_key: "API_KEY", api_secret: "API_SECRET")
private let error_callback: (LFMError) -> Void = { error in
print("\nERROR: \(error.message)\n")
}
func testUser() throws {
let exp = expectation(description: "User")
api.user.getInfo(username: username, success: { response in
print("\n\(response.realname) (@\(response.name))'s profile:")
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testTracks() throws {
let exp = expectation(description: "Tracks")
api.user.getRecentTracks(username: username, limit: 5, success: { tracks in
print("Recent tracks:\n====================")
for track in tracks {
var nowPlaying = "[NOW] "
if let _ = track.date {
nowPlaying = ""
}
print("\(nowPlaying)\(track.artist.text!) - \(track.name) [\(track.album!.text!)]")
}
print("====================\n")
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testFriends() throws {
let exp = expectation(description: "Friends")
api.user.getFriends(username: username, success: { friends in
print("Friends:\n====================")
for friend in friends {
print("- @\(friend.name)")
}
print("====================\n")
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testTrack() throws {
let exp = expectation(description: "Track")
api.track.getInfo(track: "360", artist: "Charli XCX", username: username, success: { track in
print("Track info:\n====================")
print("\(track.artist.name!) - \(track.name) [\(track.album!.title)] \(track.userplaycount!)/\(track.playcount)")
print("====================\n")
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testSearch() throws {
let exp = expectation(description: "Search")
api.track.search(query: "360 Charli XCX", limit: 2, success: { results in
print("Search:\n====================")
for track in results.trackmatches.track {
print("\(track.artist) - \(track.name)")
}
print("====================\n")
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testSession() throws {
let exp = expectation(description: "Session")
print(api.auth.getLogin(callback: "myapp://"))
api.auth.getSession(token: "YOUR_TOKEN", success: { session in
print(session.name)
print(session.key)
print(session.subscriber)
self.api.setSession(session: session)
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testNowPlaying() throws {
let exp = expectation(description: "Now Playing")
let session = LFMResponseSession(name: username, key: "YOUR_SESSION_KEY", subscriber: 0)
api.setSession(session: session)
api.track.updateNowPlaying(artist: "Charli XCX", track: "360", album: "BRAT", success: {
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
func testScrobble() throws {
let exp = expectation(description: "Scrobbler")
let session = LFMResponseSession(name: username, key: "YOUR_SESSION_KEY", subscriber: 0)
api.setSession(session: session)
api.track.scrobble(artist: "Charli XCX", track: "360", timestamp: Date().timeIntervalSince1970, album: "BRAT", album_artist: nil, success: {
exp.fulfill()
}, error: error_callback)
waitForExpectations(timeout: 5)
}
}