Join::push()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 20
rs 9.9666
1
<?php
2
namespace GJClasses;
3
4
class Join
5
{
6
    public function push($api_key, $subject, $content, $url)
7
    {
8
        $push = new \GJClasses\Push('join');
9
        $type = $push->getPushType($url);
10
11
        if ($type == 'note') {
12
13
            $message = $this->pushNote($api_key, $subject, $content);
14
15
        } elseif ($type == 'url') {
16
17
            $message = $this->pushUrl($api_key, $subject, $url);
18
19
        } else {
20
21
            $message = 'Push type incorrect or not specified';
22
23
        }
24
25
        return $message;
26
    }
27
28
    public function getBaseUrl()
29
    {
30
        return 'https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush?';
31
    }
32
33
    public function pushNote($api_key, $subject, $content)
34
    {
35
        $full_url = $this->getBaseUrl() . 'apikey=' . $api_key . '&deviceId=group.all&title=' . urlencode($subject) . '&url=' . urlencode($content);
36
        $handle = curl_init($full_url);
37
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
38
        curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
39
        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
40
        curl_exec($handle);
41
        curl_close($handle);
42
        return 'Note Sent';
43
    }
44
45
    public function pushUrl($api_key, $subject, $url)
46
    {
47
        $full_url = $this->getBaseUrl() . 'apikey=' . $api_key . '&deviceId=group.all&title=' . urlencode($subject) . '&url=' . urlencode($url);
48
        $handle = curl_init($full_url);
49
        curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
50
        curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
51
        curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
52
        curl_exec($handle);
53
        curl_close($handle);
54
        return 'URL Sent';
55
    }
56
}
57