aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/tips-and-tricks.md
diff options
context:
space:
mode:
authorBastien Wirtz <bastien.wirtz@gmail.com>2021-03-04 18:40:07 -0800
committerGitHub <noreply@github.com>2021-03-04 18:40:07 -0800
commitcc7ff885527283d97f32347210b0370e8477c4ff (patch)
tree6c2eda44ed25cf2cd91cced7ab159ecd5e6735f7 /docs/tips-and-tricks.md
parent7bcfce6bdad32ec392279867af7f3f3c67a972b3 (diff)
parent9542de6eb25bfa20b376920b607db864c9e20a7a (diff)
downloadhomer-cc7ff885527283d97f32347210b0370e8477c4ff.tar.gz
homer-cc7ff885527283d97f32347210b0370e8477c4ff.tar.zst
homer-cc7ff885527283d97f32347210b0370e8477c4ff.zip
Merge pull request #175 from luixal/message-remote-fields-mappingv21.03.1
Adds mapping remote field to Homer expected ones when loading message from URL
Diffstat (limited to 'docs/tips-and-tricks.md')
-rw-r--r--docs/tips-and-tricks.md58
1 files changed, 58 insertions, 0 deletions
diff --git a/docs/tips-and-tricks.md b/docs/tips-and-tricks.md
index 2719fc5..94167fb 100644
--- a/docs/tips-and-tricks.md
+++ b/docs/tips-and-tricks.md
@@ -113,6 +113,64 @@ docker create \
113 113
114 114
115## Get the news headlines in Homer 115## Get the news headlines in Homer
116
117### Mapping Fields
118Most times, the url you're getting headlines from follows a different schema than the one expected by Homer.
119
120For example, if you would like to show jokes from ChuckNorris.io, you'll find that the url https://api.chucknorris.io/jokes/random is giving you info like this:
121
122```json
123{
124 "categories": [],
125 "created_at": "2020-01-05 13:42:22.089095",
126 "icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
127 "id": "MR2-BnMBR667xSpQBIleUg",
128 "updated_at": "2020-01-05 13:42:22.089095",
129 "url": "https://api.chucknorris.io/jokes/MR2-BnMBR667xSpQBIleUg",
130 "value": "Chuck Norris can quitely sneak up on himself"
131}
132```
133
134but... you need that info to be transformed to something like this:
135
136```json
137{
138 "title": "MR2-BnMBR667xSpQBIleUg",
139 "content": "Chuck Norris can quitely sneak up on himself"
140}
141```
142
143Now, you can do that using the `mapping` field in your `message` configuration. This example would be something like this:
144
145```yml
146message:
147 url: https://api.chucknorris.io/jokes/random
148 mapping:
149 title: 'id'
150 content: 'value'
151```
152
153As you would see, using the ID as a title doesn't seem nice, that's why when a field is empty it would keep the default values, like this:
154
155```yml
156message:
157 url: https://api.chucknorris.io/jokes/random
158 mapping:
159 content: 'value'
160 title: "Chuck Norris Facts!"
161```
162
163and even an error message in case the `url` didn't respond or threw an error:
164
165```yml
166message:
167 url: https://api.chucknorris.io/jokes/random
168 mapping:
169 content: 'value'
170 title: "Chuck Norris Facts!"
171 content: "Message could not be loaded"
172```
173
116#### `by @JamiePhonic` 174#### `by @JamiePhonic`
117 175
118Homer allows you to set a "message" that will appear at the top of the page, however, you can also supply a `url:`. 176Homer allows you to set a "message" that will appear at the top of the page, however, you can also supply a `url:`.