| 1 | import json |
| 2 | |
| 3 | pub struct Response { |
| 4 | pub: |
| 5 | results []Result = []Result{len: 0} @[json: list] |
| 6 | tags []string = []string{len: 0} @[json: tags] |
| 7 | kind string @[json: result_type] |
| 8 | } |
| 9 | |
| 10 | pub struct Result { |
| 11 | pub: |
| 12 | id int @[json: defid] |
| 13 | author string @[json: author] |
| 14 | definition string @[json: definition] |
| 15 | link string @[json: permalink] |
| 16 | thumbs_down int @[json: thumbs_down] |
| 17 | thumbs_up int @[json: thumbs_up] |
| 18 | word string @[json: word] |
| 19 | date string @[json: written_on] |
| 20 | audio_samples []string @[json: sound_urls] |
| 21 | example string @[json: example] |
| 22 | } |
| 23 | |
| 24 | pub fn define(word string) !&Response { |
| 25 | resp := '{"list":[{"defid":3439287}]}' |
| 26 | response := json.decode(Response, resp) or { return err } |
| 27 | return &response |
| 28 | } |
| 29 | |
| 30 | fn test_main() { |
| 31 | response := define('')! |
| 32 | assert response.results.len > 0 |
| 33 | assert response.results[0].id == 3439287 |
| 34 | } |
| 35 | |