1 | <?php |
||
8 | class Request |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * Base URL |
||
13 | * @var string |
||
14 | */ |
||
15 | const BASE_URL = 'https://api.yourmembership.com'; |
||
16 | const API_VERSION = '2.25'; |
||
17 | |||
18 | /** |
||
19 | * Session ID use for YourMembership API |
||
20 | * @var string |
||
21 | */ |
||
22 | private static $sessionId = null; |
||
23 | /** |
||
24 | * Call Counter for Your Membership for a given session |
||
25 | * @var integer |
||
26 | */ |
||
27 | public static $callId = 0; |
||
28 | /** |
||
29 | * API Key Used for YourMembership API |
||
30 | * @var string |
||
31 | */ |
||
32 | private $apiKey; |
||
33 | /** |
||
34 | * Sa Passcode is a supplementary API key used for YourMembership API |
||
35 | * @var string |
||
36 | */ |
||
37 | private $saPasscode; |
||
38 | |||
39 | |||
40 | 5 | public function __construct(string $apiKey, string $saPasscode) |
|
45 | |||
46 | /** |
||
47 | * Create the Base Envelope for an API call to YourMembership |
||
48 | * @method buildBasePayload |
||
49 | * @author PA |
||
50 | * @date 2017-01-09 |
||
51 | * @return \SimpleXMLElement XML Envelope with necessary credential parameters |
||
52 | */ |
||
53 | 4 | public function buildBasePayload() : \SimpleXMLElement |
|
71 | |||
72 | /** |
||
73 | * Generates the XML for a API method call within |
||
74 | * @method createCallPayload |
||
75 | * @author PA |
||
76 | * @date 2017-01-09 |
||
77 | * @param string $method YourMembership API Function Name |
||
78 | * @param array $arguments Array of Arguments to be passed as part of the YourMembership "Call" |
||
79 | * @return \SimpleXMLElement |
||
80 | */ |
||
81 | 4 | public function createCallPayload(string $method, array $arguments) : \SimpleXMLElement |
|
93 | /** |
||
94 | * Recursively builds the array into a XML Tree |
||
95 | * //NOTE Child arrays must be associative |
||
96 | * @method sxmlAddChildrenRecursive |
||
97 | * @author PA |
||
98 | * @date 2017-01-12 |
||
99 | * @param SimpleXMLElement $root Root XML Node |
||
100 | * @param array $arguments Array of Arguments to be added to XML Node |
||
101 | * @return SimpleXMLElement Resulting XML Tree |
||
102 | */ |
||
103 | private function sxmlAddChildrenRecursive(\SimpleXMLElement $root, array $arguments) : \SimpleXMLElement |
||
121 | /** |
||
122 | * Builds The XML Request Body for the Your Membership API Call |
||
123 | * @method buildXMLBody |
||
124 | * @author PA |
||
125 | * @date 2017-01-10 |
||
126 | * @param string $method Your Membership API Function Name |
||
127 | * @param array $arguments Your Membership Arguments |
||
128 | 2 | * @return \SimpleXMLElement |
|
129 | */ |
||
130 | 2 | public function buildXMLBody(string $method, array $arguments) : \SimpleXMLElement |
|
145 | 3 | /** |
|
146 | * Builds a Guzzle Request Object |
||
147 | * @method buildRequest |
||
148 | * @author PA |
||
149 | * @date 2017-01-11 |
||
150 | * @param string $method YourMembership API Method |
||
151 | * @param array $arguments YourMembership API Method Call Arguments |
||
152 | * @return \GuzzleHttp\Psr7\Request Guzzle Request Object |
||
153 | */ |
||
154 | public function buildRequest(string $method, array $arguments) : \GuzzleHttp\Psr7\Request |
||
159 | 3 | ||
160 | 3 | /** |
|
161 | 3 | * Checks if Request Requires Session ID |
|
162 | * @method isSessionRequiredForMethod |
||
163 | * @author PA |
||
164 | * @date 2017-01-10 |
||
165 | * @param string $method YourMembership API Method |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function isSessionRequiredForMethod(string $method) : bool |
||
173 | 3 | ||
174 | /** |
||
175 | * Helper for Deep Copy for of $from element into $to element for SimpleXML |
||
176 | * @method sxmlAppend |
||
177 | * @author PA |
||
178 | * @date 2017-01-09 |
||
179 | * @param \SimpleXMLElement $to |
||
180 | * @param \SimpleXMLElement $from |
||
181 | * @return void |
||
182 | */ |
||
183 | private function sxmlAppend(\SimpleXMLElement $to, \SimpleXMLElement $from) { |
||
188 | |||
189 | /** |
||
190 | * Adds the Session Variable to the given XML Request Payload |
||
191 | * @method addSessionIdToRequest |
||
192 | * @author PA |
||
193 | * @date 2017-01-10 |
||
194 | * @param \SimpleXMLElement $requestXML Base Request XML Payload |
||
195 | */ |
||
196 | 1 | private function addSessionIdToRequest(\SimpleXMLElement $requestXML) : \SimpleXMLElement |
|
201 | |||
202 | |||
203 | /** |
||
204 | * Setter Method for SessionID |
||
205 | * @method setSessionId |
||
206 | * @author PA |
||
207 | * @date 2017-01-10 |
||
208 | * @param string $sessionId YourMembership Session ID |
||
209 | */ |
||
210 | public static function setSessionId(string $sessionId) |
||
214 | |||
215 | /** |
||
216 | * Checks if we have an active session available |
||
217 | * @method hasSession |
||
218 | * @author PA |
||
219 | * @date 2017-01-11 |
||
220 | * @return boolean |
||
221 | */ |
||
222 | public function hasSession() |
||
226 | |||
227 | } |
||
228 |