summaryrefslogtreecommitdiff
path: root/Postman/notifications/PostmanSlackNotify.php
blob: 5b6fae3fb87db518f843f390b528229a4a0e7875 (plain)
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
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
class PostmanSlackNotify implements Postman_Notify {

    public function send_message($message)
    {
        $options = PostmanOptions::getInstance();

        $api_url = $options->getSlackToken();

        $headers = array(
            'content-type' => 'application/json'
        );

        $body = array(
            'text' => $message
        );

        $args = array(
            'headers' => $headers,
            'body' => json_encode($body)
        );

        $result = wp_remote_post( $api_url, $args );

        if ( is_wp_error($result) ) {
            error_log( __CLASS__ . ': ' . $result->get_error_message() );
        }

        $code = wp_remote_retrieve_response_code( $result );
        $message = wp_remote_retrieve_response_message( $result );

        if ( $code != 200 && $message !== 'OK' ) {
            error_log( __CLASS__ . ': ' . $message );
        }
    }
}