Skip to content

Commit

Permalink
Added /skyblock/calendar and /skyblock/events endpoints (slothpixel#683)
Browse files Browse the repository at this point in the history
* added /skyblock/calendar and /skyblock/events endpoints

* added from and to parameters

query must have either 'to' or 'years' parameter

* remove duplicate events

* added special timestamps support

- fixed stopatyearend parameter finally
- added some more errors
- added from to be at least yearZero and years to maximum of 10

* whoops

fixed an error location & updated the spec

* updated graphql to support custom date strings
  • Loading branch information
camnwalter authored and ChristianDobbie committed Jan 10, 2022
1 parent b10fdf0 commit c84b08d
Show file tree
Hide file tree
Showing 6 changed files with 616 additions and 1 deletion.
11 changes: 11 additions & 0 deletions routes/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const buildCounts = require('../store/buildCounts');
const buildPlayerStatus = require('../store/buildPlayerStatus');
const { getAuctions, queryAuctionId } = require('../store/queryAuctions');
const { buildProfile } = require('../store/buildSkyBlockProfiles');
const { buildSkyblockCalendar, buildSkyblockEvents } = require('../store/buildSkyblockCalendar');
const { getGuildFromPlayer, getGuildFromName } = require('../store/buildGuild');
const leaderboards = require('../store/leaderboards');
const redis = require('../store/redis');
Expand Down Expand Up @@ -143,6 +144,16 @@ class SkyblockResolver {
}
return bazaar[item_id];
}

events() {
return buildSkyblockEvents();
}

calendar({
events, from, to, years, stopatyearend,
}) {
return buildSkyblockCalendar(events, from, to, years, stopatyearend);
}
}

const graphql = graphqlHTTP({
Expand Down
48 changes: 48 additions & 0 deletions routes/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,52 @@ module.exports = {
type: 'string',
},
},
calendarEventsParam: {
name: 'events',
in: 'query',
description: 'The specific events you want to view the times. If left blank, will return all events. Multiple events separated by commas.',
required: false,
schema: {
type: 'string',
},
},
calendarFromParam: {
name: 'from',
in: 'query',
description: 'Date from which to get events. Uses a Unix timestamp with milliseconds or a [custom date string](https://github.com/slothpixel/core/wiki/Using-custom-date-parameters). E.g. to get past 24 hours, use `now-1d`.',
required: false,
default: 'now',
schema: {
type: 'string',
},
},
calendarToParam: {
name: 'to',
in: 'query',
description: 'Date to get calendar events until to. Uses a Unix timestamp with milliseconds or a [custom date string](https://github.com/slothpixel/core/wiki/Using-custom-date-parameters). E.g. to reference the date 3 hours ago, use `now-3h`.',
required: false,
default: 'now',
schema: {
type: 'string',
},
},
calendarYearsParam: {
name: 'years',
in: 'query',
description: 'The amount of Skyblock years to query.',
required: false,
schema: {
type: 'integer',
},
},
calendarStopAtYearEndParam: {
name: 'stopatyearend',
in: 'query',
description: 'Whether to stop the data at the year end. If true, will only show data until the end of the current Skyblock year, otherwise will return the full year starting from the \'from\' timestamp, possibly including part of the next year.',
default: false,
required: false,
schema: {
type: 'boolean',
},
},
};
63 changes: 63 additions & 0 deletions routes/spec.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,53 @@ type SkyblockQuery {
"""
item_id: String!
): SkyblockBazaar

"""
Returns all SkyBlock events found in the calendar
Equivalent to GET /skyblock/events
"""
events: JSON

"""
Get Skyblock calendar information
Equivalent to GET /skyblock/calendar
"""
calendar(
"""
The events enum in which you would like to filter. If left blank, it will return
every event. All available events can be found on the
[events endpoint](https://api.slothpixel.me/api/skyblock/events).
"""
events: String

"""
Date from which to get events. Uses a
[custom date string](https://github.com/slothpixel/core/wiki/Using-custom-date-parameters).
E.g. to get past 24 hours, use `now-1d`.
"""
from: String

"""
Date to get calendar events until to. Uses a
[custom date string](https://github.com/slothpixel/core/wiki/Using-custom-date-parameters).
E.g. to reference the date 3 hours ago, use `now-3h`.
"""
to: String

"""
The amount of Skyblock years to query.
"""
years: Int

"""
Whether to stop the data at the year end. If true, will only show data until
the end of the current Skyblock year, otherwise will return the full year starting
from the \'from\' timestamp, possibly including part of the next year.
"""
stopatyearend: Boolean
): SkyblockCalendar
}

"""
Expand Down Expand Up @@ -2769,6 +2816,22 @@ type SkyblockBazaar {
week_historic: [Week_historicListItem]
}

type SkyblockCalendar {
from: Float
to: Float
date: String
day: Int
month: String
year: Int
time: String
minute: Int
hour: Int
next_day_countdown: Float
next_month_countdown: Float
next_year_countdown: Float
events: JSON
}

"""
Player stats in Skywars
"""
Expand Down
169 changes: 168 additions & 1 deletion routes/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const buildCounts = require('../store/buildCounts');
const { queryAuctionId } = require('../store/queryAuctions');
const { getGuildFromPlayer, getGuildFromName, getGuildFromID } = require('../store/buildGuild');
const { buildProfileList, buildProfile } = require('../store/buildSkyBlockProfiles');
const { buildSkyblockCalendar, buildSkyblockEvents } = require('../store/buildSkyblockCalendar');
const { playerObject } = require('./objects');
const { populatePlayers, getPlayer, PlayerError } = require('../store/buildPlayer');
const { getMetadata } = require('../store/queries');
Expand All @@ -22,7 +23,8 @@ const {
playerNameParam, gameNameParam, typeParam, columnParam, filterParam, sortByParam,
limitParam, significantParam, populatePlayersParam, templateParam, itemIdParam, bazaarItemIdParam,
fromParam, toParam, auctionUUIDParam, itemUUIDParam, activeParam, pageParam, sortOrderParam,
profileIdParam, guildNameParam, guildIDParam,
profileIdParam, guildNameParam, guildIDParam, calendarEventsParam, calendarFromParam, calendarToParam,
calendarYearsParam, calendarStopAtYearEndParam,
} = require('./parameters');
const packageJson = require('../package.json');

Expand Down Expand Up @@ -2285,6 +2287,171 @@ Consider supporting The Slothpixel Project on Patreon to help cover the hosting
},
},
},
'/skyblock/events': {
get: {
summary: 'SkyBlock event spec',
description: 'Returns SkyBlock events. Use key for the events parameter in /calendar/events endpoint',
operationId: 'getSkyblockEvents',
tags: [
'skyblock',
],
responses: {
200: {
description: 'successful operation',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
EVENT_ENUM: {
description: 'The cleaner name of the event. Use key for the events parameter in /calendar/events endpoint',
type: 'string',
},
},
},
},
},
},
},
route: () => '/skyblock/events',
func: (_, response) => {
response.json(buildSkyblockEvents());
},
},
},
'/skyblock/calendar': {
get: {
summary: 'Get Skyblock calendar information',
description: 'Returns information about the SkyBlock calendar',
operationId: 'getSkyblockCalendar',
tags: [
'skyblock',
],
parameters: [
calendarEventsParam, calendarFromParam, calendarToParam, calendarYearsParam, calendarStopAtYearEndParam,
],
responses: {
200: {
description: 'successful operation',
content: {
'application/json': {
schema: {
type: 'object',
properties: {
from: {
description: 'The timestamp of the \'from\' parameter',
type: 'integer',
},
to: {
description: 'The timestamp of the \'to\' parameter',
type: 'integer',
},
date: {
description: 'The date based on \'from\' parameter, e.g Early Winter 14th',
type: 'string',
},
day: {
description: 'The current day based on \'from\' parameter',
type: 'integer',
},
month: {
description: 'The current month based on \'from\' parameter',
type: 'string',
},
year: {
description: 'The current year based on \'from\' parameter',
type: 'integer',
},
time: {
description: 'The current time based on \'from\' parameter',
type: 'string',
},
minute: {
description: 'The current minute based on \'from\' parameter',
type: 'integer',
},
hour: {
description: 'The current hour based on \'from\' parameter',
type: 'integer',
},
next_day_countdown: {
description: 'The time until the next day based on \'from\' parameter',
type: 'integer',
},
next_month_countdown: {
description: 'The time until the next month based on \'from\' parameter',
type: 'integer',
},
next_year_countdown: {
description: 'The time until the next year based on \'from\' parameter',
type: 'integer',
},
events: {
type: 'object',
properties: {
EVENT_ENUM: {
type: 'object',
properties: {
name: {
description: 'The cleaner name of the event',
type: 'string',
},
duration: {
description: 'The time the event is active',
type: 'integer',
},
events: {
type: 'array',
items: {
type: 'object',
properties: {
start_timestamp: {
description: 'The starting timestamp of the event',
type: 'integer',
},
end_timestamp: {
description: 'The ending timestamp of the event',
type: 'integer',
},
starting_in: {
description: 'The time until the event starts',
type: 'integer',
},
ending_in: {
description: 'The time until the event ends',
type: 'integer',
},
pet: {
description: 'The type of pet if the event is a Traveling Zoo',
type: 'string',
},
},
},
},
},
},
},
},
},
},
},
},
},
},
route: () => '/skyblock/calendar',
func: (request, response) => {
const {
events, from, to, years, stopatyearend,
} = request.query;
try {
const result = buildSkyblockCalendar(events, from, to, years, stopatyearend);
response.json(result);
} catch (error) {
response.status(400).json({ error: error.message });
}
},
},
},
'/leaderboards': {
get: {
summary: 'Allows query of dynamic leaderboards',
Expand Down
Loading

0 comments on commit c84b08d

Please sign in to comment.