Skip to content

Commit

Permalink
Merge pull request #14 from Leenug/add_image_to_attachment
Browse files Browse the repository at this point in the history
Add image_url to attachment
  • Loading branch information
maknz committed Mar 4, 2015
2 parents b9e6938 + b05f0d8 commit 3a42047
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class Attachment {
*/
protected $text;

/**
* Optional image that should appear within the attachment
*
* @var string
*/
protected $image_url;

/**
* Optional text that should appear above the formatted data
*
Expand Down Expand Up @@ -59,6 +66,8 @@ public function __construct(array $attributes)

if (isset($attributes['text'])) $this->setText($attributes['text']);

if (isset($attributes['image_url'])) $this->setImageUrl($attributes['image_url']);

if (isset($attributes['pretext'])) $this->setPretext($attributes['pretext']);

if (isset($attributes['color'])) $this->setColor($attributes['color']);
Expand Down Expand Up @@ -114,6 +123,29 @@ public function setText($text)
return $this;
}

/**
* Get the optional image to appear within the attachment
*
* @return string
*/
public function getImageUrl()
{
return $this->image_url;
}

/**
* Set the optional image to appear within the attachment
*
* @param string $image_url
* @return $this
*/
public function setImageUrl($image_url)
{
$this->image_url = $image_url;

return $this;
}

/**
* Get the text that should appear above the formatted data
*
Expand Down Expand Up @@ -262,7 +294,8 @@ public function toArray()
'text' => $this->getText(),
'pretext' => $this->getPretext(),
'color' => $this->getColor(),
'mrkdwn_in' => $this->getMarkdownFields()
'mrkdwn_in' => $this->getMarkdownFields(),
'image_url' => $this->getImageUrl()
];

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

Expand Down Expand Up @@ -73,6 +74,7 @@ public function testMessageWithAttachmentsAndFields()
'pretext' => null,
'color' => 'bad',
'mrkdwn_in' => [],
'image_url' => 'http://fake.host/image.png',
'fields' => [
[
'title' => 'Field 1',
Expand Down

0 comments on commit 3a42047

Please sign in to comment.