|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Rizart Dokollari <[email protected]> |
|
4
|
|
|
* @author Jeroen Derks <[email protected]> |
|
5
|
|
|
* @since 12/24/17 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ElasticEmail; |
|
9
|
|
|
|
|
10
|
|
|
abstract class Response |
|
11
|
|
|
{ |
|
12
|
|
|
/** @var \GuzzleHttp\Psr7\Response */ |
|
13
|
|
|
protected $response; |
|
14
|
|
|
|
|
15
|
|
|
/** @var object */ |
|
16
|
|
|
protected $body = null; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return \GuzzleHttp\Psr7\Response |
|
20
|
|
|
*/ |
|
21
|
|
|
public function getResponse() |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->response; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function context() |
|
27
|
|
|
{ |
|
28
|
|
|
$body = $this->getBody(); |
|
29
|
|
|
return property_exists($body, 'Context') ? $body->Context : null; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return object |
|
34
|
|
|
*/ |
|
35
|
|
|
public function data() |
|
36
|
|
|
{ |
|
37
|
|
|
$body = $this->getBody(); |
|
38
|
|
|
return property_exists($body, 'data') ? $body->data : null; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return object|null |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getBody() |
|
45
|
|
|
{ |
|
46
|
|
|
if (null === $this->body) { |
|
47
|
|
|
$this->body = json_decode((string) $this->response->getBody()); |
|
48
|
|
|
} |
|
49
|
|
|
return $this->body; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return boolean |
|
54
|
|
|
*/ |
|
55
|
|
|
public function wasSuccessful() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->getBody()->success; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return int |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getStatusCode() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->response->getStatusCode(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function code() |
|
69
|
|
|
{ |
|
70
|
|
|
$body = $this->getBody(); |
|
71
|
|
|
return property_exists($body, 'Code') ? $body->Code : null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function error() |
|
75
|
|
|
{ |
|
76
|
|
|
$body = $this->getBody(); |
|
77
|
|
|
return property_exists($body, 'error') ? $body->error : null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
public function messageId() |
|
84
|
|
|
{ |
|
85
|
|
|
$data = $this->data(); |
|
86
|
|
|
return property_exists($data, 'messageid') ? $data->messageid : null; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function transactionId() |
|
93
|
|
|
{ |
|
94
|
|
|
$data = $this->data(); |
|
95
|
|
|
return property_exists($data, 'transactionid') ? $data->transactionid : null; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|