1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sausin\Signere; |
4
|
|
|
|
5
|
|
|
class Message extends BaseClass |
6
|
|
|
{ |
7
|
|
|
/** The URI of the action */ |
8
|
|
|
const URI = 'https://api.signere.no/api/Message'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Get a list of messages sent for the given document ID. |
12
|
|
|
* |
13
|
|
|
* @param string $messageId |
14
|
|
|
* @return object |
15
|
|
|
*/ |
16
|
1 |
|
public function get(string $messageId) |
17
|
|
|
{ |
18
|
|
|
// make the URL for this request |
19
|
1 |
|
$url = sprintf('%s/%s', $this->getBaseUrl(), $messageId); |
20
|
|
|
|
21
|
|
|
// get the headers for this request |
22
|
1 |
|
$headers = $this->headers->make('GET', $url); |
23
|
|
|
|
24
|
|
|
// get the response |
25
|
1 |
|
$response = $this->client->get($url, [ |
26
|
1 |
|
'headers' => $headers, |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
// return the response |
30
|
1 |
|
return $response; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Retrieves a list of all the messages that |
35
|
|
|
* are sent for the given document. |
36
|
|
|
* |
37
|
|
|
* @param string $documentId |
38
|
|
|
* @return object |
39
|
|
|
*/ |
40
|
1 |
|
public function all(string $documentId) |
41
|
|
|
{ |
42
|
|
|
// make the URL for this request |
43
|
1 |
|
$url = sprintf('%s/Document/%s', $this->getBaseUrl(), $documentId); |
44
|
|
|
|
45
|
|
|
// get the headers for this request |
46
|
1 |
|
$headers = $this->headers->make('GET', $url); |
47
|
|
|
|
48
|
|
|
// get the response |
49
|
1 |
|
$response = $this->client->get($url, [ |
50
|
1 |
|
'headers' => $headers, |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
// return the response |
54
|
1 |
|
return $response; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sends a message to the signees of a given document. |
59
|
|
|
* |
60
|
|
|
* @param array $body |
61
|
|
|
* @return object |
62
|
|
|
*/ |
63
|
1 |
|
public function sendMessage(array $body) |
64
|
|
|
{ |
65
|
|
|
// make the URL for this request |
66
|
1 |
|
$url = $this->getBaseUrl(); |
67
|
|
|
|
68
|
|
|
// get the headers for this request |
69
|
1 |
|
$headers = $this->headers->make('POST', $url, $body); |
70
|
|
|
|
71
|
|
|
// get the response |
72
|
1 |
|
$response = $this->client->post($url, [ |
73
|
1 |
|
'headers' => $headers, |
74
|
1 |
|
'json' => $body, |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
// return the response |
78
|
1 |
|
return $response; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Sends a new message to the Signeeref if the first one failed. |
83
|
|
|
* |
84
|
|
|
* @param array $body |
85
|
|
|
* @return object |
86
|
|
|
*/ |
87
|
1 |
View Code Duplication |
public function sendNewMessage(array $body) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
// make the URL for this request |
90
|
1 |
|
$url = sprintf('%s/SendNewDocumentMessage', $this->getBaseUrl()); |
91
|
|
|
|
92
|
|
|
// get the headers for this request |
93
|
1 |
|
$headers = $this->headers->make('PUT', $url, $body); |
94
|
|
|
|
95
|
|
|
// get the response |
96
|
1 |
|
$response = $this->client->post($url, [ |
97
|
1 |
|
'headers' => $headers, |
98
|
1 |
|
'json' => $body, |
99
|
|
|
]); |
100
|
|
|
|
101
|
|
|
// return the response |
102
|
1 |
|
return $response; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Sends a message to an external person with a link/URL |
107
|
|
|
* to view a document. |
108
|
|
|
* |
109
|
|
|
* @param array $body |
110
|
|
|
* @return object |
111
|
|
|
*/ |
112
|
1 |
View Code Duplication |
public function sendExternalMessage(array $body) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
// make the URL for this request |
115
|
1 |
|
$url = sprintf('%s/SendExternalMessage', $this->getBaseUrl()); |
116
|
|
|
|
117
|
|
|
// get the headers for this request |
118
|
1 |
|
$headers = $this->headers->make('POST', $url, $body); |
119
|
|
|
|
120
|
|
|
// get the response |
121
|
1 |
|
$response = $this->client->post($url, [ |
122
|
1 |
|
'headers' => $headers, |
123
|
1 |
|
'json' => $body, |
124
|
|
|
]); |
125
|
|
|
|
126
|
|
|
// return the response |
127
|
1 |
|
return $response; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.