Skip to content

Commit

Permalink
Merge pull request #15 from iwiznia/master
Browse files Browse the repository at this point in the history
Add support for attachment's title and title link
  • Loading branch information
maknz committed Mar 16, 2015
2 parents d25b168 + 84b97f7 commit 9c4f7d0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
68 changes: 67 additions & 1 deletion src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ class Attachment {
*/
protected $pretext;

/**
* Optional title for the attachment
*
* @var string
*/
protected $title;

/**
* Optional title link for the attachment
*
* @var string
*/
protected $title_link;

/**
* The color to use for the attachment
*
Expand Down Expand Up @@ -75,6 +89,10 @@ public function __construct(array $attributes)
if (isset($attributes['fields'])) $this->setFields($attributes['fields']);

if (isset($attributes['mrkdwn_in'])) $this->setMarkdownFields($attributes['mrkdwn_in']);

if (isset($attributes['title'])) $this->setTitle($attributes['title']);

if (isset($attributes['title_link'])) $this->setTitleLink($attributes['title_link']);
}

/**
Expand Down Expand Up @@ -193,6 +211,52 @@ public function setColor($color)
}

/**
* Get the title to use for the attachment
*
* @return string
*/
public function getTitle()
{
return $this->title;
}

/**
* Set the title to use for the attachment
*
* @param string $title
* @return void
*/
public function setTitle($title)
{
$this->title = $title;

return $this;
}

/**
* Get the title link to use for the attachment
*
* @return string
*/
public function getTitleLink()
{
return $this->title_link;
}

/**
* Set the title link to use for the attachment
*
* @param string $title_link
* @return void
*/
public function setTitleLink($title_link)
{
$this->title_link = $title_link;

return $this;
}

/**
* Get the fields for the attachment
*
* @return array
Expand Down Expand Up @@ -295,7 +359,9 @@ public function toArray()
'pretext' => $this->getPretext(),
'color' => $this->getColor(),
'mrkdwn_in' => $this->getMarkdownFields(),
'image_url' => $this->getImageUrl()
'image_url' => $this->getImageUrl(),
'title' => $this->getTitle(),
'title_link' => $this->getTitleLink()
];

$data['fields'] = $this->getFieldsAsArrays();
Expand Down
2 changes: 2 additions & 0 deletions tests/AttachmentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function testAttachmentToArray()
'color' => 'bad',
'mrkdwn_in' => ['pretext', 'text'],
'image_url' => 'http://fake.host/image.png',
'title' => 'A title',
'title_link' => 'http://fake.host/',
'fields' => [
[
'title' => 'Title 1',
Expand Down
6 changes: 5 additions & 1 deletion tests/ClientFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function testMessageWithAttachments()
'color' => 'bad',
'mrkdwn_in' => ['pretext', 'text'],
'image_url' => 'http://fake.host/image.png',
'fields' => []
'fields' => [],
'title' => null,
'title_link' => null
];

$expectedHttpData = [
Expand Down Expand Up @@ -75,6 +77,8 @@ public function testMessageWithAttachmentsAndFields()
'color' => 'bad',
'mrkdwn_in' => [],
'image_url' => 'http://fake.host/image.png',
'title' => 'A title',
'title_link' => 'http://fake.host/',
'fields' => [
[
'title' => 'Field 1',
Expand Down

0 comments on commit 9c4f7d0

Please sign in to comment.