Adding support for 'allows multiple' arguments in the PHP client library (patch included!)

52 views
Skip to first unread message

William Denniss

unread,
May 24, 2011, 4:18:51 AM5/24/11
to Disqus Developers
Hi All,

I've created a pull request in Github that I wanted to bring to your
attention.

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.

Pull request is here: https://github.com/disqus/disqus-php/pull/7
Diff is here: https://github.com/disqus/disqus-php/pull/7/files

I've been using this code for a few months now to do bulk thread
lookups, and it's been working well.

Please tell me what you think!

Kind Regards,
Will
Reply all
Reply to author
Forward
0 new messages