-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from libellis/feature/user-domain-model
Add User Domain Model that Maps Soundcloud API response.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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,3 +1,9 @@ | ||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
pub mod user; | ||
pub use user::*; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
|
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,57 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
struct User { | ||
id: u32, | ||
username: String, | ||
|
||
// TODO: Map these two to valid URL type rather than String. | ||
avatar_url: String, | ||
permalink_url: String, | ||
|
||
city: String, | ||
// TODO: Map this to country code to better utilize type system. | ||
country: String, | ||
track_count: u32, | ||
private_tracks_count: u32, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::User; | ||
|
||
#[test] | ||
fn mapping_from_api_response_works() { | ||
let mock_api_response = r#" | ||
{ | ||
"id": 3207, | ||
"permalink": "jwagener", | ||
"username": "Johannes Wagener", | ||
"uri": "https://api.soundcloud.com/users/3207", | ||
"permalink_url": "https://soundcloud.com/jwagener", | ||
"avatar_url": "https://i1.sndcdn.com/avatars-000001552142-pbw8yd-large.jpg?142a848", | ||
"country": "Germany", | ||
"full_name": "Johannes Wagener", | ||
"city": "Berlin", | ||
"description": "<b>Hacker at SoundCloud</b>\r\n\r\nSome of my recent Hacks:\r\n\r\nsoundiverse.com \r\nbrowse recordings with the FiRe app by artwork\r\n\r\ntopbillin.com \r\nfind people to follow on SoundCloud\r\n\r\nchatter.fm \r\nget your account hooked up with a voicebox\r\n\r\nrecbutton.com \r\nrecord straight to your soundcloud account", | ||
"discogs_name": null, | ||
"myspace_name": null, | ||
"website": "http://johannes.wagener.cc", | ||
"website_title": "johannes.wagener.cc", | ||
"online": true, | ||
"track_count": 12, | ||
"playlist_count": 1, | ||
"followers_count": 416, | ||
"followings_count": 174, | ||
"public_favorites_count": 26, | ||
"plan": "Pro Plus", | ||
"private_tracks_count": 63, | ||
"private_playlists_count": 3, | ||
"primary_email_confirmed": true | ||
}"#; | ||
|
||
let u: User = serde_json::from_str(mock_api_response).unwrap(); | ||
|
||
assert_eq!(u.id, 3207); | ||
} | ||
} |