dcard
Version:
👫 Unofficial Dcard API wrapper for Node.js developers.
93 lines (75 loc) • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getAdConfig = exports.clearLocalStorage = exports.setLocalItem = exports.getLocalItem = exports.getPrivilege = exports.updateMe = exports.getPendingFields = exports.getMe = undefined;
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _lodash = require('lodash');
var _request = require('../request');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Get the profile of yourself.
* @example
* getMe().then((res) => {
* console.log(res);
* });
*/
/* weak */
var getMe = exports.getMe = function getMe() {
return (0, _request.api)('me').then(_request.filterError).then(_request.parseJSON);
};
/**
* Get the pending fields.
* @example
* getPendingFields().then((res) => {
* console.log(res);
* });
*/
var getPendingFields = exports.getPendingFields = function getPendingFields() {
return (0, _request.api)('me/fields').then(_request.filterError).then(_request.parseJSON);
};
/**
* Update your profile.
* @example
* const data = {...}; //key listed above could be used.
* updateMe(data).then((res) => {
* console.log(res);
* });
*/
var updateMe = exports.updateMe = function updateMe(data) {
return (0, _request.api)('me', {
method: 'put',
body: (0, _lodash.pick)(data, ['name', 'birthday', 'gender', 'school', 'department', 'talent', 'wantToTry', 'exchange', 'club', 'lecture', 'lovedCountry', 'trouble', 'affection', 'identityCardId'])
}).then(_request.filterError).then(_request.parseJSON);
};
var getPrivilege = exports.getPrivilege = function getPrivilege(data) {
return (0, _request.api)('me/validate', {
method: 'post',
body: data
}).then(function (res) {
var response = res;
if (res.status !== 204) {
response.error = true;
}
return (0, _lodash.pick)(response, ['status', 'error']);
});
};
var getLocalItem = exports.getLocalItem = function getLocalItem(key) {
var value = window.localStorage.getItem(key);
if (!value) {
return {};
}
return JSON.parse(value);
};
var setLocalItem = exports.setLocalItem = function setLocalItem(key, value) {
return localStorage.setItem(key, (0, _stringify2.default)(value));
};
var clearLocalStorage = exports.clearLocalStorage = function clearLocalStorage() {
return window.localStorage.clear();
};
var getAdConfig = exports.getAdConfig = function getAdConfig(keys) {
return (0, _request.api)('configs?' + keys.join('&'), {
method: 'get'
}).then(_request.filterError).then(_request.parseJSON);
};