Code Duplication    Length = 23-27 lines in 14 locations

src/Client.php 5 locations

@@ 107-129 (lines=23) @@
104
     *
105
     * @return array
106
     */
107
    public function auth()
108
    {
109
        try {
110
            $response = $this->post(
111
                '/webservice/auth',
112
                [
113
                    'headers' => [
114
                        'Authorization' => $this->bearerOrBasic(),
115
                    ],
116
                ]
117
            );
118
119
            return [
120
                'status'    => 'ok',
121
                'http_code' => $response->getStatusCode(),
122
                'body'      => (string) $response->getBody(),
123
            ];
124
        } catch (\GuzzleHttp\Exception\ClientException $e) {
125
            return $this->clientError($e);
126
        } catch (\GuzzleHttp\Exception\ServerException $e) {
127
            return $this->parseError($e);
128
        }
129
    }
130
131
    /**
132
     * Authenticate and invalidates all the user allocated tokens.
@@ 138-160 (lines=23) @@
135
     *
136
     * @return array
137
     */
138
    public function authDelete()
139
    {
140
        try {
141
            $response = $this->delete(
142
                '/webservice/auth',
143
                [
144
                    'headers' => [
145
                        'Authorization' => $this->bearerOrBasic(),
146
                    ],
147
                ]
148
            );
149
150
            return [
151
                'status'    => 'ok',
152
                'http_code' => $response->getStatusCode(),
153
                'body'      => (string) $response->getBody(),
154
            ];
155
        } catch (\GuzzleHttp\Exception\ClientException $e) {
156
            return $this->clientError($e);
157
        } catch (\GuzzleHttp\Exception\ServerException $e) {
158
            return $this->parseError($e);
159
        }
160
    }
161
162
    /**
163
     * Authenticate and invalidates all the user allocated tokens.
@@ 169-191 (lines=23) @@
166
     *
167
     * @return array
168
     */
169
    public function authFlush()
170
    {
171
        try {
172
            $response = $this->delete(
173
                '/webservice/auth/token',
174
                [
175
                    'headers' => [
176
                        'Authorization' => $this->bearerOrBasic(),
177
                    ],
178
                ]
179
            );
180
181
            return [
182
                'status'    => 'ok',
183
                'http_code' => $response->getStatusCode(),
184
                'body'      => (string) $response->getBody(),
185
            ];
186
        } catch (\GuzzleHttp\Exception\ClientException $e) {
187
            return $this->clientError($e);
188
        } catch (\GuzzleHttp\Exception\ServerException $e) {
189
            return $this->parseError($e);
190
        }
191
    }
192
193
    /**
194
     * Authenticate and gets the number of available session tokens.
@@ 200-222 (lines=23) @@
197
     *
198
     * @return array
199
     */
200
    public function authToken()
201
    {
202
        try {
203
            $response = $this->get(
204
                '/webservice/auth/token',
205
                [
206
                    'headers' => [
207
                        'Authorization' => $this->bearerOrBasic(),
208
                    ],
209
                ]
210
            );
211
212
            return [
213
                'status'    => 'ok',
214
                'http_code' => $response->getStatusCode(),
215
                'body'      => (string) $response->getBody(),
216
            ];
217
        } catch (\GuzzleHttp\Exception\ClientException $e) {
218
            return $this->clientError($e);
219
        } catch (\GuzzleHttp\Exception\ServerException $e) {
220
            return $this->parseError($e);
221
        }
222
    }
223
224
    /**
225
     * Gets the mobile network on which the SIM is connected.
@@ 233-258 (lines=26) @@
230
     *
231
     * @return array
232
     */
233
    public function simnetwork($msisdn)
234
    {
235
        try {
236
            $response = $this->get(
237
                sprintf(
238
                    '/webservice/utilities/simnetwork/%d',
239
                    $msisdn
240
                ),
241
                [
242
                    'headers' => [
243
                        'Authorization' => $this->bearerOrBasic(),
244
                    ],
245
                ]
246
            );
247
248
            return [
249
                'status'    => 'ok',
250
                'http_code' => $response->getStatusCode(),
251
                'body'      => (string) $response->getBody(),
252
            ];
253
        } catch (\GuzzleHttp\Exception\ClientException $e) {
254
            return $this->clientError($e);
255
        } catch (\GuzzleHttp\Exception\ServerException $e) {
256
            return $this->parseError($e);
257
        }
258
    }
259
260
    /**
261
     * Test SmartCall is responding.

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