-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import json | ||
|
||
pub struct Response { | ||
pub: | ||
results []Result = []Result{len: 0} @[json: list] | ||
tags []string = []string{len: 0} @[json: tags] | ||
kind string @[json: result_type] | ||
} | ||
|
||
pub struct Result { | ||
pub: | ||
id int @[json: defid] | ||
author string @[json: author] | ||
definition string @[json: definition] | ||
link string @[json: permalink] | ||
thumbs_down int @[json: thumbs_down] | ||
thumbs_up int @[json: thumbs_up] | ||
word string @[json: word] | ||
date string @[json: written_on] | ||
audio_samples []string @[json: sound_urls] | ||
example string @[json: example] | ||
} | ||
|
||
pub fn define(word string) !&Response { | ||
resp := '{"list":[{"defid":3439287}]}' | ||
response := json.decode(Response, resp) or { return err } | ||
return &response | ||
} | ||
|
||
fn test_main() { | ||
response := define('')! | ||
assert response.results.len > 0 | ||
assert response.results[0].id == 3439287 | ||
} |
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