Jump to content

API Discussion


Alex
 Share

Recommended Posts

Could we have an alliances API in the same way that we have a nations API?  1 call for all alliance data would be better than having to keep the list up to date and pull them all separately.

 

Something other than https://politicsandwar.com/api/alliance/id=621 ?

 

I would personally like to be able to get a list of alliances :)

 

Anyway, I just want to say thanks to Sheepy for having this API part of the game. I've had much fun and learnt a lot of programming working with the API.

 

p.s. http://politicsandwar.com/api/nation/id=30063another escape character issue in the json making it invalid.

Link to comment
Share on other sites

Or, and I don't want to sound pretentious or demeaning, have the computer do it.

 

I don't know the database setup for the game but I'd assume it would go like this:

$conn = connect();

$query = $conn->prepare("SELECT * FROM nations WHERE id=?");
$query->bind_param("i", $_GET['id']);
$query->execute();
$result = $query->get_result();

echo "<pre>";
echo json_encode($result->fetch_assoc(), JSON_PRETTY_PRINT);
echo "</pre>";

I don't know if it is already done this way, but it doesn't look like it (at least in the nation/city/alliance).

 

This would also make it easier to have APIs for other things *nudge nudge* war *nudge*

  • Upvote 1

[22:37:51] <&Yosodog> Problem is, everyone is too busy deciding which top gun character they are that no decision has been made

 

BK in a nutshell

Link to comment
Share on other sites

A list of all alliances would be nice, as would listing all members on the individual alliance page.

 

Also an about page that lists all of the API pages (and probably a description of what the API is/does for people who wander there and don't know what they've found).

RollSheepy.png

Link to comment
Share on other sites

The City API got changed, they removed the "data" and "stats" tags, is that going to happen to nation and alliance as well? I'll need to change scripts if it does.

☾☆

Priest of Dio

º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

¨°º¤ø„¸ GOD EMPEROR DIO BRANDO¨°º¤ø„¸

¨°º¤ø„¸ DIO BRANDO GOD EMPEROR¨°º¤ø„¸

¨°º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

Link to comment
Share on other sites

The City API got changed, they removed the "data" and "stats" tags, is that going to happen to nation and alliance as well? I'll need to change scripts if it does.

 

Probably https://politicsandwar.com/forums/index.php?/topic/10444-city-json-api-a-bit-sad-data-there-twice-and-html-code/?p=188729

[22:37:51] <&Yosodog> Problem is, everyone is too busy deciding which top gun character they are that no decision has been made

 

BK in a nutshell

Link to comment
Share on other sites

  • Administrators

Or, and I don't want to sound pretentious or demeaning, have the computer do it.

 

I don't know the database setup for the game but I'd assume it would go like this:

$conn = connect();

$query = $conn->prepare("SELECT * FROM nations WHERE id=?");
$query->bind_param("i", $_GET['id']);
$query->execute();
$result = $query->get_result();

echo "<pre>";
echo json_encode($result->fetch_assoc(), JSON_PRETTY_PRINT);
echo "</pre>";

I don't know if it is already done this way, but it doesn't look like it (at least in the nation/city/alliance).

 

This would also make it easier to have APIs for other things *nudge nudge* war *nudge*

 

Yeah, I just learned about this recently to be honest with you. And I'm working on updating all the pages to match this format, and it does make it much, much easier.

  • Upvote 1

Is there a bug? Report It | Not understanding game mechanics? Ask About It | Got a good idea? Suggest It

Forums Rules | Game Link

Link to comment
Share on other sites

  • Administrators

Added a couple of new pages:

 

https://politicsandwar.com/api/alliances/

 

Similar to the nations page

 

https://politicsandwar.com/api/tradeprice/resource=XXX

 

Where XXX is your resource name. Defaults to steel if none provided.

  • Upvote 2

Is there a bug? Report It | Not understanding game mechanics? Ask About It | Got a good idea? Suggest It

Forums Rules | Game Link

Link to comment
Share on other sites

Added a couple of new pages:

 

https://politicsandwar.com/api/alliances/

 

Similar to the nations page

 

https://politicsandwar.com/api/tradeprices/resource=XXX

 

Where XXX is your resource name. Defaults to steel if none provided.

 

Second link should be 

https://politicsandwar.com/api/tradeprice/resource=XXX

 

 

duskhornexceptional.png.d9e24adf7f0945530780eee694428f27.png

 

He's right, I'm such a stinker. Play my exceptional game!

Link to comment
Share on other sites

  • Administrators

I don't know what you're talking about...  :rolleyes:

Is there a bug? Report It | Not understanding game mechanics? Ask About It | Got a good idea? Suggest It

Forums Rules | Game Link

Link to comment
Share on other sites

Sheepy, could I have some clarification as to what you mean by highest/lowest buy? It seems to me that it's running off 'totalvalue' as opposed to 'price', with the latter actually being more useful (as it would then give you a min/max to go with the average).

 

{
    "resource": "steel",
    "avgprice": "2868",
    "marketindex": "18,323",
    "highestbuy": {
        "date": "2016-01-11 16:23:16",
        "nationid": "21386",
        "amount": "4910",
        "price": "2694",
        "totalvalue": 13227540
    },
    "lowestbuy": {
        "date": "2016-01-11 18:36:54",
        "nationid": "28939",
        "amount": "34",
        "price": "2750",
        "totalvalue": 93500
    }
}
Also, with all APIs, is the API data generated at that point in time, or is it cached and only updated once an hour or something like that?

sig_cybernations.PNG.8d49a01423f488a0f1b846927f5acc7e.PNG

Link to comment
Share on other sites

Could we also have the sell high and low?

☾☆

Priest of Dio

º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

¨°º¤ø„¸ GOD EMPEROR DIO BRANDO¨°º¤ø„¸

¨°º¤ø„¸ DIO BRANDO GOD EMPEROR¨°º¤ø„¸

¨°º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

Link to comment
Share on other sites

Trade Prices API not currently working for me, says page not found.

 

It should be 'tradeprice' https://politicsandwar.com/api/tradeprice/resource=steelSheepy must've linked the wrong link :P

[22:37:51] <&Yosodog> Problem is, everyone is too busy deciding which top gun character they are that no decision has been made

 

BK in a nutshell

Link to comment
Share on other sites

Everything on the trade price page except for the resource name and highest/lowest buy date are numbers. So why are the totalvalues for the highest/lowest buy the only things that are served as integers?

date wouldn't be integer, it's a string due to formatting

 

Also when there's no data the fields that are strings show "null" instead of integers, while totalvalue displays 0 as integer.

duskhornexceptional.png.d9e24adf7f0945530780eee694428f27.png

 

He's right, I'm such a stinker. Play my exceptional game!

Link to comment
Share on other sites

Can we please get the number of defensive slots open added to the nation feed?

☾☆

Priest of Dio

º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

¨°º¤ø„¸ GOD EMPEROR DIO BRANDO¨°º¤ø„¸

¨°º¤ø„¸ DIO BRANDO GOD EMPEROR¨°º¤ø„¸

¨°º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

Link to comment
Share on other sites

  • Administrators

Sheepy, could I have some clarification as to what you mean by highest/lowest buy? It seems to me that it's running off 'totalvalue' as opposed to 'price', with the latter actually being more useful (as it would then give you a min/max to go with the average).

 

{
    "resource": "steel",
    "avgprice": "2868",
    "marketindex": "18,323",
    "highestbuy": {
        "date": "2016-01-11 16:23:16",
        "nationid": "21386",
        "amount": "4910",
        "price": "2694",
        "totalvalue": 13227540
    },
    "lowestbuy": {
        "date": "2016-01-11 18:36:54",
        "nationid": "28939",
        "amount": "34",
        "price": "2750",
        "totalvalue": 93500
    }
}
Also, with all APIs, is the API data generated at that point in time, or is it cached and only updated once an hour or something like that?

 

 

It's generated point in time.

 

Could we also have the sell high and low?

 

It actually shows the lowest sell and the highest buy. I should change the name of the latter.

 

Everything on the trade price page except for the resource name and highest/lowest buy date are numbers. So why are the totalvalues for the highest/lowest buy the only things that are served as integers?

 

I don't know, it's using json_encode, I presume PHP doesn't want them to be integers. Or something.

Is there a bug? Report It | Not understanding game mechanics? Ask About It | Got a good idea? Suggest It

Forums Rules | Game Link

Link to comment
Share on other sites

I don't know, it's using json_encode, I presume PHP doesn't want them to be integers. Or something.

 

Is it stored as an integer or a string in the database? Could also just be PHP being horrible with managing variable types smh

[22:37:51] <&Yosodog> Problem is, everyone is too busy deciding which top gun character they are that no decision has been made

 

BK in a nutshell

Link to comment
Share on other sites

Can we please get the number of defensive slots open added to the nation feed?

Also, vacation mode added to nation api?

☾☆

Priest of Dio

º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

¨°º¤ø„¸ GOD EMPEROR DIO BRANDO¨°º¤ø„¸

¨°º¤ø„¸ DIO BRANDO GOD EMPEROR¨°º¤ø„¸

¨°º¤ø„¤¤º°¨ ø„¸¸„¨ ø„¸¸„ø¤º°¨¨°º¤ø„¸¸„ø¤º°¨¨°º¤ø„¸

Link to comment
Share on other sites

It actually shows the lowest sell and the highest buy. I should change the name of the latter.

If you do change the name, can you please leave the old one in there for a couple of days at least, to give people time to alter scripts? Thanks :)

 

Is it stored as an integer or a string in the database? Could also just be PHP being horrible with managing variable types smh

PHP is horrible with variable types. It's perfectly happy keeping an integer as a string, right up until you use it in a calculation. At which point, it will think of it as an integer and the result will be an integer.

//PHP
a='5'; //string
b=5; //integer
c=a+b; //c is now 10
At least it's slightly better than Javascript. JS uses + to concatenate strings, which causes all sorts of fun.

//Javascript
var a='5'; //string
var b=5; //integer
var c=a+b; //c is now '55'
 

Also, vacation mode added to nation api?

If I get a chance later this week, I'll do a post in suggestions for nations, like I did with alliances.
  • Upvote 1

sig_cybernations.PNG.8d49a01423f488a0f1b846927f5acc7e.PNG

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and the Guidelines of the game and community.