Skip to content

Commit

Permalink
Fetcher for COSCUP APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
timdream committed Jul 11, 2013
1 parent 3486540 commit 4c9cf0a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions assets/fetchers.js
Expand Up @@ -308,6 +308,39 @@ GooglePlusFetcher.prototype.handleResponse = function gpf_handleResponse(res) {
this.app.handleData(text, _('google-plus-title'));
};

var COSCUPFetcher = function COSCUPFetcher(opts) {
this.types = ['coscup'];
this.fields = ['name', 'speaker', 'bio', 'abstract'];
};
COSCUPFetcher.prototype = new JSONPFetcher();
COSCUPFetcher.prototype.API_URL = 'http://coscup.org/%year/api/program';
COSCUPFetcher.prototype.HTML_REGEXP =
/<[^>]+?>|\(.+?\.\.\.\)|\&\w+\;|<script.+?\/script\>/ig;
COSCUPFetcher.prototype.getData = function cf_getData(dataType, data) {
var year = this.year = data;
this.requestData(this.API_URL.replace(/%year/, year));
};
COSCUPFetcher.prototype.handleResponse = function cf_handleResponse(res) {
if (!res) {
this.app.handleData('');
return;
}

var text = [];
var fields = this.fields;
var HTML_REGEXP = this.HTML_REGEXP;
var programs = (Array.isArray(res)) ? res : res['program'];

programs.forEach(function cf_handleProgram(program) {
fields.forEach(function cf_fields_forEach(field) {
if (program[field])
text.push(program[field].replace(HTML_REGEXP, ''));
});
});

this.app.handleData(text.join('\n'), _('coscup-title', { year: this.year }));
};

var FacebookFetcher = function FacebookFetcher() {
this.types = ['facebook'];
};
Expand Down
1 change: 1 addition & 0 deletions assets/start.js
Expand Up @@ -145,6 +145,7 @@ window.onerror = function onerror(message, url, line) {
app.addFetcher(new FileFetcher());
app.addFetcher(new ListFetcher());
app.addFetcher(new FeedFetcher());
app.addFetcher(new COSCUPFetcher());
app.addFetcher(new WikipediaFetcher());
app.addFetcher(new FacebookFetcher());
app.addFetcher(new GooglePlusFetcher());
Expand Down
1 change: 1 addition & 0 deletions locales/wordcloud.en-US.properties
Expand Up @@ -164,5 +164,6 @@ plain-text-file-please=Please select a plain text file.
my-word-cloud=My HTML5 Word Cloud
feed-title=HTML5 Word Cloud of {{title}}
wikipedia-title=HTML5 Word Cloud of Wikipedia entry: {{title}}
coscup-title=COSCUP {{year}}
google-plus-title=HTML5 Word Cloud of a Google+ page
facebook-title=HTML5 Word Cloud of {{name}}'s Facebook
1 change: 1 addition & 0 deletions locales/wordcloud.zh-TW.properties
Expand Up @@ -164,5 +164,6 @@ plain-text-file-please=請選取純文字格式的檔案。
my-word-cloud=我做的 HTML5 文字雲
feed-title={{title}} 的文字雲
wikipedia-title=維基百科條目《{{title}}》的文字雲
coscup-title=開源人年會 {{year}}
google-plus-title=某個 Google+ 頁面的文字雲
facebook-title={{name}} 的 Facebook 文字雲

0 comments on commit 4c9cf0a

Please sign in to comment.