Skip to main content

Forums / Support / Halo API Support

Tool [PHP] - Halo API class

OP BananasSplitter

  1. 1
  2. ...
  3. ...
  4. 2
Hello everyone !
What a beautiful thing that is this API ! Even if it's still in beta, it allows every developers of the community to take part in the game history. So thanks you, 343!

I'm here now to introduce you my WIP PHP class that simplify the implementation of the API in website / web application.
Here it is: https://github.com/GRosay/PHP-HaloAPI

This class is still a WIP but I want to share it with you. As it's under WTFPL licence, you can do what you want with it.

All comments and questions are welcome as this class is certainly not perfect.
Thanks for posting!

It'd be even more helpful if it was developed as a composer package. Also, why do you append r to method names?
Vubzy wrote:
Thanks for posting!

It'd be even more helpful if it was developed as a composer package. Also, why do you append r to method names?
You mean "f" to each method names ?
Sorry, it's a professional deformation (we have development convention that I use by habit). But I can change that, if it's a problem :)

I'll envisage to possibility to make a composer package, it's a good idea.
Hello again!
I committed a new version with small but efficients changes:
  • Replacing HTTP_Request2 by curl for more compatibility with servers
  • Refactoring all functions names
  • Deleting some useless class variables
Thanks your in advance for your comments :)

(P.S.: Sorry for double post)

EDIT:
I just committed again to add all API calls possible :) now it's 99% functional !
Hello everyone !
What a beautiful thing that is this API ! Even if it's still in beta, it allows every developers of the community to take part in the game history. So thanks you, 343!

I'm here now to introduce you my WIP PHP class that simplify the implementation of the API in website / web application.
Here it is: https://github.com/GRosay/PHP-HaloAPI

This class is still a WIP but I want to share it with you. As it's under WTFPL licence, you can do what you want with it.

All comments and questions are welcome as this class is certainly not perfect.
LOVE IT, will definitely implement this on my community site.
Replacing HTTP_Request2 by curl for more compatibility with servers
Awesome! Thank you! I was having troubles getting the right module installed on my server, so this is a very welcome addition. Great work.
I'd like to second the push for a composer package. It's just so convenient.
You asked for it, you got it !
I just released a beta version for a composer package.
To install it:
composer require bananassplitter/php-haloapi

As it's a beta version, don't forget to set the minimum-stability version of your composer project to "beta".

Also, I've made a major change in the class (that is now in beta version):
The API key is no more a constant of the class, you now need to pass it as a parameter when you initialize the class.
Reasons:
  • No more needing of editing the class file
  • You can call the class multiples times with differennts API key
  • More practical for composer users
The github has been updated. I'll work this afternoon on the documentation site so you don't need to seek functions names in the class :)

Again, all comments or suggestions are welcome :)
It concerns me deeply that PHP is the most popular language on this forum...
lol... sorry DF. I worked with it professionally for two years and after working in a quality tools environment with Object Oriented PHP, your life will never be the same. But I think I may actually build a quick Java JAR since my target infrastructure is AWS Lambda and I'm working with that now professionally.

BananasSplitter, the `vendor/` folder is not intended to be checked into version control. It is a folder meant to be created with `composer install`. `composer.lock` will keep track of all your dependency versions and it will make sure that your vendor folder is recreated perfectly from scratch. So you should be fine in cleaning that out.

Have you considered any potential pros to returning certain POPOs? Just a quick thought in my head. I know the responses are actually fairly complex, but there may be some that are valuable. Also overtime batching features would be nice through a single method call (like fetching the 25 games grabbed from endpoint X and running the results through endpoint Y 25 times). Testing in various forms could be valuable in some way shape or form, perhaps not in the form of contract testing due to the complexity, but there could be something. I'm also not sure how portable the package becomes (like for forum software/hosted servers) if you incorporated Guzzle as your HTTP client. Code quality tools are always nice, particularly in formatting or maintaining PSR-4 compliance... ummm. If I think of anything else I throw it out there. And if I find some time, I'd love to contribute some time.

Great call out on the API key being injected. Best of luck with this man.
Thanks for your post RayBenefield !
I'll read it again and work on your suggestion once I have more time to be sure to understand everything (as english isn't my primary language, I may misunderstand smthg)

In fact, it's the first time I make a composer package, so I wasn't sure about what I had to keep or not, so thanks, I'll try to clean that :)

Any contribution from you or someone else would be loved !
lol... sorry DF. I worked with it professionally for two years and after working in a quality tools environment with Object Oriented PHP, your life will never be the same. But I think I may actually build a quick Java JAR since my target infrastructure is AWS Lambda and I'm working with that now professionally.
Hah. I had some freelance work with PHP a while ago, maintaining other people's code. Most traumatic coding experience of my life! To me, PHP is just one of those ugly languages that I generally try and avoid, especially with the amount of whiz-bang features that newer stuff like JS (ES2015, TypeScript), Ruby (Rails), and Python (Django, etc) have to offer.

Also, please don't tell me "POPOs" is a thing

Spoiler:
Show
Der Flatulator6 :

Well, I can understand that people don't like PHP (like other don't like NodeJS and co), but I don't think that the purpose of this forum is to debate about which programming language is the best. I'm sure there is other forum for this kind of conversation :).
Der Flatulator6 :

Well, I can understand that people don't like PHP (like other don't like NodeJS and co), but I don't think that the purpose of this forum is to debate about which programming language is the best. I'm sure there is other forum for this kind of conversation :).
You are quite right. Apologies for the derail.
lol... sorry DF. I worked with it professionally for two years and after working in a quality tools environment with Object Oriented PHP, your life will never be the same. But I think I may actually build a quick Java JAR since my target infrastructure is AWS Lambda and I'm working with that now professionally.
Hah. I had some freelance work with PHP a while ago, maintaining other people's code. Most traumatic coding experience of my life! To me, PHP is just one of those ugly languages that I generally try and avoid, especially with the amount of whiz-bang features that newer stuff like JS (ES2015, TypeScript), Ruby (Rails), and Python (Django, etc) have to offer.

Also, please don't tell me "POPOs" is a thing

Spoiler:
Show

lol... no worries. PHP can truly be the worst language to work with. But it has a powerful community behind it and when you work in true OO PHP, it is powerful and beautiful. It is very close to working with strongly typed languages. Also POPOs are the same as POJOs (Plain Old PHP/Java Objects)... essentially getter/setter bags. Not my preferred approach nowadays due to DDD, but definitely common enough practice that I suggest them first.

BananasSplitter I'll try to contribute this weekend if I find some time. My weekends are normally pretty busy. But I do want to eventually start helping out as PHP is my go to for quick projects.
I have a Pull Request open that does two things:
  1. Fixes a bug where each request was being submitted twice.
  2. Adds throttling, so that you don't have to worry about your application keeping track of this. (Keeps track of the number of requests made, and the timeframe in which they were made, and then sleeps if necessary)
Everything needed to be static, so that requests are tracked across instances. The query limit variables are defined as a set of public static fields so that they're configurable from outside the class. I'm no PHP expert, so if you have a better way to do this, have at it.

Hopefully this helps out some other people. This has all been very helpful to me.
  1. Adds throttling, so that you don't have to worry about your application keeping track of this. (Keeps track of the number of requests made, and the timeframe in which they were made, and then sleeps if necessary)
Probably a better solution than the way I did it, my implementation hijacks 429 errors, parses the "try again in X seconds", waits that many seconds and re-requests. Not the most bandwidth efficient solution, but seems to work. It's the only way I could think of doing it without knowing the rate limit of one's API key.
Quote:
Probably a better solution than the way I did it, my implementation hijacks 429 errors, parses the "try again in X seconds", waits that many seconds and re-requests. Not the most bandwidth efficient solution, but seems to work. It's the only way I could think of doing it without knowing the rate limit of one's API key.
Eh, "better" is arguable. I almost thought about doing the same type of thing but I wasn't sure that I wanted to depend upon the string format remaining constant. Instead, people have to know their own limits for their key and set them on the class manually.
Quote:
Probably a better solution than the way I did it, my implementation hijacks 429 errors, parses the "try again in X seconds", waits that many seconds and re-requests. Not the most bandwidth efficient solution, but seems to work. It's the only way I could think of doing it without knowing the rate limit of one's API key.
Eh, "better" is arguable. I almost thought about doing the same type of thing but I wasn't sure that I wanted to depend upon the string format remaining constant. Instead, people have to know their own limits for their key and set them on the class manually.
I'll probably end up adding a rate-limit option to my impl, and default to the way I'm currently doing it.
https://github.com/DerFlatulator/haloapi/blob/experimental/ts/index.ts#L103.

It's a bit hacky, but it grabs the first (should be only) number in the JSON message string, or defaults to 1 second otherwise.
Thanks for contributing Null Parameter.
I will check your push request as soon as I'm back home. :)
  1. 1
  2. ...
  3. ...
  4. 2