Created
January 8, 2018 20:41
-
-
Save adampiotrowski/a5fd7105f614a27b9298bdb093ff8edb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class WellCommerceClient | |
| { | |
| public function __construct($url, $apikey) | |
| { | |
| $this->url = $url; | |
| $this->key = $apikey; | |
| $this->id = 1; | |
| } | |
| public function __call($method, $params) | |
| { | |
| if (is_array($params)) { | |
| $params = array_values($params); | |
| } else { | |
| throw new \Exception('Params must be given as array'); | |
| } | |
| $request = [ | |
| 'method' => $method, | |
| 'params' => $params, | |
| 'id' => $this->id, | |
| 'key' => $this->key, | |
| ]; | |
| $request = json_encode($request); | |
| $curl = curl_init($this->url); | |
| curl_setopt($curl, CURLOPT_POST, 1); | |
| curl_setopt($curl, CURLOPT_POSTFIELDS, $request); | |
| curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($curl, CURLOPT_HTTPHEADER, [ | |
| 'Content-type: application/json', | |
| ]); | |
| $response = curl_exec($curl); | |
| curl_close($curl); | |
| $response = json_decode($response, true); | |
| if ($response['id'] != $this->id) { | |
| throw new \Exception($response); | |
| } | |
| if (!is_null($response['error'])) { | |
| throw new \Exception('Request error: ' . $response['error']); | |
| } | |
| return $response['result']; | |
| } | |
| public function debug($Data) | |
| { | |
| echo "<pre>"; | |
| print_r($Data); | |
| die(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment