1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* SmartCall Restful API (v3) HTTP Client. |
4
|
|
|
* |
5
|
|
|
* PLEASE NOTE: The interface is very fluid while the intial integration |
6
|
|
|
* is taking place. It will be refactored in the near future. |
7
|
|
|
* |
8
|
|
|
* @author Jacques Marneweck <[email protected]> |
9
|
|
|
* @copyright 2017-2019 Jacques Marneweck. All rights strictly reserved. |
10
|
|
|
* @license MIT |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Jacques\Smartcall\HttpClient\Traits; |
14
|
|
|
|
15
|
|
|
trait Utilities |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Gets the current connection status to the various mobile networks. |
19
|
|
|
* |
20
|
|
|
* @throws Exception |
21
|
|
|
* |
22
|
|
|
* @return array |
23
|
|
|
*/ |
24
|
3 |
View Code Duplication |
public function health() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
try { |
27
|
3 |
|
$response = $this->get( |
|
|
|
|
28
|
3 |
|
'/webservice/utilities/health', |
29
|
|
|
[ |
30
|
|
|
'headers' => [ |
31
|
3 |
|
'Authorization' => $this->bearerOrBasic(), |
|
|
|
|
32
|
|
|
], |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
return [ |
37
|
1 |
|
'status' => 'ok', |
38
|
1 |
|
'http_code' => $response->getStatusCode(), |
39
|
1 |
|
'body' => (string) $response->getBody(), |
40
|
|
|
]; |
41
|
2 |
|
} catch (\GuzzleHttp\Exception\ClientException $e) { |
|
|
|
|
42
|
2 |
|
return $this->clientError($e); |
|
|
|
|
43
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
44
|
|
|
return $this->parseError($e); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Gets the mobile network on which the SIM is connected. |
50
|
|
|
* |
51
|
|
|
* @param string $msisdn |
52
|
|
|
* |
53
|
|
|
* @throws Exception |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
4 |
View Code Duplication |
public function simnetwork($msisdn) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
try { |
60
|
4 |
|
$response = $this->get( |
|
|
|
|
61
|
4 |
|
sprintf( |
62
|
4 |
|
'/webservice/utilities/simnetwork/%d', |
63
|
4 |
|
$msisdn |
64
|
|
|
), |
65
|
|
|
[ |
66
|
|
|
'headers' => [ |
67
|
4 |
|
'Authorization' => $this->bearerOrBasic(), |
|
|
|
|
68
|
|
|
], |
69
|
|
|
] |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
return [ |
73
|
2 |
|
'status' => 'ok', |
74
|
2 |
|
'http_code' => $response->getStatusCode(), |
75
|
2 |
|
'body' => (string) $response->getBody(), |
76
|
|
|
]; |
77
|
2 |
|
} catch (\GuzzleHttp\Exception\ClientException $e) { |
|
|
|
|
78
|
2 |
|
return $this->clientError($e); |
|
|
|
|
79
|
|
|
} catch (\GuzzleHttp\Exception\ServerException $e) { |
|
|
|
|
80
|
|
|
return $this->parseError($e); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
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.