|
1 |
| -# podcast-api-rust |
2 |
| -Rust library for the Listen Notes Podcast API |
| 1 | +# Podcast API Rust Library |
3 | 2 |
|
4 |
| -## Check |
| 3 | +The Podcast API Rust library provides convenient access to the [Listen Notes Podcast API](https://www.listennotes.com/api/) from |
| 4 | +applications written in the Rust language. |
| 5 | + |
| 6 | +Simple and no-nonsense podcast search & directory API. Search the meta data of all podcasts and episodes by people, places, or topics. It's the same API that powers [the best podcast search engine Listen Notes](https://www.listennotes.com/). |
| 7 | + |
| 8 | +If you have any questions, please contact [[email protected]]([email protected]?subject=Questions+about+the+Rust+SDK+of+Listen+API) |
| 9 | + |
| 10 | +<a href="https://www.listennotes.com/api/"><img src="https://raw.githubusercontent.com/ListenNotes/ListenApiDemo/master/web/src/powered_by_listennotes.png" width="300" /></a> |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +Add the following line to your `Cargo.toml` file's dependencies section: |
| 15 | + |
| 16 | +```toml |
| 17 | +[dependencies] |
| 18 | +podcast-api = "1.0.1" |
| 19 | +``` |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +The library needs to be configured with your account's API key which is |
| 24 | +available in your [Listen API Dashboard](https://www.listennotes.com/api/dashboard/#apps). Set `api_key` to its |
| 25 | +value: |
| 26 | + |
| 27 | +```rust |
| 28 | +use podcast_api::Error; |
| 29 | +use serde_json::json; |
| 30 | + |
| 31 | +#[tokio::main] |
| 32 | +async fn main() { |
| 33 | + // Api Key (None => Test API, Some(key) => Production API) |
| 34 | + let api_key = None; |
| 35 | + // let api_key = Some("put your api key here"); |
| 36 | + |
| 37 | + // Create client |
| 38 | + let client = podcast_api::Client::new(api_key); |
| 39 | + |
| 40 | + // Call API |
| 41 | + match client |
| 42 | + .typeahead(&json!({ |
| 43 | + "q": "startup", |
| 44 | + "show_podcasts": 1 |
| 45 | + })) |
| 46 | + .await |
| 47 | + { |
| 48 | + Ok(response) => { |
| 49 | + println!("Successfully called Listen Notes API."); |
| 50 | + if let Ok(body) = response.json().await { |
| 51 | + println!("Response Body:"); |
| 52 | + println!("{}", body); |
| 53 | + } else { |
| 54 | + println!("Response body JSON data parsing error.") |
| 55 | + } |
| 56 | + } |
| 57 | + Err(err) => { |
| 58 | + match err { |
| 59 | + Error::NotFoundError => { println!("Not Found: {}", err); } |
| 60 | + Error::AuthenticationError => { println!("Authentication Issue: {}", err); } |
| 61 | + Error::RateLimitError => { println!("Rate Limit: {}", err); } |
| 62 | + Error::InvalidRequestError => { println!("Invalid Request: {}", err); } |
| 63 | + Error::ListenApiError => { println!("API Error: {}", err); } |
| 64 | + Error::ApiConnectionError => { println!("Connection Issue: {}", err); } |
| 65 | + Error::Reqwest(err) => { println!("Reqwest HTTP Client Error: {}", err); } |
| 66 | + Error::Json(err) => { println!("JSON Parsing Error: {}", err); } |
| 67 | + } |
| 68 | + } |
| 69 | + }; |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +If `apiKey` is `None`, then we'll connect to a [mock server](https://www.listennotes.com/api/tutorials/#faq0) that returns fake data for testing purposes. |
| 74 | + |
| 75 | + |
| 76 | +### Handling errors |
| 77 | + |
| 78 | +Unsuccessful requests return errors. |
| 79 | + |
| 80 | +| Error | Description | |
| 81 | +| ------------- | ------------- | |
| 82 | +| AuthenticationError | wrong api key or your account is suspended | |
| 83 | +| InvalidRequestError | something wrong on your end (client side errors), e.g., missing required parameters | |
| 84 | +| RateLimitError | you are using FREE plan and you exceed the quota limit | |
| 85 | +| NotFoundError | endpoint not exist, or podcast / episode not exist | |
| 86 | +| ApiConnectionError | failed to connect to Listen API servers | |
| 87 | +| ListenApiError | something wrong on our end (unexpected server errors) | |
| 88 | + |
| 89 | +All errors can be found in [this file](https://github.com/ListenNotes/podcast-api-rust/blob/main/src/error.rs). |
| 90 | + |
| 91 | + |
| 92 | +## Development |
| 93 | + |
| 94 | +### Check |
5 | 95 | - formatting: `cargo fmt -- --check`
|
6 | 96 | - valid code: `cargo check`
|
7 | 97 | - linting: `cargo clippy`
|
8 | 98 |
|
9 |
| -## Open Docs |
| 99 | +### Open Docs |
10 | 100 | `cargo doc --open`
|
11 | 101 |
|
12 |
| -## Build |
| 102 | +### Build |
13 | 103 | `cargo build`
|
14 | 104 |
|
15 |
| -## Test |
| 105 | +### Test |
16 | 106 | `cargo test`
|
17 | 107 |
|
18 |
| -## Usage |
19 |
| -Add this to your `Cargo.toml`: |
20 |
| -```toml |
21 |
| -[dependencies] |
22 |
| -podcast-api = "0.1" |
23 |
| -``` |
| 108 | +### Run example app |
| 109 | +```sh |
| 110 | +cd examples/sample && cargo run |
| 111 | +``` |
0 commit comments