You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-10Lines changed: 69 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,15 +18,7 @@ If you have any questions, please contact [[email protected]](hello@listenno
18
18
[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate PodcastAPI into your Xcode project using CocoaPods, specify it in your `Podfile`:
19
19
20
20
```ruby
21
-
pod 'PodcastAPI', '~> 1.0.1'
22
-
```
23
-
24
-
### Carthage
25
-
26
-
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate PodcastAPI into your Xcode project using Carthage, specify it in your `Cartfile`:
27
-
28
-
```ogdl
29
-
github "ListenNotes/PodcastAPI" ~> 1.0.1
21
+
pod 'PodcastAPI'
30
22
```
31
23
32
24
### Swift Package Manager
@@ -62,7 +54,7 @@ let apiKey = ProcessInfo.processInfo.environment["LISTEN_API_KEY", default: ""]
62
54
// the program would exit before requests return any response
63
55
let client = PodcastAPI.Client(apiKey: apiKey, synchronousRequest: true)
64
56
65
-
// By default, we do asynchronous requests.
57
+
// By default, we do asynchronous requests, for GUI-based applications on iOS or macOS
66
58
// let client = PodcastAPI.Client(apiKey: apiKey)
67
59
68
60
// All parameters are passed via this Dictionary[String: String]
@@ -91,12 +83,60 @@ client.search(parameters: parameters) { response in
91
83
print(response.getFreeQuota())
92
84
print(response.getUsage())
93
85
print(response.getNextBillingDate())
86
+
87
+
// If you use PodcastAPI library in a GUI app (e.g., iOS/macOS),
88
+
// You need to update UI in the main thread
89
+
// DispatchQueue.main.async {
90
+
// self.displayLabel.text = "some text here"
91
+
// }
94
92
}
95
93
}
96
94
```
97
95
98
96
If `apiKey` is an empty string "", then we'll connect to a [mock server](https://www.listennotes.com/api/tutorials/#faq0) that returns fake data for testing purposes.
99
97
98
+
### synchronousRequest parameter
99
+
100
+
A command line executable will exit without wait for http async requests to finish. Therefore, we have to make http requests synchronous. Please set the `synchronousRequest` parameter to true when instantiating a Client object:
101
+
102
+
```swift
103
+
let client = PodcastAPI.Client(apiKey: apiKey, synchronousRequest: true)
104
+
```
105
+
106
+
In GUI Apps (e.g., iOS / macOS), you don't need to pass a `synchronousRequest` parameter. Just do this:
107
+
108
+
```swift
109
+
let client = PodcastAPI.Client(apiKey: apiKey)
110
+
```
111
+
112
+
### Update UI in the main thread
113
+
114
+
In the completion closure of an API request, you need to update UI in the main thread (`DispatchQueue.main.async`) for GUI apps (e.g., iOS, macOS):
115
+
116
+
```swift
117
+
client.search(parameters: parameters) { response in
118
+
iflet error = response.error {
119
+
switch (error) {
120
+
case PodcastApiError.apiConnectionError:
121
+
print("Can't connect to Listen API server")
122
+
case PodcastApiError.authenticationError:
123
+
print("wrong api key")
124
+
default:
125
+
print("unknown error")
126
+
}
127
+
} else {
128
+
iflet json = response.toJson() {
129
+
print(json)
130
+
}
131
+
132
+
// If you use PodcastAPI library in a GUI app (e.g., iOS/macOS),
| serverError | something wrong on our end (unexpected server errors) |
113
153
114
154
All errors can be found in [this file](https://github.com/ListenNotes/podcast-api-swift/blob/main/Sources/PodcastAPI/PodcastApiError.swift).
155
+
156
+
### Run example apps
157
+
158
+
We provide two example apps: one is a command line app, and the other is an iOS app.
159
+
160
+
#### Run the command line example app
161
+
162
+
```sh
163
+
164
+
# From the root directory of podcast-api-swift, where Package.swift is located:
165
+
166
+
$ swift run
167
+
```
168
+
169
+
You can see the code under [Sources/ExampleCommandLineApp](https://github.com/ListenNotes/podcast-api-swift/tree/main/Sources/ExampleCommandLineApp).
170
+
171
+
#### Run the iOS example app
172
+
173
+
Just open ExampleIOSApp.xcworkspace with Xcode, from the directory of [Sources/ExampleIOSApp](https://github.com/ListenNotes/podcast-api-swift/tree/main/Sources/ExampleIOSApp).
0 commit comments