maplestory-openapi
Version:
This JavaScript library enables the use of the MapleStory OpenAPI of Nexon.
113 lines (110 loc) • 4.45 kB
JavaScript
import { MapleStoryFriendsApi as MapleStoryFriendsApi$1 } from '../common/mapleStoryFriendsApi.js';
import { CubeHistoryResponseDto } from './dto/history/cubeHistory.js';
import { PotentialHistoryResponseDto } from './dto/history/potentialHistory.js';
import { StarforceHistoryResponseDto } from './dto/history/starforceHistory.js';
import { AchievementDto } from './dto/user/achievement.js';
import { CharacterListDto } from './dto/user/characterList.js';
/**
* MapleStory Friends API client for KMS<br>
* This is an implementation of <a href="https://openapi.nexon.com/ko/friends/maplestory/?id=36">MapleStory Friends API</a>
*/
class MapleStoryFriendsApi extends MapleStoryFriendsApi$1 {
subUrl = 'maplestory';
timezoneOffset = 540;
constructor(accessToken) {
super(accessToken);
}
//#region 계정 정보 조회
/**
* 계정의 보유 캐릭터 목록을 조회합니다.
* - 이 항목을 조회하시려면 NEXON Open ID 클라이언트 설정에서 '캐릭터 목록'을 활용 데이터 항목으로 선택해주세요.
* - 이후 자세한 데이터 호출 및 활용 방법은 <a href="https://openapi.nexon.com/ko/open-id/development-guide/">NEXON Open ID 개발 가이드 문서</a>를 참조해주세요.
*/
async getCharacterList() {
const path = `${this.subUrl}/v1/character/list`;
const { data } = await this.client.get(path);
return new CharacterListDto(data);
}
/**
* 계정의 업적 정보를 조회합니다.
* - 이 항목을 조회하시려면 NEXON Open ID 클라이언트 설정에서 '업적 정보'를 활용 데이터 항목으로 선택해주세요.
* - 이후 자세한 데이터 호출 및 활용 방법은 <a href="https://openapi.nexon.com/ko/open-id/development-guide/">NEXON Open ID 개발 가이드 문서</a>를 참조해주세요.
*/
async getAchievement() {
const path = `${this.subUrl}/v1/user/achievement`;
const { data } = await this.client.get(path);
return new AchievementDto(data);
}
async getStarforceHistory(count, parameter) {
const path = `${this.subUrl}/v1/history/starforce`;
const query = {
count,
};
if (typeof parameter === 'string') {
query.cursor = parameter;
}
else if (typeof parameter === 'object' || parameter === undefined) {
query.date = this.toDateString(parameter ??
this.getProperDefaultDateOptions({
hour: 0,
minute: 0,
dateOffset: 0,
}), {
year: 2023,
month: 12,
day: 27,
});
}
const { data } = await this.client.get(path, {
params: query,
});
return new StarforceHistoryResponseDto(data);
}
async getCubeHistory(count, parameter) {
const path = `${this.subUrl}/v1/history/cube`;
const query = {
count,
};
if (typeof parameter === 'string') {
query.cursor = parameter;
}
else if (typeof parameter === 'object' || parameter === undefined) {
query.date = this.toDateString(parameter ??
this.getProperDefaultDateOptions({
hour: 0,
minute: 0,
dateOffset: 0,
}));
}
const { data } = await this.client.get(path, {
params: query,
});
return new CubeHistoryResponseDto(data);
}
async getPotentialHistory(count, parameter) {
const path = `${this.subUrl}/v1/history/potential`;
const query = {
count,
};
if (typeof parameter === 'string') {
query.cursor = parameter;
}
else if (typeof parameter === 'object' || parameter === undefined) {
query.date = this.toDateString(parameter ??
this.getProperDefaultDateOptions({
hour: 0,
minute: 0,
dateOffset: 0,
}), {
year: 2024,
month: 1,
day: 25,
});
}
const { data } = await this.client.get(path, {
params: query,
});
return new PotentialHistoryResponseDto(data);
}
}
export { MapleStoryFriendsApi };