-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.js
33 lines (29 loc) · 918 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { encode } = require("querystring");
const fetch = require("isomorphic-unfetch");
const URL = "http://www.radio-browser.info/webservice";
const STATIONS = `/json/stations`;
const BY_ID = `${URL}${STATIONS}/byid`;
const SEARCH = `${URL}${STATIONS}/search`;
const request = (url, query = {}, pagination = {}) =>
console.log([url, "?", encode(query)].join("")) ||
fetch([url, "?", encode(query)].join(""), {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"User-Agent": "bemba/radio-gql"
},
body: JSON.stringify({
order: "votes",
reverse: "true",
limit: 50,
...pagination
})
}).then(res => res.json());
const get = id => request(`${BY_ID}/${id}`).then(([station]) => station);
const search = ({ query, pagination }) =>
request(`${SEARCH}`, query, pagination);
module.exports = {
get,
search
};