This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-postmark-dmarc-api.php
197 lines (168 loc) · 4.04 KB
/
wp-postmark-dmarc-api.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
/**
* WP Postmark API (http://developer.postmarkapp.com/)
*
* @package WP-API-Libraries\WP-Postmark-Base\WP-Postmark-Dmarc-API
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/* Check if class exists. */
if ( ! class_exists( 'PostMarkDmarcAPI' ) ) {
if ( ! class_exists( 'PostMarkBase' ) ) {
include_once( 'wp-postmark-base.php' );
}
/**
* PostMarkAPI class.
*/
class PostMarkDmarcAPI extends PostMarkBase {
/**
* Dmark Base URI
* Docs: https://dmarc.postmarkapp.com/api/
* Route: https://dmarc.postmarkapp.com/
*
* (default value: 'https://dmarc.postmarkapp.com/')
*
* @var string
* @access protected
*/
protected $route_uri = 'https://dmarc.postmarkapp.com';
/**
* __construct function.
*
* @access public
* @param string $account_token (default: null) Account Token.
* @return void
*/
public function __construct( string $account_token = null ) {
$this->account_token = $account_token;
}
/**
* Set Headers.
*
* @access public
* @return void
*/
public function set_headers() {
$this->args['headers'] = array(
'Accept' => 'application/json',
'Content-Type' => 'application/json',
);
if ( ! empty( $this->account_token ) ) {
$this->args['headers']['X-Api-Token'] = $this->account_token;
}
}
/**
* Create a record.
*
* @access public
* @param string $email Email.
* @param string $domain Domain.
*/
public function create_record( $email, $domain ) {
$args = array(
'method' => 'POST',
'body' => array(
'email' => $email,
'domain' => $domain,
),
);
return $this->build_request( $args )->fetch( '/records' );
}
/**
* Get records associated with given account key.
*
* @return [type] [description]
*/
public function get_record() {
return $this->build_request()->fetch( '/records/my' );
}
/**
* Get DNS snippets for this account.
*
* @return [type] [description]
*/
public function get_dns_snippet() {
return $this->build_request()->fetch( '/records/my/dns' );
}
/**
* Verify DNS records.
*
* @return [type] [description]
*/
public function verify_dns() {
$args = array(
'method' => 'POST',
);
return $this->build_request( $args )->fetch( '/records/my/verify' );
}
/**
* Delete my records.
*
* @return [type] [description]
*/
public function delete_record() {
$args = array(
'method' => 'DELETE',
);
return $this->build_request( $args )->fetch( '/records/my' );
}
/**
* List dmarc reports (with optional parameters to specify search).
*
* @param string $from_date From Date.
* @param string $to_date To Date.
* @param string $limit Limit.
* @param string $after After.
*/
public function list_dmarc_reports( $from_date = '', $to_date = '', $limit = '', $after = '' ) {
$request = '';
if ( '' === $from_date && '' === $to_date && '' === $limit && '' === $after ) {
$request = '/records/my/reports';
} else {
$args = array(
'from_date' => $from_date,
'to_date' => $to_date,
'limit' => $limit,
'after' => $after,
);
$request = '/records/my/reports?' . http_build_query( array_filter( $args ) );
}
return $request;
}
/**
* Get DMARC Report.
*
* @access public
* @param mixed $dmarc_report_id DMARC Report ID.
*/
public function get_dmarc_report( $dmarc_report_id ) {
return $this->build_request()->fetch( '/records/my/reports' . $dmarc_report_id );
}
/**
* Recover API Token.
*
* @access public
* @param mixed $owner Owner.
*/
public function recover_api_token( $owner ) {
$args = array(
'method' => 'POST',
'body' => array(
'owner' => $owner,
),
);
return $this->build_request( $args )->fetch( '/tokens/recover' );
}
/**
* Rotate API Token..
*
* @access public
*/
public function rotate_api_token() {
$args = array(
'method' => 'POST',
);
return $this->build_request( $args )->fetch( '/records/my/token/rotate' );
}
}
}