Skip to content

@lands.io/mod-sdk / Clans

Class: Clans

Static utility class for fetching clan information from the public API

Example

// Batch fetch multiple clans
const clans = await Clans.getBatch(['clan1', 'clan2', 'clan3']);

// Get single clan with full details
const clan = await Clans.getById('clan-id');

// Search clans
const results = await Clans.search('dragon', 10);

Table of contents

Constructors

Methods

Constructors

constructor

new Clans(): Clans

Returns

Clans

Methods

getBatch

getBatch(clanIds): Promise\<ClanInfo[]>

Batch fetch multiple clans by their IDs Returns basic clan information (no members/applications)

Parameters

Name Type Description
clanIds string[] Array of clan IDs to fetch

Returns

Promise\<ClanInfo[]>

Array of clan information


getById

getById(clanId): Promise\<ClanDetails>

Fetch a single clan with full details including members and applications

Parameters

Name Type Description
clanId string Clan ID to fetch

Returns

Promise\<ClanDetails>

Detailed clan information


search(query, limit?, offset?): Promise\<ClanInfo[]>

Search for clans by name or tag

Parameters

Name Type Default value Description
query string undefined Search query string
limit number 20 Maximum number of results (default: 20)
offset number 0 Number of results to skip (default: 0)

Returns

Promise\<ClanInfo[]>

Array of matching clans


Source Code

View full implementation
/**
 * Static utility class for fetching clan information from the public API
 *
 * @example
 * ```typescript
 * // Batch fetch multiple clans
 * const clans = await Clans.getBatch(['clan1', 'clan2', 'clan3']);
 *
 * // Get single clan with full details
 * const clan = await Clans.getById('clan-id');
 *
 * // Search clans
 * const results = await Clans.search('dragon', 10);
 * ```
 */
export class Clans {
  /**
   * Batch fetch multiple clans by their IDs
   * Returns basic clan information (no members/applications)
   *
   * @param clanIds - Array of clan IDs to fetch
   * @returns Array of clan information
   */
  static async getBatch(clanIds: string[]): Promise<ClanInfo[]> {
    const url = `${getPublicApiUrl()}/api/clans/batch`;

    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({ clanIds }),
    });

    if (!response.ok) {
      throw new Error(`Failed to fetch clans: ${response.statusText}`);
    }

    return response.json();
  }

  /**
   * Fetch a single clan with full details including members and applications
   *
   * @param clanId - Clan ID to fetch
   * @returns Detailed clan information
   */
  static async getById(clanId: string): Promise<ClanDetails> {
    const url = `${getPublicApiUrl()}/api/clans/${encodeURIComponent(clanId)}`;

    const response = await fetch(url);

    if (!response.ok) {
      throw new Error(`Failed to fetch clan: ${response.statusText}`);
    }

    return response.json();
  }

  /**
   * Search for clans by name or tag
   *
   * @param query - Search query string
   * @param limit - Maximum number of results (default: 20)
   * @param offset - Number of results to skip (default: 0)
   * @returns Array of matching clans
   */
  static async search(
    query: string,
    limit = 20,
    offset = 0
  ): Promise<ClanInfo[]> {
    const params = new URLSearchParams({
      query,
      limit: limit.toString(),
      offset: offset.toString(),
    });

    const url = `${getPublicApiUrl()}/api/clans/search?${params}`;

    const response = await fetch(url);

    if (!response.ok) {
      throw new Error(`Failed to search clans: ${response.statusText}`);
    }

    return response.json();
  }
}