Closed WilliamDenniss closed 13 years ago
I posted the following justification for this pull request to the mailing list, copied here:
Currently when using the PHP client library to communicate with Disqus, I couldn't find any way for making API calls where multiple arguments are passed to fields that are designated by the API as allows multiple. For example, threads/list
allows you to pass multiple thread
arguments (see http://disqus.com/api/docs/threads/list/ ) Using this feature allows you to make 1 API call to query 100 threads, instead of 100 API calls for the same – the benefits are obvious, and this is good API design on the part of Disqus!
So this allows multiple is supported in the Disqus API, but you can't actually supply multiple arguments in the PHP client library, as it uses a dictionary (as far as I could see, please correct me if I missed something!). My change allows you to supply an array instead of just a single value, in order to take advantage of the 'allows multiple' feature of Disqus.
Example: How to query 1 thread (existing).
$threads = $api->threads->list(array(
'thread'=> '1234',
));
Example: How to query multiple threads (with my patch applied).
$threads = $api->threads->list(array(
'thread'=> array('1234', '2345'),
));
If you look at the resulting URL, the patch simply unfolds the array like so: "&thread=1234&thread=2345", and this is the format that the API expects.
So unless I missed the supported way of doing this in the PHP client library, I humbly propose that my change is merged into the master.
I've been using this code for a few months now to do bulk thread lookups, and it's been working well.
With this change, arrays are treated as multiple values for the same argument, to be used with Disqus method arguments that allow for multiple values. Such method arguments are marked in the API docs with 'allows multiple'.
I could not find an existing way to pass multiple values for the same argument using the PHP API, so I made this change. In any case, the change is fairly intuitive I think.
E.g. "thread" : array("1234", "2345")
is unrolled as "&thread=1234&thread=2345"
I had previously submitted this pull request – it is redone using the same whitespace options that Disqus uses.