Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implemented optional url params #8

Merged
merged 1 commit into from

2 participants

@EvanK

There were a couple optional url parameters detailed in the REST API docs that were not currently implemented in this library:

  • per_page for IronMQ#getQueues
  • timeout for IronMQ#getMessages and IronMQ#getMessage

I also added some casting of numeric params to int, not sure if it would make more sense to instead check whether they are ints and throw an exception if they're not?

@EvanK EvanK Implemented optional url params per REST API documentation
* per_page for IronMQ#getQueues
* timeout for IronMQ#getMessages and IronMQ#getMessage
ff44a1b
@thousandsofthem
Collaborator

Thanks for your help!

@thousandsofthem thousandsofthem merged commit 3444918 into iron-io:master
@EvanK

Happy to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. @EvanK

    Implemented optional url params per REST API documentation

    EvanK authored
    * per_page for IronMQ#getQueues
    * timeout for IronMQ#getMessages and IronMQ#getMessage
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 8 deletions.
  1. +27 −8 IronMQ.class.php
View
35 IronMQ.class.php
@@ -131,6 +131,9 @@ class IronMQ extends IronCore{
'api_version' => '1',
);
+ const LIST_QUEUES_PER_PAGE = 30;
+ const GET_MESSAGE_TIMEOUT = 60;
+
/**
* @param string|array $config_file_or_options
* Array of options or name of config file.
@@ -165,11 +168,22 @@ public function setProjectId($project_id) {
}
}
- public function getQueues($page = 0){
+ /**
+ * Get list of message queues
+ *
+ * @param int $page
+ * Zero-indexed page to view
+ * @param int $per_page
+ * Number of queues per page
+ */
+ public function getQueues($page = 0, $per_page = self::LIST_QUEUES_PER_PAGE) {
$url = "projects/{$this->project_id}/queues";
$params = array();
- if($page > 0) {
- $params['page'] = $page;
+ if($page !== 0) {
+ $params['page'] = (int) $page;
+ }
+ if($per_page !== self::LIST_QUEUES_PER_PAGE) {
+ $params['per_page'] = (int) $per_page;
}
$this->setJsonHeaders();
return self::json_decode($this->apiCall(self::GET, $url, $params));
@@ -261,14 +275,18 @@ public function postMessages($queue_name, $messages) {
*
* @param string $queue_name Queue name
* @param int $count
+ * @param int $timeout
* @return array|null array of messages or null
*/
- public function getMessages($queue_name, $count=1) {
+ public function getMessages($queue_name, $count = 1, $timeout = self::GET_MESSAGE_TIMEOUT) {
$queue = rawurlencode($queue_name);
$url = "projects/{$this->project_id}/queues/$queue/messages";
$params = array();
- if($count > 1) {
- $params['n'] = $count;
+ if($count !== 1) {
+ $params['n'] = (int) $count;
+ }
+ if($timeout !== self::GET_MESSAGE_TIMEOUT) {
+ $params['timeout'] = (int) $timeout;
}
$this->setJsonHeaders();
$response = $this->apiCall(self::GET, $url, $params);
@@ -284,10 +302,11 @@ public function getMessages($queue_name, $count=1) {
* Get single message from queue
*
* @param string $queue_name Queue name
+ * @param int $timeout
* @return mixed|null single message or null
*/
- public function getMessage($queue_name) {
- $messages = $this->getMessages($queue_name, 1);
+ public function getMessage($queue_name, $timeout = self::GET_MESSAGE_TIMEOUT) {
+ $messages = $this->getMessages($queue_name, 1, $timeout);
if ($messages){
return $messages[0];
}else{
Something went wrong with that request. Please try again.