This repository was archived by the owner on Jan 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGatewayTrait.php
More file actions
76 lines (67 loc) · 1.62 KB
/
GatewayTrait.php
File metadata and controls
76 lines (67 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* This file is part of NotifyMe.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NotifyMeHQ\Http;
trait GatewayTrait
{
/**
* The http client.
*
* @var \GuzzleHttp\Client
*/
protected $client;
/**
* The configuration options.
*
* @var string[]
*/
protected $config;
/**
* Get error response from server or fallback to general error.
*
* @param \GuzzleHttp\Message\ResponseInterface|\Psr\Http\Message\ResponseInterface $rawResponse
*
* @return array
*/
protected function responseError($rawResponse)
{
return json_decode($rawResponse->getBody(), true) ?: $this->buildError($rawResponse);
}
/**
* Build a fallback error.
*
* @param \GuzzleHttp\Message\ResponseInterface|\Psr\Http\Message\ResponseInterface $rawResponse
*
* @return array
*/
protected function buildError($rawResponse)
{
return ['error' => "API Response not valid. (Raw response API {$rawResponse->getBody()})"];
}
/**
* Build request url from string.
*
* @param string|null $endpoint
*
* @return string
*/
protected function buildUrlFromString($endpoint = null)
{
if ($endpoint) {
return $this->getRequestUrl().'/'.$endpoint;
}
return $this->getRequestUrl();
}
/**
* Get the gateway request url.
*
* @return string
*/
abstract protected function getRequestUrl();
}