summaryrefslogtreecommitdiff
path: root/Postman/notifications/PostmanPushoverNotify.php
blob: 14ef7d2ea6a8167338771f2b4d9d11ee07e65f7e (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 = PostmanOptions::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 ) );
        }
    }
}