textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
74 lines (73 loc) • 2.59 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../core/api");
/**
* Likes is an API module for managing thread/block likes
*
* Likes are added as blocks in a thread, which target another block, usually a file(s).
*
* @extends API
*/
class Likes extends api_1.API {
/**
* Adds a like to a block
*
* @param block Target block ID. Usually a file(s) block.
* @returns The generated like block
*/
add(block) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`blocks/${block}/likes`);
return response.json();
});
}
/**
* Retrieves a like by ID
*
* @param id ID of the target like
* @returns The target like block
*/
get(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet(`blocks/${id}/like`);
return response.json();
});
}
/**
* Retrieves a list of likes on a target block
*
* @param block ID of the target block
* @returns An array of likes associated with the target block
*/
list(block) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet(`blocks/${block}/likes`);
return response.json();
});
}
/**
* Ignores a block like by its ID
*
* This adds an 'ignore' thread block targeted at the like.
* Ignored blocks are by default not returned when listing.
*
* @param id ID of the like
* @returns The added ignore block
*/
ignore(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendDelete(`blocks/${id}`);
return response.json();
});
}
}
exports.default = Likes;
;