diff --git a/lib/Trello/Api/Board.php b/lib/Trello/Api/Board.php index a033270..2851872 100644 --- a/lib/Trello/Api/Board.php +++ b/lib/Trello/Api/Board.php @@ -336,4 +336,14 @@ public function powerUps() { return new Board\PowerUps($this->client); } + + /** + * Board CustomFields API + * + * @return Board\CustomFields + */ + public function customFields() + { + return new Board\CustomFields($this->client); + } } diff --git a/lib/Trello/Api/Board/CustomFields.php b/lib/Trello/Api/Board/CustomFields.php new file mode 100644 index 0000000..d81515c --- /dev/null +++ b/lib/Trello/Api/Board/CustomFields.php @@ -0,0 +1,33 @@ +get($this->getPath($id), $params); + } +} diff --git a/lib/Trello/Api/Board/Labels.php b/lib/Trello/Api/Board/Labels.php index f924f76..095b9d7 100644 --- a/lib/Trello/Api/Board/Labels.php +++ b/lib/Trello/Api/Board/Labels.php @@ -56,6 +56,27 @@ public function show($id, $color) return $this->get($this->getPath($id).'/'.rawurlencode($color)); } + /** + * Add a label related to a given board + * @link https://developers.trello.com/advanced-reference/board#post-1-boards-board-id-labels + * + * @param string $id the board's id + * @param string $color the label's color + * @param string $name the label's name + * + * @return array + */ + public function add($id, $color, $name) + { + + $params = array( + 'color' => $color, + 'name' => $name + ); + + return $this->post($this->getPath($id), $params); + } + /** * Set a label's name on a given board and for a given color * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-blue diff --git a/lib/Trello/Api/Board/Members.php b/lib/Trello/Api/Board/Members.php index f1cc6c2..8091936 100644 --- a/lib/Trello/Api/Board/Members.php +++ b/lib/Trello/Api/Board/Members.php @@ -47,6 +47,25 @@ public function remove($id, $memberId) { return $this->delete($this->getPath($id).'/'.$memberId); } + + /** + * Add a given member from a given board + * @link https://trello.com/docs/api/board/#get-1-boards-board-id-members + * + * @param string $id the board's id + * @param string $memberId the member's id + * + * @return array + */ + public function add($id, $memberId, $role = 'normal') + { + $params = array( + 'idMember' => $memberId, + 'type' => $role, + ); + + return $this->put($this->getPath($id).'/'.$memberId, $params); + } /** * Filter members related to a given board diff --git a/lib/Trello/Api/Card.php b/lib/Trello/Api/Card.php index 5c45e16..3b0bb47 100644 --- a/lib/Trello/Api/Card.php +++ b/lib/Trello/Api/Card.php @@ -9,11 +9,7 @@ * @link https://trello.com/docs/api/card * * Unimplemented: - * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-name - * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-pos - * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-state * - https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem - * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-converttocard * - https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-markassociatednotificationsread */ @@ -91,6 +87,24 @@ public function create(array $params = array()) return $this->post($this->getPath(), $params); } + + /** + * Create a checklist Item + * @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem + * + * @param string $cardId id of the card the item is added to + * @param string $checkListId id of the checklist the item is added to + * @param array $params optional attributes + * + * @return array card info + */ + + public function createCheckListItem($cardId, $checkListId, $params = Array()){ + + $this->validateRequiredParameters(array('idChecklist', 'name'), $params); + + return $this->post($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem', $params); + } /** * Update a card @@ -152,6 +166,45 @@ public function getBoardField($id, $field) return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field)); } + /** + * Get the checkitemstates, for now will return the full list of checkitem states; + * @link https://trello.com/docs/api/card/index.html#get-1-cards-card-id-or-shortlink-checkitemstates + * + * @param string $id the card's id or short link + * + * @return array list info + */ + public function getCheckItemStates($id){ + + return $this->get($this->getPath().'/'.rawurlencode($id).'/checkItemStates', array('value' => 'all')); + } + + /** + * Get the checklists, for now will return the full list of checkitem states; + * @link https://trello.readme.io/v1.0/reference#cardsidchecklists + * + * @param string $id the card's id or short link + * @param array $fields (optional) an array with the requested fields, all by default + * + * @return array checklist info + */ + public function getCheckLists($id, array $fields = array('fields'=>'all')){ + + return $this->get($this->getPath().'/'.rawurlencode($id).'/checklists', $fields); + + } + + /** + * Get the members; + * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-members + * + * @param string $id the card's id or short link + * + * @return array list info + */ + public function getMembers($id){ + return $this->get($this->getPath().'/'.rawurlencode($id).'/members', array('value' => 'all')); + } /** * Set a given card's list * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idlist @@ -283,6 +336,128 @@ public function setSubscribed($id, $subscribed) return $this->put($this->getPath().'/'.rawurlencode($id).'/subscribed', array('value' => $subscribed)); } + + /** + * Set a given card's memberId + * @link tbd + * + * @param string $id the list's id + * @param string $idMembers comma seperated list of responsible members + * + * @return array list info + */ + public function setIdMembers($id, $idMembers) + { + return $this->put($this->getPath().'/'.rawurlencode($id).'/idMembers', array('value' => $idMembers)); + } + +/** + * Set a given checklist item name + * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-name + * + * @param string $cardId the cards's id + * @param string $checkListId the checklist's id + * @param string $itemId the item's id + * @param string $name new name value + * + * @return array list info + */ + public function setCheckListItemName($cardId,$checkListId,$itemId, $name) + { + return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/name', array('value' => $name)); + } + + /** + * Set a given checklist item position + * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-pos + * + * @param string $cardId the cards's id + * @param string $checkListId the checklist's id + * @param string $itemId the item's id + * @param string $position new position value + * + * @return array list info + */ + public function setCheckListItemPosition($cardId,$checkListId,$itemId, $position) + { + return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/pos', array('value' => $position)); + } + + /** + * Set a given checklist item closed state + * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-checklist-idchecklist-checkitem-idcheckitem-state + * + * @param string $cardId the cards's id + * @param string $checkListId the checklist's id + * @param string $itemId the item's id + * @param bool $complete new complete value, defaults to true + * + * @return array list info + */ + public function setCheckListItemClosed($cardId,$checkListId,$itemId, $complete = true) + { + return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId).'/state', array('value' => $complete)); + } + + /** + * Update checklist item by parameter array + * @link https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-checklist-idchecklistcurrent-checkitem-idcheckitem + * + * @param string $cardId the cards's id + * @param string $checkListId the checklist's id + * @param string $itemId the item's id + * @param array $params item attributes to update + * + * @return array list info + */ + public function updateCheckListItem($cardId,$checkListId,$itemId, $params = array()) + { + return $this->put($this->getPath().'/'.rawurlencode($cardId).'/checklist/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($itemId), $params); + } + + /** + * Get checkitem from a given card + * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2 + * + * @param string $id the card's id or short link + * @param string $checkItemId the check item id + * @param array $params the parameter array to retrieve, default is to retrieve all fields + * + * @return array + */ + public function getCheckItem($id, $checkItemId, array $params = array('fields'=> 'all')) + { + return $this->get($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $params); + } + + /** + * Update checkItem for a given card + * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-1 + * + * @param string $id the card's id or short link + * @param string $checkItemId the check item id + * @param array $updateFields the fields that should be updated + * @return array + */ + public function updateCheckItem($id, $checkItemId, array $updateFields = array()) + { + return $this->put($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId), $updateFields); + } + + /** + * Remove checkitem from a given card + * @link https://trello.readme.io/v1.0/reference#cardsidcheckitemidcheckitem-2 + * + * @param string $id the card's id or short link + * @param string $checkItemId the checklist item id + * + * @return array + */ + public function removeCheckItem($id, $checkItemId) + { + return $this->delete($this->getPath().'/'.rawurlencode($id).'/checkItem/'.rawurlencode($checkItemId)); + } + /** * Actions API * @@ -342,4 +517,14 @@ public function stickers() { return new Card\Stickers($this->client); } + + /** + * CustomFieldItems API + * + * @return Card\CustomFieldItems + */ + public function customFieldItems() + { + return new Card\CustomFieldItems($this->client); + } } diff --git a/lib/Trello/Api/Card/Actions.php b/lib/Trello/Api/Card/Actions.php index a87032b..a57e926 100644 --- a/lib/Trello/Api/Card/Actions.php +++ b/lib/Trello/Api/Card/Actions.php @@ -27,7 +27,7 @@ public function all($id, array $params = array()) { return $this->get($this->getPath($id), $params); } - + /** * Add comment to a given card * @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-actions-comments @@ -53,6 +53,20 @@ public function addComment($id, $text) */ public function removeComment($id, $commentId) { - return $this->delete($this->getPath($id).'/comments/'.rawurlencode($commentId)); + return $this->delete($this->getPath($id).'/'.rawurlencode($commentId).'/comments'); + } + + /** + * Update comment to a given card + * @link https://trello.com/docs/api/card/index.html#put-1-cards-card-id-or-shortlink-actions-idaction-comments + * + * @param string $id the card's id or short link + * @param string $commentId the comment's id + * @param string $text the new comment text + * @return array + */ + public function updateComment($id, $commentId, $text) + { + return $this->put($this->getPath($id).'/'.rawurlencode($commentId).'/comments', array('text' => $text)); } } diff --git a/lib/Trello/Api/Card/CustomFieldItems.php b/lib/Trello/Api/Card/CustomFieldItems.php new file mode 100644 index 0000000..912197e --- /dev/null +++ b/lib/Trello/Api/Card/CustomFieldItems.php @@ -0,0 +1,56 @@ + 'true')); + $data = $this->get($this->getPath($id), $params); + + return array_key_exists('customFieldItems', $data) ? $data['customFieldItems'] : array(); + } + + /** + * Update a given custom field value on a given card + * @link https://developers.trello.com/docs/getting-started-custom-fields#section-setting-updating-customfielditems + * + * @param string $id the card's id or short link + * @param string $customFieldId the card's id or short link + * @param array $value the member's id + * + * @return array + */ + public function update($id, $customFieldId, $value = array()) + { + $path = $this->getPath($id) . 'customField/' . rawurldecode($customFieldId) . '/item'; + + return $this->put( + $path, + $value + ); + } +} diff --git a/lib/Trello/Api/Card/Labels.php b/lib/Trello/Api/Card/Labels.php index a8cfbfd..201a425 100644 --- a/lib/Trello/Api/Card/Labels.php +++ b/lib/Trello/Api/Card/Labels.php @@ -38,6 +38,25 @@ public function set($id, array $labels) return $this->put($this->getPath($id), array('value' => $labels)); } + + /** + * Set a given card's label by labelId + * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-labels + * + * @param string $id the card's id or short link + * @param string $labelId the label id + * + * @return array card info + * + * @throws InvalidArgumentException If a label does not exist + */ + public function setById($id, $labelId) + { + //first set the right path based on the documentation; + $this->path = 'cards/#id#/idLabels'; + + return $this->post($this->getPath($id), array('value' => $labelId)); + } /** * Remove a given label from a given card @@ -58,4 +77,21 @@ public function remove($id, $label) return $this->delete($this->getPath($id).'/'.rawurlencode($label)); } + + /** + * Remove a given label from a given card based on the label id + * @link https://developers.trello.com/advanced-reference/card#delete-1-cards-card-id-or-shortlink-idlabels-idlabel + * + * @param string $id the card's id or short link + * @param string $labelId the label id to remove + * + * @return array card info + * + * @throws InvalidArgumentException If a label does not exist + */ + public function removeById($id, $labelId) + { + $this->path = 'cards/#id#/idLabels'; + return $this->delete($this->getPath($id).'/'.rawurlencode($labelId)); + } } diff --git a/lib/Trello/Api/Checklist.php b/lib/Trello/Api/Checklist.php index be3e783..29711c1 100644 --- a/lib/Trello/Api/Checklist.php +++ b/lib/Trello/Api/Checklist.php @@ -85,7 +85,52 @@ public function remove($id) { return $this->delete($this->getPath().'/'.rawurlencode($id)); } - + + /** + * Remove a listitem from a checklist + * @link https://trello.com/docs/api/checklist/index.html#delete-1-checklists-idchecklist-checkitems-idcheckitem + * + * @param string $checkListId the checklist's id + * @param string $listItemId the listItem id + * + * @return array + */ + public function removeListItem($checkListId, $listItemId) + { + return $this->delete($this->getPath().'/'.rawurlencode($checkListId).'/checkItems/'.rawurlencode($listItemId)); + } + + + /** + * get checklist items from a checklist + * @link https://trello.readme.io/v1.0/reference#checklistsidcardscheckitems + * + * @param string $checkListId the checklist's id + * @param string $listItemId (optional) the listItem id + * @param array $fields (options) the fields to retrieve + * + * @return array + */ + public function getListItems($checkListId, array $fields = array('fields' => 'all')) + { + return $this->get($this->getPath().'/'.rawurlencode($checkListId).'/checkItems', $fields); + } + + /** + * get a specific checklist item from a checklist + * @link https://trello.readme.io/v1.0/reference#checklistsidcardscheckitems + * + * @param string $checkListId the checklist's id + * @param string $listItemId the listItem id + * @param array $fields (options) the fields to retrieve + * + * @return array + */ + public function getListItem($checkListId, $listItemId, array $fields = array('fields' => 'all')) + { + return $this->get($this->getPath().'/'.rawurlencode($checkListId).'/checkItem/'.rawurlencode($listItemId), $fields); + } + /** * Get the board of a given checklist * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-board diff --git a/lib/Trello/Client.php b/lib/Trello/Client.php index d276941..6626520 100644 --- a/lib/Trello/Client.php +++ b/lib/Trello/Client.php @@ -62,7 +62,7 @@ class Client implements ClientInterface private $options = array( 'base_url' => 'https://api.trello.com/', 'user_agent' => 'php-trello-api (http://github.com/cdaguerre/php-trello-api)', - 'timeout' => 10, + 'timeout' => 50, 'api_limit' => 5000, 'api_version' => 1, 'cache_dir' => null, diff --git a/lib/Trello/HttpClient/HttpClient.php b/lib/Trello/HttpClient/HttpClient.php index fda62e8..bdb4d98 100644 --- a/lib/Trello/HttpClient/HttpClient.php +++ b/lib/Trello/HttpClient/HttpClient.php @@ -17,7 +17,7 @@ class HttpClient implements HttpClientInterface protected $options = array( 'base_url' => 'https://api.trello.com/', 'user_agent' => 'php-trello-api (http://github.com/cdaguerre/php-trello-api)', - 'timeout' => 10, + 'timeout' => 50, 'api_version' => 1, );