@param array $data
@param array $headers

@throws Exception

@return array|string
19781
public function create(array $data, array $headers = [])
    {
        $url = $this->url('invoices');

        return $this->post($url, $data, $headers);
    }
502965
protected function request($url, $data, array $headers = array())
    {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

        curl_exec($ch);
        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return floor($statusCode / 100) == 2;
    }
409334
public function createSubscription(array $data, array $headers = [])
    {
        $url = $this->url('estimates/create_subscription');

        return $this->post($url, $data, $headers);
    }
498287
protected function parseSignature(array $header, $data)
    {
        if ($data == '' || !isset($header['alg']) || $header['alg'] == 'none') {
            return null;
        }

        $hash = $this->deserializer->fromBase64URL($data);

        return new Signature($hash);
    }
718833
public function checkoutExistingSubscription(array $data = [], array $headers = [])
    {
        $url = $this->url('hosted_pages/checkout_existing');

        return $this->post($url, $data, $headers);
    }
382891
public static function json($data = array(), $status = 200, array $headers = array())
	{
		if ($data instanceof ArrayableInterface)
		{
			$data = $data->toArray();
		}

		return new JsonResponse($data, $status, $headers);
	}
538231
public function post($url, $data = '', array $headers = [])
    {
        return $this->executor->execute(
            $url,
            [
                CURLOPT_POST => true,
                CURLOPT_HTTPHEADER => $headers,
                CURLOPT_POSTFIELDS => $data,
            ]
        );
    }
29670
public function post($url, array $data, array $headers = null)
    {
        $headers = is_null($headers) ? ['Content-Type: application/json; charset=utf-8'] : $headers;
        return $this->sendRequest('POST', $url, $headers, $data);
    }
346816
public function respond(array $data = [], array $headers = []): JsonResponse
    {
        $meta = [
            'meta' => [
                'server_time' => time(),
                'server_timezone' => date_default_timezone_get(),
                'api_version' => 'v1',
            ],
        ];

        return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
    }
1111352
protected function respond($data, $headers = [])
    {
        $this->setResponseHeaders($headers);

        return response()->json($data, $this->getStatusCode(), $this->getResponseHeaders());
    }
168857
public function put($url, $data, array $headers = array())
    {
        curl_setopt($this->handle, CURLOPT_CUSTOMREQUEST, 'PUT');

        $fields = is_array($data) ? http_build_query($data) : $data;
        curl_setopt($this->handle, CURLOPT_POSTFIELDS, $fields);

        $headers = array_replace($headers, ['Content-Length' => strlen($fields)]);
        return $this->execute($url, $headers);
    }
1019268
public function createFromArray(array $data)
    {
        $headers = json_encode(
            Arr::path($this->emailConfig, 'defaults.headers', [])
        );

        if (isset($data['sender_localpart'])) {
            if (! Arr::path($this->emailConfig, 'defaults.sender.domain')) {
                throw new \Exception('defaults.sender.domain not set in email config');
            }

            $data['sender_email'] = (
                Arr::remove($data, 'sender_localpart') . '@' .
                Arr::path($this->emailConfig, 'defaults.sender.domain')
            );
        }

        $defaults = [
            'headers'      => $headers,
            'sender_email' => Arr::path($this->emailConfig, 'defaults.sender.email'),
            'sender_name'  => Arr::path($this->emailConfig, 'defaults.sender.name'),
        ];

        $email = $this->emailMapper->getPrototype();

        $email = $email->exchangeArray(
            array_merge($defaults, $data)
        );

        $email = $this->emailMapper->persist($email);

        return $email;
    }
1047284
private function getHeaders(array $headers)
    {
        $str = '';
        foreach ($headers as $key => $value) {
            $str .= sprintf("%s: %s\r\n", $key, $value);
        }

        return $str;
    }
107997
private function send($url, array $data = [], array $headers = [])
    {
        // Set incoming parameters as cURL options
        $this->setUrl($url);
        $this->setData($data);
        $this->setHeaders($headers);

        return $this->executeCurlRequest();
    }
1239210
public function revenueRecognition(array $data = [], array $headers = [])
    {
        $url = $this->url('exports/revenue_recognition');

        return $this->post($url, $data, $headers);
    }
830899
public function parse($data, array $headers)
    {
        $source = json_decode($data);
        $errors = $this->getJsonErrors();
        $this->string = $data;
        if (!$errors) {
            if (!(
                $headers['Status'] === 201 ||
                $headers['Status'] === 200 ||
                $headers['Status'] === 409 ||
                $headers['Status'] === 422 ||
                $headers['Status'] === 400
            )) {
                print_r($headers);
                exit;
            }
            if ($headers['Status'] === 201 || $headers['Status'] === 200) {
                switch ($headers['Method']) {
                    case 'UPLOAD':
                        return empty($source->pendingFile->ref) ? null : (string) $source->pendingFile->ref;
                    case 'POST':
                        // print_r($headers);
                        if (!empty($headers['id'])) {
                            return (int) $headers['id'];
                        } elseif (!empty($source->fileId)) {
                            return (int) $source->fileId;
                        }
                        // no break
                    case 'PUT':
                        return isset($source->id) ? $source->id : true;
                    case 'DELETE':
                        return true;

                    default:
                        if (!empty($source->STATUS)) {
                            unset($source->STATUS);
                        }
                        if (!empty($source->project->files)) {
                            $source = $source->project->files;
                        } elseif (!empty($source->project->notebooks)) {
                            $source = $source->project->notebooks;
                        } elseif (!empty($source->project->links)) {
                            $source = $source->project->links;
                        } elseif (
                            !empty($source->messageReplies) &&
                            preg_match('!messageReplies/(\d+)!', $headers['X-Action'])
                        ) {
                            $source = current($source->messageReplies);
                        } elseif (
                            !empty($source->people) &&
                            preg_match('!projects/(\d+)/people/(\d+)!', $headers['X-Action'])
                        ) {
                            $source = current($source->people);
                        } elseif (
                            !empty($source->project) &&
                            preg_match('!projects/(\d+)/notebooks!', $headers['X-Action'])
                        ) {
                            $source = [];
                        } elseif (
                            isset($source->cards) &&
                            preg_match('!portfolio/columns/(\d+)/cards!', $headers['X-Action'])
                        ) {
                            $source = $source->cards;
                        } else {
                            $source = current($source);
                        }
                        if ($headers['X-Action'] === 'links' || $headers['X-Action'] === 'notebooks') {
                            $_source = [];
                            $wrapper = $headers['X-Action'];
                            foreach ($source as $project) {
                                foreach ($project->$wrapper as $object) {
                                    $_source[] = $object;
                                }
                            }
                            $source = $_source;
                        } elseif (strpos($headers['X-Action'], 'time_entries') !== false && !$source) {
                            $source = [];
                        }
                        $this->headers = $headers;
                        $this->string = json_encode($source);

                        $this->data   = self::camelizeObject($source);

                        if (!empty($this->data->id)) {
                            $this->data->id = (int) $this->data->id;
                        }

                        return $this;
                }
            } elseif (!empty($source->MESSAGE)) {
                $errors = $source->MESSAGE;
            } else {
                $errors = null;
            }
        }

        throw new Exception([
            'Message'  => $errors,
            'Response' => $data,
            'Headers'  => $headers
        ]);
    }
941082
protected function extractSingleItemData(array $data) {
        if ($this->singleResponseKey && !array_key_exists($this->singleResponseKey, $data)) {
            throw new Exception('Invalid response, missing field ' . $this->singleResponseKey);
        }

        return ($this->singleResponseKey) ? $data[$this->singleResponseKey] : $data;
    }