npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clash-of-clans-api

v0.6.4

Published

Clash of Clans API module

Downloads

87

Readme

Introduction

Provides an easy way to get started with the Clash of Clans API

Installation

npm install --save clash-of-clans-api

Usage

All fetches return a promise using request-promise

Instantiation

In order to get started with Clash of Clans API, you need to create an account at developer.clashofclans.com and create a key. You will need the IP of the host using to connect to the services.

Once you get your token, you have two choices.

  • Set the COC_API_TOKEN env variable
  • Pass in a token option when creating the ClashApi object

Example:

import clashApi from 'clash-of-clans-api';
let client = clashApi({
  token: yourApiToken // Optional, can also use COC_API_TOKEN env variable
});

In addition, if you need to pass in any additional options to request (for example to set a proxy) then you can use the request option to do so:

import clashApi from 'clash-of-clans-api';
let client = clashApi({
  request: {
    proxy: process.env.MY_PROXY,
  },
});

See request options for the full list of supported request options

Clan Search

There is a DSL for performing clan searches. At least one filtering criteria must be defined and if name is used as part of search, it is required to be at least three characters long.

See https://developer.clashofclans.com/api-docs/index.html#!/clans/searchClans

Example:

client
  .clans()
  .withWarFrequency('always')
  .withMinMembers(25)
  .fetch()
  .then(response => console.log(response))
  .catch(err => console.log(err))

All query parameters are supported, simply prepend with and capitalize the first letter of the query param. Complete the request with a call to fetch().

Clan by Tag

Request clan details by clan tag. Be sure to include the hashtag #.

Example:

client
  .clanByTag('#UPC2UQ')
  .then(response => console.log(response))
  .catch(err => console.log(err));

Clan Members by Tag

Request clan member details by clan tag. Be sure to include the hashtag #.

Example:

client
  .clanMembersByTag('#UPC2UQ')
  .then(response => console.log(response))
  .catch(err => console.log(err));

Clan Warlog by Tag

Request clan warlog by clan tag. Be sure to include the hashtag #.

Example:

client
  .clanWarlogByTag('#UPC2UQ')
  .then(response => console.log(response))
  .catch(err => console.log(err));

Current War by Tag

Request current war information by clan tag. Be sure to include the hashtag #.

Example:

client
  .clanCurrentWarByTag(`#UPC2UQ`)
  .then(response => console.log(response))
  .catch(err => console.log(err));

Clan War Leagues support

Request the current clan war leagues the clan is participating in.

Example:

client
  .clanLeague(`#UPC2UQ`)
  .then(response => console.log(response))
  .catch(err => console.log(err));
  
// Response contains response.rounds[].warTags[]. Each of the warTags 
// can be used to retrieve further information about the league war.
client
  .clanLeagueWars(response.rounds[0].warTags[0])
  .then(response => console.log(response))
  .catch(err => console.log(err));

Location

Location has a DSL for requesting location details

Examples:

// Request all location details
client
  .locations()
  .fetch()
  .then(response => console.log(response))
  .catch(err => console.log(err));

// Request details for a single location
client
  .locations()
  .withId(locationId)
  .fetch()
  .then(response => console.log(response))
  .catch(err => console.log(err));

// Request clan details for a single location
client
  .locations()
  .withId(locationId)
  .byClan()
  .fetch()
  .then(response => console.log(response))
  .catch(err => console.log(err));

// Request player details for a single location
client
  .locations()
  .withId(locationId)
  .byPlayer()
  .fetch()
  .then(response => console.log(response))
  .catch(err => console.log(err));

Tutorial for complete beginners

https://medium.com/@alexionutale/how-to-use-clash-of-clans-api-cd4fe7406576?source=friends_link&sk=c12a0c2a736658681878f20cc98af08f