Skip to content

Instantly share code, notes, and snippets.

@iraniamir
Last active January 5, 2017 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iraniamir/2ee8118e1debf55f3d34b0c3cd9ce420 to your computer and use it in GitHub Desktop.
Save iraniamir/2ee8118e1debf55f3d34b0c3cd9ce420 to your computer and use it in GitHub Desktop.
aparat.com application programing interface
var Client = require('node-rest-client').Client;
var client = new Client();
var cb = require('cb');
class Actions {
constructor() {
this.timeout = 10000; // 10 Sec
}
get(url, query, callback) {
this.makeRequest(url, query, 'GET', cb(function(res) {
callback(res);
}).timeout(this.timeout));
}
put(url, query, callback) {
this.makeRequest(url, query, 'PUT', cb(function(res) {
callback(res);
}).timeout(this.timeout));
}
post(url, query, callback) {
this.makeRequest(url, query, 'POST', cb(function(res) {
callback(res);
}).timeout(this.timeout));
}
delete(url, query, callback) {
this.makeRequest(url, query, 'DELETE', cb(function(res) {
callback(res);
}).timeout(this.timeout));
}
makeRequest(request, query, typeReq, callback) {
// registering remote methods
client.registerMethod('jsonMethod', request, typeReq);
client.methods.jsonMethod(query, function(data, response) {
callback(JSON.parse(data.toString('utf8')));
});
}
}
module.exports = new Actions();
var Action = require('./actions');
var path = require('path');
var cb = require('cb');
class AparatApi {
constructor() {
this.api_adress = 'http://www.aparat.com/etc/api/';
}
videohash(id, callback) {
const adress = this.api_adress + path.join('video', 'videohash', id);
Action.get(adress, {}, cb(function(res) {
callback((res.video.title) ? res.video : null);
}));
}
mostviewedvideos(callback) {
const adress = this.api_adress + 'mostviewedvideos';
Action.get(adress, {}, cb(function(res) {
callback(res.mostviewedvideos);
}));
}
lastvideos(perPage, callback) {
const adress = this.api_adress + path.join('lastvideos', 'perpage', perPage);
Action.get(adress, {}, cb(function(res) {
callback(res.lastvideos);
}));
}
vitrinvideos(callback) {
const adress = this.api_adress + 'vitrinvideos';
Action.get(adress, {}, cb(function(res) {
callback(res.vitrinvideos);
}));
}
videoRecom(id, perPage, callback) {
const adress = this.api_adress + path.join('videoRecom', 'videohash', id, 'perpage', perPage);
Action.get(adress, {}, cb(function(res) {
callback(res.videorecom);
}));
}
}
module.exports = new AparatApi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment