1.0.2 • Published 6 years ago

travian-kingdoms-api v1.0.2

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

Travian Kingdoms API npm version

JS Api for communication with travian kingdoms public (!!) endpoints.

What is public endpoint?

Endpoints for external tools published by travian kingdoms.

Functions

register

You need to call this first, to get an privateApiKey / publicSiteKey. With this privateApiKey you can make further calls to our api's.

Options

NameTypeRequiredMeaning
urlStringyesServer url like https://cz4.travian.com
emailString (max 255)yesNeeds to be a valid email
siteNameString (max 255)yesName of the tool
siteUrlString (max 255)yesUrl of the tool - needs to be a valid url
publicboolyesIf you set it to true, that means we maybe include your tool in a tool list

Example

const tka = require('travian-kingdoms-api')

tka.register(
	{
		url: 'https://cz4.kingdoms.com',
		email: 'some@email.com',
		siteName: 'someSiteName',
		siteUrl: 'http://www.someSite.url',
		isPublic: 'true'
	},
	(err, response, body) => {
		/* handle err/response status if you want */
		console.log(body)
	}
)

Response

{
    time: 1524656411039,
    response: {
        privateApiKey: 'xxx',
        publicSiteKey: 'yyy'
    }
}

updateSiteData

You can call this if you want to update some data of your tool.

Options

NameTypeRequiredMeaning
urlStringyesServer url like https://cz4.travian.com
privateApiKeyStringyesYour private Api Key ( you retrieved via register function)
emailString (max 255)yesNeeds to be a valid email
siteNameString (max 255)yesName of the tool
siteUrlString (max 255)yesUrl of the tool - needs to be a valid url
publicboolyesIf you set it to true, that means we maybe include your tool in a tool list

Example

const tka = require('travian-kingdoms-api')

tka.updateSiteData(
	{
		privateApiKey: 'xxx',
		url: 'https://cz4.kingdoms.com',
		email: 'some@email.com',
		siteName: 'someSiteName',
		siteUrl: 'http://www.someSite.url',
		isPublic: 'true'
	},
	(err, response, body) => {
		/* handle err/response status if you want */
		console.log(body)
	}
)

Response

{
    time: 1524656860998,
    response: {
        data: true
    }
}

getMapData

To get all public map data (old map.sql :-) ) from a specific date).

Options

NameTypeRequiredMeaning
urlStringyesServer url like https://cz4.travian.com
privateApiKeyStringyesYour private Api Key ( you retrieved via register function)
dateStringnoNeeds to be a date in format: d.m.Y (e.g. 27.08.2014). If no date is present, the today will be used.

Example

const tka = require('travian-kingdoms-api')

tka.getMapData(
	{
		privateApiKey: 'xxx',
		url: 'https://cz4.kingdoms.com',
		date: '20.02.2018'
	},
	(err, response, body) => {
		/* handle err/response status if you want */
		console.log(body)
	}
)

Or without date:

const tka = require('travian-kingdoms-api')

tka.getMapData(
	{
		privateApiKey: 'xxx',
		url: 'https://cz4.kingdoms.com'
	},
	(err, response, body) => {
		/* handle err/response status if you want */
		console.log(body)
	}
)

Response

{
    time: 1524659209779,
    response: {
        gameworld: {
            name: 'cz4',
            startTime: 1518008400,
            speed: 1,
            speedTroops: 1,
            lastUpdateTime: '1519167901',
            date: 1519084800,
            version: '1.0' },
         players: [ ... ], //array of players
         kingdoms:[ ... ], //array of kingdoms
         map: {
            radius: '60',
            cells: [ ... ], //array of cells
            landscapes: [ ... ] //array of landscapes
        }
    }
}