summaryrefslogtreecommitdiff
path: root/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php
blob: c1f2661e21d20039dd5dd630c113c95790ab2b8a (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
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
class PostmanPushoverNotify implements Postman_Notify {

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

        $api_url = "https://api.pushover.net/1/messages.json";
        $app_token = $options->getPushoverToken();
        $user_key = $options->getPushoverUser();

        $args = array(
            'body' => array(
                "token" => $app_token,
                "user" => $user_key,
                "message" => $message,
            )
        );

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

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

        $body = json_decode( wp_remote_retrieve_body( $result ), true );
        if ( $body['status'] == 0 ) {
            error_log( __CLASS__ . ': ' . print_r( $body, true ) );
        }
    }
}