diff --git a/docs/endpoints.md b/docs/endpoints.md index 5798fd4..50763e4 100644 --- a/docs/endpoints.md +++ b/docs/endpoints.md @@ -55,6 +55,8 @@ client.language('de').items().all() - [`api().account().gliders()`](#apiaccountgliders) - The unlocked gliders of the account. - [`api().account().home().cats()`](#apiaccounthomecats) - The unlocked cats in the home instance of the account. - [`api().account().home().nodes()`](#apiaccounthomenodes) - The unlocked nodes in the home instance of the account. +- ['api().account().homestead().decorations()`](#apiaccounthomesteaddecorations) - The account's currently used decorations in homestead. +- ['api().account().homestead().glyphs()`](#apiaccounthomesteadglyphs) - The account's glyphs stored in homestead. - [`api().account().inventory()`](#apiaccountinventory) - The shared inventory slots of the account. - [`api().account().jadebots()`](#apiaccountjadebots) - The unlocked jadebots of the account. - [`api().account().legendaryarmory()`](#apiaccountlegendaryarmory) - The items in the legendary armory of the account. @@ -83,7 +85,7 @@ client.language('de').items().all() - [`api().account().wizardsvault().daily()`](#apiaccountwizardsvaultdaily) - The account's daily objectives in the Wizard's Vault. - [`api().account().wizardsvault().weekly()`](#apiaccountwizardsvaultweekly) - The account's weekly objectives in the Wizard's Vault. - [`api().account().wizardsvault().special()`](#apiaccountwizardsvaultspecial) - The account's seasonal objectives in the Wizard's Vault. -- [`api().account().worldbosses()`](#apiaccountworldbosses) - The daily worldbosses completed by the account.  +- [`api().account().worldbosses()`](#apiaccountworldbosses) - The daily worldbosses completed by the account. - [`api().achievements()`](#apiachievements) - Information about achievements. - [`api().achievements().categories()`](#apiachievementscategories) - The categories for achievements. - [`api().achievements().groups()`](#apiachievementsgroups) - The top-level groups for achievements. @@ -141,6 +143,9 @@ client.language('de').items().all() - [`api().guild().treasury()`](#apiguildtreasury) - Information about the items in the guild's treasury. - [`api().home().cats()`](#apihomecats) - Information about home instance cats. - [`api().home().nodes()`](#apihomenodes) - Information about home instance nodes. +- ['api().homestead().decorations()`](#apihomesteaddecorations) - Information about homestead decorations. +- ['api().homestead().decorations().categories()`](#apihomesteaddecorationscategories) - Information about homestead decoration categories. +- ['api().homestead().glyphs()`](#apihomesteadglyphs) - Information about glyphs in homestead. - [`api().items()`](#apiitems) - Information about items that were discovered by players. - [`api().itemstats()`](#apiitemstats) - Information about stats for items. - [`api().mailcarriers()`](#apimailcarriers) - Information about mailcarriers. @@ -387,6 +392,36 @@ Alternative method of calling [`api().commerce().delivery()`](#apicommercedelive --- +### `api().account().homestead().decorations()` + +> The account's currently used decorations in homestead. + +- **API-URL:** [/v2/account/homestead/decorations](https://api.guildwars2.com/v2/account/homestead/decorations) +- **Paginated:** No +- **Bulk expanding:** No +- **Authenticated:** Yes +- **Localized:** No +- **Cache time:** 5 minutes + +[↑ Back to the overview](#available-endpoints) + +--- + +### `api().account().homestead().glyphs()` + +> The account's glyphs stored in homestead. + +- **API-URL:** [/v2/account/homestead/glyphs](https://api.guildwars2.com/v2/account/homestead/glyphs) +- **Paginated:** No +- **Bulk expanding:** No +- **Authenticated:** Yes +- **Localized:** No +- **Cache time:** 5 minutes + +[↑ Back to the overview](#available-endpoints) + +--- + ### `api().account().inventory()` > The shared inventory slots of the account. @@ -1656,6 +1691,51 @@ Alternative method of calling [`api().commerce().transactions()`](#apicommercetr --- +### `api().homestead().decorations()` + +> Information about homestead decorations. + +- **API-URL:** [/v2/homestead/decorations](https://api.guildwars2.com/v2/homestead/decorations) +- **Paginated:** Yes +- **Bulk expanding:** Yes +- **Authenticated:** No +- **Localized:** No +- **Cache time:** 24 hours + +[↑ Back to the overview](#available-endpoints) + +--- + +### `api().homestead().decorations().categories()` + +> Information about homestead decoration categories. + +- **API-URL:** [/v2/homestead/decorations/categories](https://api.guildwars2.com/v2/homestead/decorations/categories) +- **Paginated:** Yes +- **Bulk expanding:** Yes +- **Authenticated:** No +- **Localized:** No +- **Cache time:** 24 hours + +[↑ Back to the overview](#available-endpoints) + +--- + +### `api().homestead().glyphs()` + +> Information about glyphs in homestead. + +- **API-URL:** [/v2/homestead/glyphs](https://api.guildwars2.com/v2/homestead/glyphs) +- **Paginated:** Yes +- **Bulk expanding:** Yes +- **Authenticated:** No +- **Localized:** No +- **Cache time:** 24 hours + +[↑ Back to the overview](#available-endpoints) + +--- + ### `api().items()` > Information about items that were discovered by players. diff --git a/src/client.js b/src/client.js index 86d825f..acf001f 100644 --- a/src/client.js +++ b/src/client.js @@ -160,6 +160,10 @@ module.exports = class Client { return new endpoints.HomeEndpoint(this) } + homestead() { + return new endpoints.HomesteadEndpoint(this) + } + items () { return new endpoints.ItemsEndpoint(this) } diff --git a/src/endpoints/account-blob.js b/src/endpoints/account-blob.js index 2f229a0..3c70dd7 100644 --- a/src/endpoints/account-blob.js +++ b/src/endpoints/account-blob.js @@ -20,6 +20,8 @@ function blob (parent) { guilds: wrap(() => accountGuilds(client)), 'home.cats': wrap(() => client.account().home().cats().get()), 'home.nodes': wrap(() => client.account().home().nodes().get()), + 'homestead.decorations': wrap(() => client.account().homestead().decorations().get()), + 'homestead.glyphs': wrap(() => client.account().homestead().glyphs().get()), jadebots: wrap(() => client.account().jadebots().get()), legendaryarmory: wrap(() => client.account().legendaryarmory().get()), luck: wrap(() => client.account().luck().get()), @@ -42,7 +44,7 @@ function blob (parent) { skiffs: wrap(() => client.account().skiffs().get()), skins: wrap(() => client.account().skins().get()), titles: wrap(() => client.account().titles().get()), - wallet: wrap(() => client.account().wallet().get()) + wallet: wrap(() => client.account().wallet().get()), } return flow.parallel(requests).then(data => { diff --git a/src/endpoints/account.js b/src/endpoints/account.js index b88152f..0163510 100644 --- a/src/endpoints/account.js +++ b/src/endpoints/account.js @@ -61,6 +61,13 @@ class AccountEndpoint extends AbstractEndpoint { } } + homestead () { + return { + decorations: () => new HomesteadDecorationsEndpoint(this), + glyphs: () => new HomesteadGlyphsEndpoint(this) + } + } + inventory () { return new InventoryEndpoint(this) } @@ -287,6 +294,24 @@ class HomeNodesEndpoint extends AbstractEndpoint { } } +class HomesteadDecorationsEndpoint extends AbstractEndpoint { + constructor(client) { + super(client) + this.url = "/v2/account/homestead/decorations" + this.isAuthenticated = true + this.cacheTime = 5 * 60 + } +} + +class HomesteadGlyphsEndpoint extends AbstractEndpoint { + constructor(client) { + super(client) + this.url = "/v2/account/homestead/glyphs" + this.isAuthenticated = true + this.cacheTime = 5 * 60 + } +} + class InventoryEndpoint extends AbstractEndpoint { constructor (client) { super(client) diff --git a/src/endpoints/homestead.js b/src/endpoints/homestead.js new file mode 100644 index 0000000..60718dd --- /dev/null +++ b/src/endpoints/homestead.js @@ -0,0 +1,45 @@ +const AbstractEndpoint = require("../endpoint") + +module.exports = class HomesteadEndpoint extends AbstractEndpoint { + decorations() { + return new DecorationsEndpoint(this) + } + + glyphs() { + return new GlyphsEndpoint(this) + } +} + +class DecorationsEndpoint extends AbstractEndpoint { + constructor(client) { + super(client) + this.url = "/v2/homestead/decorations" + this.isPaginated = true + this.isBulk = true + this.cacheTime = 24 * 60 * 60 + } + + categories() { + return new DecorationsCategoriesEndpoint(this) + } +} + +class GlyphsEndpoint extends AbstractEndpoint { + constructor(client) { + super(client) + this.url = "/v2/homestead/glyphs" + this.isPaginated = true + this.isBulk = true + this.cacheTime = 24 * 60 * 60 + } +} + +class DecorationsCategoriesEndpoint extends AbstractEndpoint { + constructor(client) { + super(client) + this.url = "/v2/homestead/decorations/categories" + this.isPaginated = true + this.isBulk = true + this.cacheTime = 24 * 60 * 60 + } +} diff --git a/src/endpoints/index.js b/src/endpoints/index.js index 81d215d..3bc3db0 100644 --- a/src/endpoints/index.js +++ b/src/endpoints/index.js @@ -19,6 +19,7 @@ module.exports = { GlidersEndpoint: require('./gliders'), GuildEndpoint: require('./guild'), HomeEndpoint: require('./home'), + HomesteadEndpoint: require('./homestead'), ItemsEndpoint: require('./items'), ItemstatsEndpoint: require('./itemstats'), JadebotsEndpoint: require('./jadebots'), diff --git a/tests/client.spec.js b/tests/client.spec.js index 4ea9f44..3904d4b 100644 --- a/tests/client.spec.js +++ b/tests/client.spec.js @@ -235,6 +235,11 @@ describe('client', () => { expect(endpoint.cats).not.toEqual(undefined) }) + it('can get the homestead endpoint', () => { + let endpoint = client.homestead() + expect(endpoint.decorations).not.toEqual(undefined) + }) + it('can get the items endpoint', () => { let endpoint = client.items() expect(endpoint.url).toEqual('/v2/items') diff --git a/tests/endpoints/account-blob.spec.js b/tests/endpoints/account-blob.spec.js index 81b9af9..22e9e1a 100644 --- a/tests/endpoints/account-blob.spec.js +++ b/tests/endpoints/account-blob.spec.js @@ -20,6 +20,10 @@ function mockClient (hasGuildPermission) { cats: () => ({ get: () => _s([{ id: 1, hint: 'chicken' }]) }), nodes: () => ({ get: () => _s(['quartz_node', 'airship_cargo']) }) }), + homestead: () => ({ + decorations: () => ({ get: () => _s([{ id: 35, count: 50 }]) }), + glyphs: () => ({ get: () => _s(['volatility_harvesting', 'volatility_logging']) }) + }), inventory: () => ({ get: () => _s([{ id: 123, foo: 'bar' }]) }), jadebots: () => ({ get: () => _s([1, 2, 3]) }), legendaryarmory: () => ({ get: () => _s([{ id: 123, count: 1 }]) }), @@ -105,6 +109,10 @@ const expectedResponse = { cats: [{ id: 1, hint: 'chicken' }], nodes: ['quartz_node', 'airship_cargo'] }, + homestead: { + decorations: [{ id: 35, count: 50 }], + glyphs: ['volatility_harvesting', 'volatility_logging'] + }, jadebots: [1, 2, 3], legendaryarmory: [{ id: 123, count: 1 }], luck: 123, diff --git a/tests/endpoints/account.spec.js b/tests/endpoints/account.spec.js index d0be427..82e69e0 100644 --- a/tests/endpoints/account.spec.js +++ b/tests/endpoints/account.spec.js @@ -276,6 +276,36 @@ describe('endpoints > account', () => { expect(content).toEqual(['quartz_node', 'airship_cargo']) }) + it('test /v2/account/homestead/decorations', async () => { + endpoint = endpoint.homestead().decorations() + + expect(endpoint.isPaginated).toEqual(false) + expect(endpoint.isBulk).toEqual(false) + expect(endpoint.isLocalized).toEqual(false) + expect(endpoint.isAuthenticated).toEqual(true) + expect(endpoint.cacheTime).not.toEqual(undefined) + expect(endpoint.url).toEqual('/v2/account/homestead/decorations') + + fetchMock.addResponse([{ id: 35, count: 50 }]) + let content = await endpoint.get() + expect(content).toEqual([{ id: 35, count: 50 }]) + }) + + it('test /v2/account/homestead/glyphs', async () => { + endpoint = endpoint.homestead().glyphs() + + expect(endpoint.isPaginated).toEqual(false) + expect(endpoint.isBulk).toEqual(false) + expect(endpoint.isLocalized).toEqual(false) + expect(endpoint.isAuthenticated).toEqual(true) + expect(endpoint.cacheTime).not.toEqual(undefined) + expect(endpoint.url).toEqual('/v2/account/homestead/glyphs') + + fetchMock.addResponse(['volatility_harvesting', 'volatility_logging']) + let content = await endpoint.get() + expect(content).toEqual(['volatility_harvesting', 'volatility_logging']) + }) + it('test /v2/account/jadebots', async () => { endpoint = endpoint.jadebots() diff --git a/tests/endpoints/homestead.spec.js b/tests/endpoints/homestead.spec.js new file mode 100644 index 0000000..f296be8 --- /dev/null +++ b/tests/endpoints/homestead.spec.js @@ -0,0 +1,71 @@ +/* eslint-env jest */ +const {mockClient, fetchMock} = require("../mocks/client.mock") +const Module = require("../../src/endpoints/homestead") + +describe("endpoints > homestead", () => { + let endpoint + beforeEach(() => { + endpoint = new Module(mockClient) + fetchMock.reset() + }) + + it("test /v2/homestead/decorations", async () => { + endpoint = endpoint.decorations() + + expect(endpoint.isPaginated).toEqual(true) + expect(endpoint.isBulk).toEqual(true) + expect(endpoint.isLocalized).toEqual(false) + expect(endpoint.isAuthenticated).toEqual(false) + expect(endpoint.cacheTime).not.toEqual(undefined) + expect(endpoint.url).toEqual("/v2/homestead/decorations") + + fetchMock.addResponse({ + id: 35, + name: "Kodan Cottage Wall", + description: "", + categories: [19, 1], + max_count: 250, + icon: "https://render.guildwars2.com/file/EBBA1865F40A0E6EFBCACA609271191E6E9CDDCF/3375022.png", + }) + + let content = await endpoint.get(35) + expect(content.name).toEqual("Kodan Cottage Wall") + }) + + it("test /v2/homestead/glyphs", async () => { + endpoint = endpoint.glyphs() + + expect(endpoint.isPaginated).toEqual(true) + expect(endpoint.isBulk).toEqual(true) + expect(endpoint.isLocalized).toEqual(false) + expect(endpoint.isAuthenticated).toEqual(false) + expect(endpoint.cacheTime).not.toEqual(undefined) + expect(endpoint.url).toEqual("/v2/homestead/glyphs") + + fetchMock.addResponse({ + id: "volatility_harvesting", + }) + + let content = await endpoint.get("volatility_harvesting") + expect(content.id).toEqual("volatility_harvesting") + }) + +it("test /v2/homestead/decorations/categories", async () => { + endpoint = endpoint.decorations().categories() + + expect(endpoint.isPaginated).toEqual(true) + expect(endpoint.isBulk).toEqual(true) + expect(endpoint.isLocalized).toEqual(false) + expect(endpoint.isAuthenticated).toEqual(false) + expect(endpoint.cacheTime).not.toEqual(undefined) + expect(endpoint.url).toEqual("/v2/homestead/decorations/categories") + + fetchMock.addResponse({ + id: 1, + name: "Architecture", + }) + + let content = await endpoint.get(1) + expect(content.name).toEqual("Architecture") + }) +})