Completed
Push — master ( a8a226...edd472 )
by Tomas
01:14
created

Apps::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OneSignal;
4
5
use OneSignal\Resolver\ResolverFactory;
6
7
class Apps
8
{
9
    protected $api;
10
11
    private $resolverFactory;
12
13
    public function __construct(OneSignal $api, ResolverFactory $resolverFactory)
14
    {
15
        $this->api = $api;
16
        $this->resolverFactory = $resolverFactory;
17
    }
18
19
    /**
20
     * Get information about application with provided ID.
21
     *
22
     * User authentication key must be set.
23
     *
24
     * @param string $id ID of your application
25
     *
26
     * @return array
27
     */
28
    public function getOne($id)
29
    {
30
        return $this->api->request('GET', '/apps/'.$id, [
31
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
32
        ]);
33
    }
34
35
    /**
36
     * Get information about all your created applications.
37
     *
38
     * User authentication key must be set.
39
     *
40
     * @return array
41
     */
42
    public function getAll()
43
    {
44
        return $this->api->request('GET', '/apps', [
45
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
46
        ]);
47
    }
48
49
    /**
50
     * Create a new application with provided data.
51
     *
52
     * User authentication key must be set.
53
     *
54
     * @param array $data Application data
55
     *
56
     * @return array
57
     */
58 View Code Duplication
    public function add(array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
61
62
        return $this->api->request('POST', '/apps', [
63
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
64
        ], json_encode($data));
65
    }
66
67
    /**
68
     * Update application with provided data.
69
     *
70
     * User authentication key must be set.
71
     *
72
     * @param string $id   ID of your application
73
     * @param array  $data New application data
74
     *
75
     * @return array
76
     */
77 View Code Duplication
    public function update($id, array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $data = $this->resolverFactory->createAppResolver()->resolve($data);
80
81
        return $this->api->request('PUT', '/apps/'.$id, [
82
            'Authorization' => 'Basic '.$this->api->getConfig()->getUserAuthKey(),
83
        ], json_encode($data));
84
    }
85
86
    /**
87
     * Create a new segment for application with provided data.
88
     *
89
     * @param string $appId ID of your application
90
     * @param array  $data  Segment Data
91
     *
92
     * @return array
93
     */
94 View Code Duplication
    public function createSegment($appId, array $data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $data = $this->resolverFactory->createSegmentResolver()->resolve($data);
97
98
        return $this->api->request('POST', '/apps/'.$appId.'/segments', [
99
            'Authorization' => 'Basic '.$this->api->getConfig()->getApplicationAuthKey(),
100
        ], json_encode($data));
101
    }
102
103
    /**
104
     * Delete existing segment from your application.
105
     *
106
     * Application auth key must be set.
107
     *
108
     * @param string $appId     Application ID
109
     * @param string $segmentId Segment ID
110
     *
111
     * @return array
112
     */
113
    public function deleteSegment($appId, $segmentId)
114
    {
115
        return $this->api->request('DELETE', '/apps/'.$appId.'/segments/'.$segmentId, [
116
            'Authorization' => 'Basic '.$this->api->getConfig()->getApplicationAuthKey(),
117
        ]);
118
    }
119
}
120