Code Duplication    Length = 23-27 lines in 15 locations

src/Traits/SmartLoad.php 8 locations

@@ 26-51 (lines=26) @@
23
     *
24
     * @return array
25
     */
26
    public function balance($dealerMsisdn)
27
    {
28
        try {
29
            $response = $this->get(
30
                sprintf(
31
                    '/webservice/smartload/balance/%s',
32
                    $dealerMsisdn
33
                ),
34
                [
35
                    'headers' => [
36
                        'Authorization' => $this->bearerOrBasic(),
37
                    ],
38
                ]
39
            );
40
41
            return [
42
                'status'    => 'ok',
43
                'http_code' => $response->getStatusCode(),
44
                'body'      => (string) $response->getBody(),
45
            ];
46
        } catch (\GuzzleHttp\Exception\ClientException $e) {
47
            return $this->clientError($e);
48
        } catch (\GuzzleHttp\Exception\ServerException $e) {
49
            return $this->parseError($e);
50
        }
51
    }
52
53
    /**
54
     * Authenticate and request to cancel a previous recharge request. Will only
@@ 64-90 (lines=27) @@
61
     *
62
     * @return array
63
     */
64
    public function cancelRecharge($dealerMsisdn, $clientReference)
65
    {
66
        try {
67
            $response = $this->delete(
68
                sprintf(
69
                    '/webservice/smartload/recharges/%s/%s',
70
                    $dealerMsisdn,
71
                    $clientReference
72
                ),
73
                [
74
                    'headers' => [
75
                        'Authorization' => $this->bearerOrBasic(),
76
                    ],
77
                ]
78
            );
79
80
            return [
81
                'status'    => 'ok',
82
                'http_code' => $response->getStatusCode(),
83
                'body'      => (string) $response->getBody(),
84
            ];
85
        } catch (\GuzzleHttp\Exception\ClientException $e) {
86
            return $this->clientError($e);
87
        } catch (\GuzzleHttp\Exception\ServerException $e) {
88
            return $this->parseError($e);
89
        }
90
    }
91
92
    /**
93
     * Authenticate and request period based cashup reports.
@@ 141-166 (lines=26) @@
138
     *
139
     * @return array
140
     */
141
    public function cashupToday($dealerMsisdn)
142
    {
143
        try {
144
            $response = $this->get(
145
                sprintf(
146
                    '/webservice/smartload/cashup/%s',
147
                    $dealerMsisdn
148
                ),
149
                [
150
                    'headers' => [
151
                        'Authorization' => $this->bearerOrBasic(),
152
                    ],
153
                ]
154
            );
155
156
            return [
157
                'status'    => 'ok',
158
                'http_code' => $response->getStatusCode(),
159
                'body'      => (string) $response->getBody(),
160
            ];
161
        } catch (\GuzzleHttp\Exception\ClientException $e) {
162
            return $this->clientError($e);
163
        } catch (\GuzzleHttp\Exception\ServerException $e) {
164
            return $this->parseError($e);
165
        }
166
    }
167
168
    /**
169
     * Authenticate and request to transfer funds from one Smartload account to another.
@@ 219-244 (lines=26) @@
216
     *
217
     * @return array
218
     */
219
    public function network($networkId)
220
    {
221
        try {
222
            $response = $this->get(
223
                sprintf(
224
                    '/webservice/smartload/networks/%d',
225
                    $networkId
226
                ),
227
                [
228
                    'headers' => [
229
                        'Authorization' => $this->bearerOrBasic(),
230
                    ],
231
                ]
232
            );
233
234
            return [
235
                'status'    => 'ok',
236
                'http_code' => $response->getStatusCode(),
237
                'body'      => (string) $response->getBody(),
238
            ];
239
        } catch (\GuzzleHttp\Exception\ClientException $e) {
240
            return $this->clientError($e);
241
        } catch (\GuzzleHttp\Exception\ServerException $e) {
242
            return $this->parseError($e);
243
        }
244
    }
245
246
    /**
247
     * Authenticate and retrieves a list of all available networks.
@@ 253-275 (lines=23) @@
250
     *
251
     * @return array
252
     */
253
    public function networks()
254
    {
255
        try {
256
            $response = $this->get(
257
                '/webservice/smartload/networks',
258
                [
259
                    'headers' => [
260
                        'Authorization' => $this->bearerOrBasic(),
261
                    ],
262
                ]
263
            );
264
265
            return [
266
                'status'    => 'ok',
267
                'http_code' => $response->getStatusCode(),
268
                'body'      => (string) $response->getBody(),
269
            ];
270
        } catch (\GuzzleHttp\Exception\ClientException $e) {
271
            return $this->clientError($e);
272
        } catch (\GuzzleHttp\Exception\ServerException $e) {
273
            return $this->parseError($e);
274
        }
275
    }
276
277
    /**
278
     * Authenticate and recharge prevend request.
@@ 332-357 (lines=26) @@
329
     *
330
     * @return array
331
     */
332
    public function products($productId)
333
    {
334
        try {
335
            $response = $this->get(
336
                sprintf(
337
                    '/webservice/smartload/products/%d',
338
                    $productId
339
                ),
340
                [
341
                    'headers' => [
342
                        'Authorization' => $this->bearerOrBasic(),
343
                    ],
344
                ]
345
            );
346
347
            return [
348
                'status'    => 'ok',
349
                'http_code' => $response->getStatusCode(),
350
                'body'      => (string) $response->getBody(),
351
            ];
352
        } catch (\GuzzleHttp\Exception\ClientException $e) {
353
            return $this->clientError($e);
354
        } catch (\GuzzleHttp\Exception\ServerException $e) {
355
            return $this->parseError($e);
356
        }
357
    }
358
359
    /**
360
     * Authenticate and recharge request.
@@ 414-439 (lines=26) @@
411
     *
412
     * @return array
413
     */
414
    public function registered($dealerMsisdn)
415
    {
416
        try {
417
            $response = $this->get(
418
                sprintf(
419
                    '/webservice/smartload/registered/%s',
420
                    $dealerMsisdn
421
                ),
422
                [
423
                    'headers' => [
424
                        'Authorization' => $this->bearerOrBasic(),
425
                    ],
426
                ]
427
            );
428
429
            return [
430
                'status'    => 'ok',
431
                'http_code' => $response->getStatusCode(),
432
                'body'      => (string) $response->getBody(),
433
            ];
434
        } catch (\GuzzleHttp\Exception\ClientException $e) {
435
            return $this->clientError($e);
436
        } catch (\GuzzleHttp\Exception\ServerException $e) {
437
            return $this->parseError($e);
438
        }
439
    }
440
441
    /**
442
     * Authenticate and retrieves the details of the transaction that was performed
@@ 448-474 (lines=27) @@
445
     * @param string $dealerMsisdn
446
     * @param string $clientReference
447
     */
448
    public function transaction($dealerMsisdn, $clientReference)
449
    {
450
        try {
451
            $response = $this->get(
452
                sprintf(
453
                    '/webservice/smartload/recharges/%s/%s',
454
                    $dealerMsisdn,
455
                    $clientReference
456
                ),
457
                [
458
                    'headers' => [
459
                        'Authorization' => $this->bearerOrBasic(),
460
                    ],
461
                ]
462
            );
463
464
            return [
465
                'status'    => 'ok',
466
                'http_code' => $response->getStatusCode(),
467
                'body'      => (string) $response->getBody(),
468
            ];
469
        } catch (\GuzzleHttp\Exception\ClientException $e) {
470
            return $this->clientError($e);
471
        } catch (\GuzzleHttp\Exception\ServerException $e) {
472
            return $this->parseError($e);
473
        }
474
    }
475
}
476

src/Traits/SmartRica.php 1 location

@@ 56-78 (lines=23) @@
53
        }
54
    }
55
56
    public function registrations()
57
    {
58
        try {
59
            $response = $this->post(
60
                '/webservice/smartrica/registrations',
61
                [
62
                    'headers' => [
63
                        'Authorization' => $this->bearerOrBasic(),
64
                    ],
65
                ]
66
            );
67
68
            return [
69
                'status'    => 'ok',
70
                'http_code' => $response->getStatusCode(),
71
                'body'      => (string) $response->getBody(),
72
            ];
73
        } catch (\GuzzleHttp\Exception\ClientException $e) {
74
            return $this->clientError($e);
75
        } catch (\GuzzleHttp\Exception\ServerException $e) {
76
            return $this->parseError($e);
77
        }
78
    }
79
}
80

src/Client.php 6 locations

@@ 113-135 (lines=23) @@
110
     *
111
     * @return array
112
     */
113
    public function auth()
114
    {
115
        try {
116
            $response = $this->post(
117
                '/webservice/auth',
118
                [
119
                    'headers' => [
120
                        'Authorization' => $this->bearerOrBasic(),
121
                    ],
122
                ]
123
            );
124
125
            return [
126
                'status'    => 'ok',
127
                'http_code' => $response->getStatusCode(),
128
                'body'      => (string) $response->getBody(),
129
            ];
130
        } catch (\GuzzleHttp\Exception\ClientException $e) {
131
            return $this->clientError($e);
132
        } catch (\GuzzleHttp\Exception\ServerException $e) {
133
            return $this->parseError($e);
134
        }
135
    }
136
137
    /**
138
     * Authenticate and invalidates all the user allocated tokens.
@@ 144-166 (lines=23) @@
141
     *
142
     * @return array
143
     */
144
    public function authDelete()
145
    {
146
        try {
147
            $response = $this->delete(
148
                '/webservice/auth',
149
                [
150
                    'headers' => [
151
                        'Authorization' => $this->bearerOrBasic(),
152
                    ],
153
                ]
154
            );
155
156
            return [
157
                'status'    => 'ok',
158
                'http_code' => $response->getStatusCode(),
159
                'body'      => (string) $response->getBody(),
160
            ];
161
        } catch (\GuzzleHttp\Exception\ClientException $e) {
162
            return $this->clientError($e);
163
        } catch (\GuzzleHttp\Exception\ServerException $e) {
164
            return $this->parseError($e);
165
        }
166
    }
167
168
    /**
169
     * Authenticate and invalidates all the user allocated tokens.
@@ 175-197 (lines=23) @@
172
     *
173
     * @return array
174
     */
175
    public function authFlush()
176
    {
177
        try {
178
            $response = $this->delete(
179
                '/webservice/auth/token',
180
                [
181
                    'headers' => [
182
                        'Authorization' => $this->bearerOrBasic(),
183
                    ],
184
                ]
185
            );
186
187
            return [
188
                'status'    => 'ok',
189
                'http_code' => $response->getStatusCode(),
190
                'body'      => (string) $response->getBody(),
191
            ];
192
        } catch (\GuzzleHttp\Exception\ClientException $e) {
193
            return $this->clientError($e);
194
        } catch (\GuzzleHttp\Exception\ServerException $e) {
195
            return $this->parseError($e);
196
        }
197
    }
198
199
    /**
200
     * Authenticate and gets the number of available session tokens.
@@ 206-228 (lines=23) @@
203
     *
204
     * @return array
205
     */
206
    public function authToken()
207
    {
208
        try {
209
            $response = $this->get(
210
                '/webservice/auth/token',
211
                [
212
                    'headers' => [
213
                        'Authorization' => $this->bearerOrBasic(),
214
                    ],
215
                ]
216
            );
217
218
            return [
219
                'status'    => 'ok',
220
                'http_code' => $response->getStatusCode(),
221
                'body'      => (string) $response->getBody(),
222
            ];
223
        } catch (\GuzzleHttp\Exception\ClientException $e) {
224
            return $this->clientError($e);
225
        } catch (\GuzzleHttp\Exception\ServerException $e) {
226
            return $this->parseError($e);
227
        }
228
    }
229
230
    /**
231
     * Gets the current connection status to the various mobile networks.
@@ 237-259 (lines=23) @@
234
     *
235
     * @return array
236
     */
237
    public function health()
238
    {
239
        try {
240
            $response = $this->get(
241
                '/webservice/utilities/health',
242
                [
243
                    'headers' => [
244
                        'Authorization' => $this->bearerOrBasic(),
245
                    ],
246
                ]
247
            );
248
249
            return [
250
                'status'    => 'ok',
251
                'http_code' => $response->getStatusCode(),
252
                'body'      => (string) $response->getBody(),
253
            ];
254
        } catch (\GuzzleHttp\Exception\ClientException $e) {
255
            return $this->clientError($e);
256
        } catch (\GuzzleHttp\Exception\ServerException $e) {
257
            return $this->parseError($e);
258
        }
259
    }
260
261
    /**
262
     * Gets the mobile network on which the SIM is connected.
@@ 270-295 (lines=26) @@
267
     *
268
     * @return array
269
     */
270
    public function simnetwork($msisdn)
271
    {
272
        try {
273
            $response = $this->get(
274
                sprintf(
275
                    '/webservice/utilities/simnetwork/%d',
276
                    $msisdn
277
                ),
278
                [
279
                    'headers' => [
280
                        'Authorization' => $this->bearerOrBasic(),
281
                    ],
282
                ]
283
            );
284
285
            return [
286
                'status'    => 'ok',
287
                'http_code' => $response->getStatusCode(),
288
                'body'      => (string) $response->getBody(),
289
            ];
290
        } catch (\GuzzleHttp\Exception\ClientException $e) {
291
            return $this->clientError($e);
292
        } catch (\GuzzleHttp\Exception\ServerException $e) {
293
            return $this->parseError($e);
294
        }
295
    }
296
297
    /**
298
     * Test SmartCall is responding.