Jump to content

API Discussion


Alex
 Share

Recommended Posts

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'

 

For sure, it's one of the reasons why PHP is fairly disliked. I'll use c# whenever I can and PHP only when I have to. I'm sure you know, but fortunately in PHP7 they have scalar type hinting so at least it's a step in the right direction. I've updated my local environments to have PHP7 and I've actually seen a pretty decent increase in performance. So at least PHP is getting better. I won't dare update on a live site just yet though, knowing PHP there's probably a pretty major exploit hiding in there somewhere.

 

And with your JS example, this has happened to me more times than it should have :3

[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

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 :)

 

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'
 

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

 

 

Yeah, I wasn't sure where to post the suggestion at.

☾☆

Priest of Dio

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

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

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

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

Link to comment
Share on other sites

  • 1 month later...
  • 7 months later...

What about:

https://politicsandwar.com/api/nations/allianceid=623

This would allow one to list nations filtered by the alliance. Currently I get a list of 5293 nations.. painfull to load. But only need 43 of them.

I can filter them out myself of course but it slows down the loading process even more. 

Edited by niquedegraaff
Link to comment
Share on other sites

I'm talking about the API here ;) Not the frontend of the website.

 

Also, Alex, since you publish public data, could you please enable CORS header from server-side? ( http://enable-cors.org )

 

 

 

Cross-Origin Resource Sharing (CORS) is a specification that enables truly open access across domain-boundaries. If you serve public content, please consider using CORS to open it up for universal JavaScript/browser access.

 

Thank you

 

 

Edited by niquedegraaff
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 1 month later...

I know part of the concern with all the API pulls is server overload, however what is some events were RSS instead of API? I cannot pretend to say whether or not RSS has less of a demand than API, but I think it would?

Examples of RSS feeds:

  • New Wars
  • New Market Offers
  • New Alliance Applicant

In my train of thought, this could help
A. Reduce the workload of API requests coming into the server
B. Reduce the amount of hostile API attempts
C. Eliminate API requests from those who want to just get notifications to those who want to build information/graphs/etc.

Edited by Restius
Link to comment
Share on other sites

I know part of the concern with all the API pulls is server overload, however what is some events were RSS instead of API? I cannot pretend to say whether or not RSS has less of a demand than API, but I think it would?

Personally as a programmer, I'd rather JSON over XML, it's alot easier to work with and it compresses better. I also don't see what the difference would be, between a pull for an RSS feed and a pull for a JSON API call.

 

Probably what really needs to happen is that certain bits of information are pre-calculated and "snapshotted", anywhere from once an hour to once a day, depending on the information and stored in a second database (along with the time they were snapshotted and any relevant values that make up the calculated values). It could even be dynamic in some cases, in that if someone loads a nation/alliance page, it does a quick check if the page has been snapshotted recently and if it hasn't been, takes a snapshot from the data that's been calculated already, to load the page. Might mean some pages take slightly longer to load, but people aren't likely to notice.

 

The API can then run mostly off the second "snapshot" database and hopefully rarely dipping into the "real time" database. In addition, have all API requests linked to a user's nation (to track who is using the API). Alex can then track usage and if someone is then abusing the API (like if someone is accounting for 10-20% of all API calls), they can be messaged to explain and potentially either limited in some capacity or completely cut off.

sig_cybernations.PNG.8d49a01423f488a0f1b846927f5acc7e.PNG

Link to comment
Share on other sites

Personally as a programmer, I'd rather JSON over XML, it's alot easier to work with and it compresses better. I also don't see what the difference would be, between a pull for an RSS feed and a pull for a JSON API call.

 

As a non-programmer who stumbles around python tutorials to get his shit done, I prefer JSON over XML as well.

☾☆


High Priest of Dio

Link to comment
Share on other sites

  • 3 weeks later...
  • Administrators

Did a couple of API things:

 

Added an API for singular wars. URL is here: https://politicsandwar.com/api/war/WARIDHERE

You can find the ID for a war on most war-related page URLs, easiest is to look at a timeline or from the Wars API.

 

Added an API for alliance applicants. URL is here: https://politicsandwar.com/api/applicants/ALLIANCEIDHERE

This will return false if the alliance doesn't exist, or there are no applicants. Otherwise it will return true with a list of nations.

 

Added city count to the nations API.

 

Fixed some variable misinterpretation to remove quotes from integer values in a few places. Should make things (very, very slightly) faster to load

  • Upvote 3

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

Did a couple of API things:

 

Added an API for singular wars. URL is here: https://politicsandwar.com/api/war/WARIDHERE

You can find the ID for a war on most war-related page URLs, easiest is to look at a timeline or from the Wars API.

 

Added an API for alliance applicants. URL is here: https://politicsandwar.com/applicants/ALLIANCEIDHERE

This will return false if the alliance doesn't exist, or there are no applicants. Otherwise it will return true with a list of nations.

 

Added city count to the nations API.

 

Fixed some variable misinterpretation to remove quotes from integer values in a few places. Should make things (very, very slightly) faster to load

 

I think your applicant API is wrong. Seems it's https://politicsandwar.com/api/applicants/AID

 

oh god I'm in love with you. Is there any way to get damages on the war API?

Edited by Yosodog

[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

I think your applicant API is wrong. Seems it's https://politicsandwar.com/api/applicants/AID

 

oh god I'm in love with you. Is there any way to get damages on the war API?

 

I might add damage totals and things, we'll see. But yes, you are correct, I forget the /api/ directory in my URL. Glad you figured it out :P

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

Thanks for working on the API again.

I think you can reduce server load on API side by adding the ability to filter the nations list on alliance id and score. 
At the moment we get the full list of nations (a whopping 5018 !!), but most times we only need a few :).

Edited by niquedegraaff
Link to comment
Share on other sites

  • 1 year later...

Thanks for all the APIs. They seem mostly complete, but I need a way to access the treaty web. Treaties could be included in the Alliance and Alliances APIs, or in a separate API. While a separate API would be slightly more convenient to me, it might make more sense to do it the other way. Either way, could you please include this information? It would be extremely helpful.

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...
  • 3 months later...
  • 3 weeks later...
On 3/5/2019 at 8:15 PM, Leopold von Habsburg said:

Just going to reiterate this request for the new year ;)

Going to re-reiterate this request for all the poor econ boys that had to sift through 3000 pages of transactions to send back safekeeping after the war. ❤️ 

btw great work on the war api, its smackaliciously sexy

Edited by Radoje
  • Like 2
  • Upvote 1
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.