kz / lifx-php

lifx-php is a PHP package for the LIFX HTTP API
MIT License
15 stars 3 forks source link

Query Strings not sending? #3

Closed kubacode closed 9 years ago

kubacode commented 9 years ago

@kz are the Query Strings for setLights, setColor, breatheLights & pulseLights methods sending the query string correctly for you? I've had to refactor the sendRequest method to accept an additional parameter with the query string, rather than the third parameter in a new Request.

I may have a different version of Guzzle installed compared to the version used to develop, so this could be the case of the issue - I'm currently running 6.0.1.

I'll pop through a PR with a fix if they aren't set correctly!

kz commented 9 years ago

Hi @kubacode, thanks for opening the issue. I have not had the time to actually test the code yet and I'm busy with another project right now which I need to finish before working on this.

The issue may come from the fourth parameter in new Request:

$request = new Request('PUT', 'lights/' . $selector . '/power', [], [
    'state' => $state,
    'duration' => $duration,
]);

As you can see, an associative array is being uploaded. However, Guzzle's documentation shows:

$response = $client->post('http://httpbin.org/post', [
    'form_params' => [
        'field_name' => 'abc',
        'other_field' => '123',
        'nested_field' => [
            'nested' => 'hello'
        ]
    ]
]);

Therefore, it might fix it should you pass the associative array as a value for the key 'form_params' as shown above. This might work, although I am unsure, as this comes for the documentation for the Client class instead of the Request class.

I won't be able to work on this anytime soon since I really want to make progress with Panel for LIFX (mainly to learn AngularJS by the end of this week). I appreciate the time you have invested in this package and my lack of maintenance of this package will be over soon!

kubacode commented 9 years ago

I've got a fix for this already - I'll pop through a PR after work this evening.

No problem at all with lack of maintenance - good luck with Panel for LIFX!

kubacode commented 9 years ago

PR submitted!

kz commented 9 years ago

Thank you!