public function getOrderInfo($accountId, $orderId) { $order = \Requests::patch($this->getUrl() . 'accounts/' . $accountId . '/orders/' . $orderId, array('Authorization' => 'Bearer ' . $this->getToken(), 'Content-Type' => 'application/json')); //$this->checkAnswer($order); print_r($order->headers); return $order; }
public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json")) { try { $options = array('auth' => new \Requests_Auth_Basic(array($api_key, ''))); if ($method == "GET") { $url_params = is_array($data) ? '?' . http_build_query($data) : ''; $response = \Requests::get(Client::BASE_URL . $url . $url_params, $headers, $options); } else { if ($method == "POST") { $response = \Requests::post(Client::BASE_URL . $url, $headers, json_encode($data), $options); } else { if ($method == "PATCH") { $response = \Requests::patch(Client::BASE_URL . $url, $headers, json_encode($data), $options); } else { if ($method == "DELETE") { $response = \Requests::delete(Client::BASE_URL . $url, $headers, $options); } } } } } catch (\Exception $e) { throw new UnableToConnect(); } if ($response->status_code >= 200 && $response->status_code <= 206) { if ($method == "DELETE") { return $response->status_code == 204 || $response->status_code == 200; } return json_decode($response->body); } if ($response->status_code == 400) { $code = 0; $message = ""; try { $error = (array) json_decode($response->body)->errors[0]; $code = key($error); $message = current($error); } catch (\Exception $e) { throw new UnhandledError($response->body, $response->status_code); } throw new InputValidationError($message, $code); } if ($response->status_code == 401) { throw new AuthenticationError(); } if ($response->status_code == 404) { throw new NotFound(); } if ($response->status_code == 403) { throw new InvalidApiKey(); } if ($response->status_code == 405) { throw new MethodNotAllowed(); } throw new UnhandledError($response->body, $response->status_code); }
public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json")) { try { $options = array('auth' => new AuthBearer($api_key), 'timeout' => 120); if ($method == "GET") { $url_params = is_array($data) ? '?' . http_build_query($data) : ''; $response = \Requests::get(Culqi::$api_base . $url . $url_params, $headers, $options); } else { if ($method == "POST") { $response = \Requests::post(Culqi::$api_base . $url, $headers, json_encode($data), $options); } else { if ($method == "PATCH") { $response = \Requests::patch(Culqi::$api_base . $url, $headers, json_encode($data), $options); } else { if ($method == "DELETE") { $response = \Requests::delete(Culqi::$api_base, $options); } } } } } catch (\Exception $e) { throw new Errors\UnableToConnect(); } if ($response->status_code >= 200 && $response->status_code <= 206) { if ($method == "DELETE") { return $response->status_code == 204 || $response->status_code == 200; } return json_decode($response->body); } if ($response->status_code == 400) { $code = 0; $message = ""; throw new Errors\UnhandledError($response->body, $response->status_code); } if ($response->status_code == 401) { throw new Errors\AuthenticationError(); } if ($response->status_code == 404) { throw new Errors\NotFound(); } if ($response->status_code == 403) { throw new Errors\InvalidApiKey(); } if ($response->status_code == 405) { throw new Errors\MethodNotAllowed(); } throw new Errors\UnhandledError($response->body, $response->status_code); }
protected function request($method, $url, $client_id, $secret_id, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json")) { try { $options = array('auth' => new \Requests_Auth_Basic(array($client_id, $secret_id))); if ($method == "GET") { $url_params = is_array($data) ? '?' . http_build_query($data) : ''; $response = \Requests::get($this->base_url . $url . $url_params, $headers, $options); } else { if ($method == "POST") { $response = \Requests::post($this->base_url . $url, $headers, json_encode($data), $options); } else { if ($method == "PATCH") { $response = \Requests::patch($this->base_url . $url, $headers, json_encode($data), $options); } else { if ($method == "DELETE") { $response = \Requests::delete($this->base_url . $url, $headers, $options); } } } } } catch (\Exception $e) { throw new \Exception(Error_Message::ERROR_CONNECTION); } if ($response->status_code >= 200 && $response->status_code <= 206) { if ($method == "DELETE") { return $response->status_code == 204 || $response->status_code == 200; } return json_decode($response->body); } if ($response->status_code >= 400 && $response->status_code <= 406) { try { $error = (array) json_decode($response->body); $code = $error['errorCode']; $message = $error['errorMessage']; } catch (\Exception $e) { throw new \Exception($response->body, $response->status_code); } throw new \Exception($message, $code); } throw new \Exception($response->body, $response->status_code); }
public function testPATCHWithArray() { $data = array('test' => 'true', 'test2' => 'test'); $request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions()); $this->assertEquals(200, $request->status_code); $result = json_decode($request->body, true); $this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']); }