Skip to content

Commit

Permalink
Merge 5916c19 into 579530b
Browse files Browse the repository at this point in the history
  • Loading branch information
amycw committed Aug 9, 2018
2 parents 579530b + 5916c19 commit fed2650
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 59 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -13,8 +13,8 @@
],
"require": {
"php": ">=5.3",
"guzzlehttp/guzzle": "~3.7"
},
"guzzle/guzzle":"~3.7"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
},
Expand Down
13 changes: 13 additions & 0 deletions docs/Event/CardLabelEvent.md
@@ -0,0 +1,13 @@

======================

### Set label
```php
setLabel(\Trello\Model\LabelInterface $label)
```

### Get label
```php
getLabel()
```

5 changes: 5 additions & 0 deletions docs/Manager.md
Expand Up @@ -26,6 +26,11 @@ getList(string $id)
getCard(string $id)
```

### Get label by id or create a new one
```php
getLabel(string $id)
```

### Get checklist by id or create a new one
```php
getChecklist(string $id)
Expand Down
10 changes: 10 additions & 0 deletions docs/Model/Board.md
Expand Up @@ -151,6 +151,16 @@ setLabelNames(array $labelNames)
getLabelNames()
```

### Get labels
```php
getLabels()
```

### Get label that has name $name and color $color
```php
getLabel($name, $color)
```

### Set power ups
```php
setPowerUps(array $powerUps)
Expand Down
10 changes: 10 additions & 0 deletions docs/Model/BoardInterface.md
Expand Up @@ -151,6 +151,16 @@ setLabelNames(array $labelNames)
getLabelNames()
```

### Get labels
```php
getLabels()
```

### Get label that has name $name and color $color
```php
getLabel($name, $color)
```

### Set power ups
```php
setPowerUps(array $powerUps)
Expand Down
16 changes: 8 additions & 8 deletions docs/Model/Card.md
Expand Up @@ -281,24 +281,24 @@ setLabels(array $labels)
getLabels()
```

### Get the colors of labels associated to this card
### Get the ids of labels associated to this card
```php
getLabelColors()
getLabelIds()
```

### Does the card have the label of which the color is $color?
### Does the card have the label?
```php
hasLabel($color)
hasLabel(LabelInterface $label)
```

### Add the label of color $color
### Add the label $label
```php
addLabel($color)
addLabel(LabelInterface $label)
```

### Remove the label of color $color
### Remove the label $label
```php
removeLabel($color)
removeLabel(LabelInterface $label)
```

### Set Badges
Expand Down
47 changes: 47 additions & 0 deletions docs/Model/Label.md
@@ -0,0 +1,47 @@

======================

### Get id
```php
getId()
```

### Set name
```php
setName($name)
```

### Get name
```php
getName()
```

### Set color
```php
setColor($color)
```

### Get color
```php
getColor()
```

### Set boardId
```php
setBoardId($boardId)
```

### Get boardId
```php
getBoardId()
```

### Set board
```php
setBoard(\Trello\Model\BoardInterface $board)
```

### Get board
```php
getBoard()
```
47 changes: 47 additions & 0 deletions docs/Model/LabelInterface.md
@@ -0,0 +1,47 @@

======================

### Get id
```php
getId()
```

### Set name
```php
setName($name)
```

### Get name
```php
getName()
```

### Set color
```php
setColor($color)
```

### Get color
```php
getColor()
```

### Set boardId
```php
setBoardId($boardId)
```

### Get boardId
```php
getBoardId()
```

### Set board
```php
setBoard(\Trello\Model\BoardInterface $board)
```

### Get board
```php
getBoard()
```
4 changes: 0 additions & 4 deletions lib/Trello/Api/AbstractApi.php
Expand Up @@ -211,13 +211,11 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr
$parameters[$name] = $parameter ? 'true' : 'false';
}
}

$response = $this->client->getHttpClient()->put(
$path,
$this->createParametersBody($parameters),
$requestHeaders
);

return ResponseMediator::getContent($response);
}

Expand Down Expand Up @@ -258,9 +256,7 @@ protected function createParametersBody(array $parameters)
if (is_bool($subParameter)) {
$subParameter = $subParameter ? 'true' : 'false';
}
$parameters[$name.'/'.$subName] = $subParameter;
}
unset($parameters[$name]);
} elseif ($parameter instanceof DateTime) {
$parameters[$name] = $parameter->format($parameter::ATOM);
}
Expand Down
110 changes: 110 additions & 0 deletions lib/Trello/Api/Label.php
@@ -0,0 +1,110 @@
<?php

namespace Trello\Api;

use Trello\Exception\InvalidArgumentException;

class Label extends AbstractApi
{
/**
* Base path of labels api
* @var string
*/
protected $path = 'labels';


public static $fields = array(
'idBoard',
'name',
'color',
);

/**
* Find a label by id
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $params optional attributes
*
* @return array label info
*/
public function show($id, array $params = array())
{
return $this->get($this->getPath().'/'.rawurlencode($id), $params);
}

/**
* Create a label
* @link https://developers.trello.com/reference/#id-1
*
* @param array $params optional attributes
*
* @return array label info
*/
public function create(array $params = array())
{
$this->validateRequiredParameters(array('name', 'idBoard', 'color'), $params);

return $this->post('boards/'.rawurlencode($params['idBoard']).'/labels/', $params);
}

/**
* Update a label
* @link https://developers.trello.com/reference/#id-1
*
* @param string $id the label's id
* @param array $params label attributes to update
*
* @return array label info
*/
public function update($id, array $params = array())
{
return $this->put($this->getPath().'/'.rawurlencode($id).'/labels/', $params);
}

/**
* Set a given label's board
* @link https://developers.trello.com/reference/#id-1
*
* @param string $id the label's id
* @param string $boardId the board's id
*
* @return array board info
*/
public function setBoard($id, $boardId)
{
return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
}

/**
* Get a given label's board
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $params optional parameters
*
* @return array board info
*/
public function getBoard($id, array $params = array())
{
return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
}

/**
* Get the field of a board of a given label
* @link https://developers.trello.com/reference/#id
*
* @param string $id the label's id
* @param array $field the name of the field
*
* @return array
*
* @throws InvalidArgumentException if the field does not exist
*/
public function getBoardField($id, $field)
{
$this->validateAllowedParameters(Board::$fields, $field, 'field');

return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
}
}
4 changes: 4 additions & 0 deletions lib/Trello/Client.php
Expand Up @@ -137,6 +137,10 @@ public function api($name)
case 'webhooks':
$api = new Api\Webhook($this);
break;
case 'label':
case 'labels':
$api = new Api\Label($this);
break;
default:
throw new InvalidArgumentException(sprintf('Undefined api called: "%s"', $name));
}
Expand Down
33 changes: 33 additions & 0 deletions lib/Trello/Event/CardLabelEvent.php
@@ -0,0 +1,33 @@
<?php

namespace Trello\Event;

use Trello\Model\LabelInterface;

class CardChecklistEvent extends CardEvent
{
/**
* @var LabelInterface
*/
protected $checklist;

/**
* Set label
*
* @param LabelInterface $label
*/
public function setLabel(LabelInterface $label)
{
$this->label = $label;
}

/**
* Get label
*
* @return LabelInterface
*/
public function getLabel()
{
return $this->label;
}
}
4 changes: 2 additions & 2 deletions lib/Trello/Events.php
Expand Up @@ -202,13 +202,13 @@ final class Events

/**
* When a new label is added to a card
* The event listener method receives a Trello\Event\CardEvent instance.
* The event listener method receives a Trello\Event\CardLabelEvent instance.
*/
const CARD_ADD_LABEL = 'addLabelToCard';

/**
* When a new label is removed from a card
* The event listener method receives a Trello\Event\CardEvent instance.
* The event listener method receives a Trello\Event\CardLabelEvent instance.
*/
const CARD_REMOVE_LABEL = 'removeLabelFromCard';

Expand Down

0 comments on commit fed2650

Please sign in to comment.