-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconstellix-api.php
107 lines (90 loc) · 2.84 KB
/
constellix-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
<?php
/**
* Constellix API WordPress Wrapper
*
* See readme for setup and coding examples.
*
* @author Austin Ginder <[email protected]>
*/
function constellix_api_get( $command ) {
$timestamp = round( microtime( true ) * 1000 );
$hmac = base64_encode( hash_hmac( 'sha1', $timestamp, CONSTELLIX_SECRET_KEY, true ) );
$args = [
'timeout' => 120,
'headers' => [
'Content-type' => 'application/json',
'x-cnsdns-apiKey' => CONSTELLIX_API_KEY,
'x-cnsdns-hmac' => $hmac,
'x-cnsdns-requestDate' => $timestamp,
],
];
$remote = wp_remote_get( "https://api.dns.constellix.com/v1/$command/", $args );
if ( is_wp_error( $remote ) ) {
return $remote->get_error_message();
} else {
return json_decode( $remote['body'] );
}
}
function constellix_api_post( $command, $post ) {
$timestamp = round( microtime( true ) * 1000 );
$hmac = base64_encode( hash_hmac( 'sha1', $timestamp, CONSTELLIX_SECRET_KEY, true ) );
$args = [
'timeout' => 120,
'headers' => [
'Content-type' => 'application/json',
'x-cnsdns-apiKey' => CONSTELLIX_API_KEY,
'x-cnsdns-hmac' => $hmac,
'x-cnsdns-requestDate' => $timestamp,
],
'body' => json_encode( $post ),
'method' => 'POST',
];
$remote = wp_remote_post( "https://api.dns.constellix.com/v1/$command/", $args );
if ( is_wp_error( $remote ) ) {
return $remote->get_error_message();
} else {
return json_decode( $remote['body'] );
}
}
function constellix_api_put( $command, $post ) {
$timestamp = round( microtime( true ) * 1000 );
$hmac = base64_encode( hash_hmac( 'sha1', $timestamp, CONSTELLIX_SECRET_KEY, true ) );
$args = [
'timeout' => 120,
'headers' => [
'Content-type' => 'application/json',
'x-cnsdns-apiKey' => CONSTELLIX_API_KEY,
'x-cnsdns-hmac' => $hmac,
'x-cnsdns-requestDate' => $timestamp,
],
'body' => json_encode( $post ),
'method' => 'PUT',
];
$remote = wp_remote_post( "https://api.dns.constellix.com/v1/$command/", $args );
if ( is_wp_error( $remote ) ) {
return $remote->get_error_message();
} else {
return json_decode( $remote['body'] );
}
}
function constellix_api_delete( $command ) {
$timestamp = round( microtime( true ) * 1000 );
$hmac = base64_encode( hash_hmac( 'sha1', $timestamp, CONSTELLIX_SECRET_KEY, true ) );
$args = [
'timeout' => 120,
'headers' => [
'Content-type' => 'application/json',
'x-cnsdns-apiKey' => CONSTELLIX_API_KEY,
'x-cnsdns-hmac' => $hmac,
'x-cnsdns-requestDate' => $timestamp,
],
'body' => json_encode( $post ),
'method' => 'DELETE',
];
$remote = wp_remote_post( "https://api.dns.constellix.com/v1/$command/", $args );
if ( is_wp_error( $remote ) ) {
return $remote->get_error_message();
} else {
return json_decode( $remote['body'] );
}
}