0.7.8 • Published 2 years ago

@edixon/css-battle-api v0.7.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

CSS Battle API

npm.io npm.io npm.io

npm.io code style: prettier

First API client to get public information from the CSS Battle page. Created with NodeJS and Typescript, all types are exposed for use.   + 💗

📃 NOTE: For now can only get the profile information of users, but later methods will be created to obtain: "leader board", "battle targets", etc.

📃 NOTE: To be able to use api from a frontend app, you must use a proxy, the library comes with one by default, it is on a free server so don't expect quick results.

Example: shield to Github

Installation

  • NPM
npm install @edixon/css-battle-api
  • CDN
<!-- Bundle optimized to production -->
<script src="https://cdn.jsdelivr.net/npm/@edixon/css-battle-api@0.7.3/dist/bundle/CSSBattleAPI.min.js"></script>

Usage

We require the library and we get the CSSBattleAPI class, then we create an instance to use the query methods.

const { CSSBattleAPI } = require('@edixon/css-battle-api')

const CBA = new CSSBattleAPI()

CBA.profile('USERNAME').then(profile => {
  console.log(profile.ranking.totalScore) // Total score obtained in CSS Battle
})

You can also pass a configuration object to the class to set a proxy and be able to use of the client side api. Can enter a URL or true to use the default proxy.

const CBA = new CSSBattleAPI({
  proxy: /* boolean | string */
})

Using typescript, async/await and try/catch.

When an error occurs a string error is returned, is a friendly message that describe the cause of the error in the query.

import { CSSBattleAPI, TRanking } from '@edixon/css-battle-api'

async function getRanking(username: string): Promise<TRanking> {
  try {
    const { ranking } = await new CSSBattleAPI().profile(username)

    return ranking
  } catch (error) {
    throw new Error(error)
  }
}

Types

type TProfile = {
  avatar: string
  name: string
  username: string
  job: string | null
  country: string | null
  networks: TNetworks
  ranking: TRanking
}

type TNetworks = {
  website: string | null
  github: string | null
  twitter: string | null
  codepen: string | null
} | null

type TRanking = {
  rank: number
  totalPlayers: number
  totalScore: number
  battlesPlayed: number
}

Contributing

See CONTRIBUTING.md

License

MIT © Edixon Piña

0.7.8

2 years ago

0.7.7

2 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago