Skip to content

Commit

Permalink
Normalize sidebar listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico B committed Aug 6, 2017
1 parent ad06e2a commit 69de21e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/data/sources/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class API {
};
}

constructor(uri, type, apiKey) {
constructor(uri, type, baseHost, apiKey) {
const axiosConfig = API.createAxiosConfig(uri, apiKey);
const host = baseHost || hostName(uri);
this.fetch = API.fetch(axiosConfig);
this.name = toHumanName(type);
this.host = hostName(uri);
this.host = host;
this.type = type;
this.faviconURL = findFavicon(uri);
this.faviconURL = findFavicon(host);
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/data/sources/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
const API = require('./api');
const types = require('../types');
const queryString = require('query-string');
const { valueSeq } = require('../../utils');

class Sidebar extends API {
constructor() {
const baseURL = 'https://sidebar.io/';
super(baseURL, types.Sidebar);
this.normalize = this.normalize.bind(this);
}

normalize(data) {
return data.map(({ headline, url, date }) => (
{
title: headline,
publishedAt: date,
link: valueSeq(queryString.parse(url))[0],
type: this.type,
}
));
}

getListing() {
return this.fetch('/api');
}

get listing() {
return this.getListing();
return this.getListing()
.then(this.normalize)
.catch(e => { throw new Error(e) });
}
}

Expand Down

0 comments on commit 69de21e

Please sign in to comment.