summaryrefslogtreecommitdiff
path: root/Postman/notifications/PostmanPushoverNotify.php
blob: 1c483b345ff50738cdb349fa4eba34e93ce7b7fb (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
<?php

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 ) );
        }
    }
}