Completed
Push — master ( fe47f8...2aa7aa )
by Brian
09:43
created

src/wormling/phparia/Api/Applications.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * Copyright 2014 Brian Smith <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace phparia\Api;
20
21
use GuzzleHttp\Exception\RequestException;
22
use phparia\Client\AriClientAware;
23
use phparia\Exception\ConflictException;
24
use phparia\Exception\InvalidParameterException;
25
use phparia\Exception\NotFoundException;
26
use phparia\Exception\UnprocessableEntityException;
27
use phparia\Resources\Application;
28
29
/**
30
 * Applications API
31
 *
32
 * @author Brian Smith <[email protected]>
33
 */
34
class Applications extends AriClientAware
35
{
36
    /**
37
     * List all getApplications.
38
     *
39
     * @return Application[]
40
     */
41
    public function getApplications()
42
    {
43
        $uri = 'applications';
44
        $response = $this->client->getEndpoint()->get($uri);
45 1
46
        $applications = [];
47 1
        foreach (\GuzzleHttp\json_decode($response->getBody()) as $application) {
48 1
            $applications[] = new Application($this->client, $application);
49
        }
50 1
51 1
        return $applications;
52 1
    }
53 1
54
    /**
55 1
     * Get details of an application.
56
     *
57
     * @param $applicationName
58
     * @return Application
59
     * @throws NotFoundException
60
     */
61 View Code Duplication
    public function getApplication($applicationName)
0 ignored issues
show
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...
62
    {
63
        $uri = "applications/$applicationName";
64
        try {
65 2
            $response = $this->client->getEndpoint()->get($uri);
66
        } catch (RequestException $e) {
67 2
            $this->processRequestException($e);
68
        }
69 2
70 2
        return new Application($this->client, \GuzzleHttp\json_decode($response->getBody()));
71 1
    }
72
73
    /**
74 1
     * Subscribe an application to a event source. Returns the state of the application after the subscriptions have changed
75
     *
76
     * @param string $applicationName Application's name
77
     * @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}.  Allows comma separated values.
78
     * @return Application
79
     * @throws InvalidParameterException
80
     * @throws NotFoundException
81
     * @throws UnprocessableEntityException Event source does not exist.
82
     */
83
    public function subscribe($applicationName, $eventSource)
84
    {
85
        $uri = "applications/$applicationName/subscription";
86
        try {
87 4
            $response = $this->client->getEndpoint()->post($uri, [
88
                'form_params' => [
89 4
                    'eventSource' => $eventSource,
90
                ]
91 4
            ]);
92 4
        } catch (RequestException $e) {
93 4
            $this->processRequestException($e);
94 4
        }
95 1
96 2
        return new Application($this->client, \GuzzleHttp\json_decode($response->getBody()));
97 1
    }
98 1
99 1
    /**
100
     * Unsubscribe an application from an event source. Returns the state of the application after the subscriptions have changed
101
     *
102 1
     * @param string $applicationName Application's name
103
     * @param string $eventSource (required) URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}  Allows comma separated values.
104
     * @return Application
105
     * @throws ConflictException
106
     * @throws InvalidParameterException
107
     * @throws NotFoundException
108
     * @throws UnprocessableEntityException
109
     */
110 View Code Duplication
    public function unsubscribe($applicationName, $eventSource)
0 ignored issues
show
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...
111
    {
112
        $uri = "applications/$applicationName/subscription?eventSource=".\GuzzleHttp\json_encode($eventSource);
113
        try {
114
            $response = $this->client->getEndpoint()->delete($uri);
115
        } catch (RequestException $e) {
116 4
            $this->processRequestException($e);
117
        }
118 4
119
        return new Application($this->client, \GuzzleHttp\json_decode($response->getBody()));
120 4
    }
121
}
122