Created
May 30, 2017 22:39
-
-
Save rquast/e864a73aa9aa26bef2f529e64413b4d4 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 FastSpringAPIClient { | |
| const USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'; | |
| function __construct() { | |
| } | |
| function post($path, $data) { | |
| $data_string = json_encode($data); | |
| $url = FASTSPRING_API_BASE_URL . $path; | |
| $headers = [ | |
| 'Accept: application/json', | |
| 'Content-Type: application/json', | |
| 'Content-Length: ' . strlen($data_string) | |
| ]; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_setopt($ch, CURLOPT_POST, 1); | |
| curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | |
| curl_setopt($ch, CURLOPT_USERPWD, FASTSPRING_API_USERNAME . ':' . FASTSPRING_API_PASSWORD); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
| curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); | |
| $response = json_decode(curl_unescape($ch, curl_exec($ch)), true); | |
| $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
| curl_close($ch); | |
| return [ | |
| 'response' => $response, | |
| 'status' => $status_code | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment