unsplash / unsplash-php

👻 Official PHP wrapper for the Unsplash API
MIT License
409 stars 71 forks source link

Add method to view remaining rate limit #97

Closed KevinBatdorf closed 5 years ago

KevinBatdorf commented 5 years ago

Without this exposed you could do something like this:

$response = Crew\Unsplash\Photo::all();

$headers = (new ReflectionObject($response))->getProperty('headers');
$headers->setAccessible(true);
$headers = $headers->getValue($response);

if (intval($headers['X-Ratelimit-Remaining'][0]) < 500) send_message_to_slack();
lukechesser commented 5 years ago

Hey @KevinBatdorf thanks for opening this up. Is it possible to add a test for this? I think the fixtures have the header there, so you could test that it returns the correct value for a fixture

KevinBatdorf commented 5 years ago

Hi @lukechesser

I added a unit test for the ArrayObject and a test on the Endpoint class to just ensure the header exists on the mock call. Any other tests you would like?

lukechesser commented 5 years ago

@KevinBatdorf this looks good to me! Thanks for adding this in :)