Glpi\Api\Rest\EndPointHandler: lines coverage

96% of 26

Lines
Method Lines Line %
Glpi\Api\Rest\EndPointHandler::__construct() 2 100%
Glpi\Api\Rest\EndPointHandler::getClient() 1 0%
Glpi\Api\Rest\EndPointHandler::getMyProfiles() 3 100%
Glpi\Api\Rest\EndPointHandler::getActiveProfile() 3 100%
Glpi\Api\Rest\EndPointHandler::changeActiveProfile() 4 100%
Glpi\Api\Rest\EndPointHandler::getMyEntities() 4 100%
Glpi\Api\Rest\EndPointHandler::getActiveEntities() 3 100%
Glpi\Api\Rest\EndPointHandler::changeActiveEntities() 6 100%
#
1
<?php
2
/**
3
 * --------------------------------------------------------------------
4
 *
5
 * LICENSE
6
 *
7
 * This file is part of the GLPI API Client Library for PHP,
8
 * a subproject of GLPI. GLPI is a free IT Asset Management.
9
 *
10
 * GLPI is free software: you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 3
13
 * of the License, or (at your option) any later version.
14
 *
15
 * GLPI is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 * --------------------------------------------------------------------
20
 * @author    Domingo Oropeza - <doropeza@teclib.com>
21
 * @copyright (C) 2017 Teclib' and contributors.
22
 * @license   GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
23
 * @link      https://github.com/glpi-project/php-library-glpi
24
 * @link      http://www.glpi-project.org/
25
 * --------------------------------------------------------------------
26
 */
27

                    
28
namespace Glpi\Api\Rest;
29

                    
30

                    
31
/**
32
 * Class EndPointHandler
33
 * @package Glpi\Api\Rest
34
 */
35
class EndPointHandler {
36

                    
37
   /**
38
    * @var Client
39
    */
40
   protected $client;
41

                    
42
   /**
43
    * EndPointHandler constructor.
44
    * @param Client $client
45
    */
46
   public function __construct(Client $client) {100%
47
      $this->client = $client;
48
   }
49

                    
50
   /**
51
    * @return Client
52
    */
53
   public function getClient() {0%
54
      return $this->client;
55
   }
56

                    
57
   /**
58
    * Return all the profiles associated to logged user.
59
    * @return array
60
    */
61
   public function getMyProfiles() {100%
62
      $response = $this->client->request('get', 'getMyProfiles');
63
      return [
64
         'statusCode' => $response->getStatusCode(),
65
         'body' => $response->getBody()->getContents(),
66
      ];
67
   }
68

                    
69
   /**
70
    * Return the current active profile.
71
    * @return array
72
    */
73
   public function getActiveProfile() {100%
74
      $response = $this->client->request('get', 'getActiveProfile');
75
      return [
76
         'statusCode' => $response->getStatusCode(),
77
         'body' => $response->getBody()->getContents(),
78
      ];
79
   }
80

                    
81
   /**
82
    * Change active profile to the profiles_id one.
83
    * @see getMyProfiles endpoint for possible profiles.
84
    *
85
    * @param integer $profiles_id
86
    * @return array
87
    */
88
   public function changeActiveProfile($profiles_id) {100%
89
      $options['body'] = json_encode(['profiles_id' => $profiles_id]);
90
      $response = $this->client->request('post', 'changeActiveProfile', $options);
91
      return [
92
         'statusCode' => $response->getStatusCode(),
93
         'body' => $response->getBody()->getContents(),
94
      ];
95
   }
96

                    
97
   /**
98
    * Return all the possible entities of the current logged user (and for current active profile).
99
    * @param array $queryString
100
    * @return array
101
    */
102
   public function getMyEntities(array $queryString = []) {100%
103
      $options['query'] = $queryString;
104
      $response = $this->client->request('get', 'getMyEntities', $options);
105
      return [
106
         'statusCode' => $response->getStatusCode(),
107
         'body' => $response->getBody()->getContents(),
108
      ];
109
   }
110

                    
111
   /**
112
    * Return active entities of current logged user.
113
    * @return array
114
    */
115
   public function getActiveEntities() {100%
116
      $response = $this->client->request('get', 'getActiveEntities');
117
      return [
118
         'statusCode' => $response->getStatusCode(),
119
         'body' => $response->getBody()->getContents(),
120
      ];
121
   }
122

                    
123
   /**
124
    * Change active entity to the entities_id one.
125
    * @see getMyEntities endpoint for possible entities.
126
    *
127
    * @param array $parameters
128
    * @return array
129
    */
130
   public function changeActiveEntities(array $parameters = []) {100%
131
      $options = [];
132
      if ($parameters) {
133
         $options['body'] = json_encode($parameters);
134
      }
135
      $response = $this->client->request('post', 'changeActiveEntities', $options);
136
      return [
137
         'statusCode' => $response->getStatusCode(),
138
         'body' => $response->getBody()->getContents(),
139
      ];
140
   }
141

                    
142
}
Powered by atoum
Back to top