forked from laravel-notification-channels/webex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebexMessageAttachment.php
97 lines (86 loc) · 2.4 KB
/
WebexMessageAttachment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace NotificationChannels\Webex;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
/**
* This class provides a fluent interface for creating a Webex Message Attachment representation.
*/
class WebexMessageAttachment implements Arrayable, Jsonable, JsonSerializable
{
/**
* The content type of the attachment.
*/
public string $contentType = 'application/vnd.microsoft.card.adaptive';
/**
* The content of the attachment.
*
* @var array|mixed
*/
public mixed $content;
/**
* Set the content type of the attachment.
*/
public function contentType(string $contentType): WebexMessageAttachment
{
$this->contentType = $contentType;
return $this;
}
/**
* Set the content of the attachment.
*
* @param array|mixed $content
*
* @link https://developer.webex.com/buttons-and-cards-designer
* @link https://adaptivecards.io/
*/
public function content(mixed $content): WebexMessageAttachment
{
$this->content = $content;
return $this;
}
/**
* Get the instance as an array suitable for `multipart/form-data` request.
*
* @return array an associative array with name, contents, and headers as keys
*
* @internal
*/
public function toArray(): array
{
return [
'name' => 'attachments',
'contents' => json_encode($this->jsonSerialize()),
'headers' => ['Content-Type' => 'application/json'],
];
}
/**
* Get the instance as an array suitable for `application/json` request or {@see \json_encode()}.
*
* @return array all instance properties as an associative array
*
* @internal
*/
public function jsonSerialize(): array
{
return [
'contentType' => $this->contentType,
'content' => $this->content,
];
}
/**
* Get the instance as JSON.
*
* This is a wrapper around PHP's {@see \json_encode()} and the instance's
* {@see jsonSerialize()}.
*
* @param int $options a bitmask flag parameter for {@see \json_encode()}
* @return string the JSON representation
*
* @internal
*/
public function toJson($options = 0): string
{
return json_encode($this->jsonSerialize(), $options);
}
}