1.0.7 • Published 7 years ago

blizzard_forum v1.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Try Now

Run a sample online to see how this API works.

Usage

Simply download & save it to your package.json with:

$ npm install --save blizzard_forum

Load it with:

// EcmaScript 6 / EcmaScript 2015
import blizzardForum from "blizzard_forum"
let blizForum = new blizzardForum()

// Lower versions
let blizzardForum = require("blizzard_forum")
let blizForum = new blizzardForum.default()

That's it. And you may want to set the host and region, which are set to https://us.battle.net and en by default:

// https://tw.battle.net/forums/zh

blizForum.set("server.host", "https://tw.battle.net")
blizForum.set("server.region", "zh")

Contribute & Development

See CONTRIBUTING.md.

Features

Functionalities of this API.

query()

Returns an object of functions.

Initalizes an query expression.

blizForum.query()

topic(forum_name, topic_id(, onError))

Returns an array of functions.

This loads a topic with URL https://us.battle.net/forums/en/forum_name/topic/topic_id.

Let's say we're loading this topic: https://us.battle.net/forums/en/bnet/topic/13815891462, thus we should run:

.query().topic("bnet", 13815891462)

onError is a function which handles the error during the loading process. It takes 1 argument: error, which contains the error information.

data()

Returns a Promise object.

This loads the topic's information. Attributes available: id, lastPosition, forum, isSticky, isFeatured, isLocked, isHidden, isFrozen, isSpam and pollId.

.query().topic(...).data().then((data) => {
    console.log(data.isLocked);
});

posts((fields)(, filters))

Returns a Promise object. Loads all posts of a topic.

fields is an array that tells the API what information you want. For example, if you pass ["isBlizzardPost"], the result you get will be something like [{isBlizzardPost: true}, {isBlizzardPost: false}, ...].

filters is a function which tells the API that if you wish a post to be in your result. It takes 1 argument, an object with everything about the post: id, position, info, attributes, create_time, lastEditTime, isBlizzardPost, url and content.

Both arguments are optional.

The example below is to print all URLs (and it will only get the URLs) of the Blizzard-staff posted contents under a topic.

.query().topic(...).posts(['url'], (post) => { return post.isBlizzardPost }).then((posts) => {
    posts.forEach(post => { console.log(post.url) })
});
1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago