@param $method
@param $json

@return array|mixed
541946
protected function doAPIcall($method, $json) {
    $client = \Drupal::httpClient();
    $options = [
      'json' => $json,
      'headers' => [
        'Content-Type' => 'application/json;charset=utf-8',
      ],
      'auth' => [
        $this->username,
        $this->password,
      ],
    ];
    try {
      $endpoint = $this->endpoint . $method;
      $response = $client->request('POST', $endpoint, $options);
      if ($response->getStatusCode() != '200') {
        throw new \LogicException(t('API Method %method is failed.', ['%method' => $method]));
      }
      $body = $response->getBody();
      $content = $body->getContents();

      \Drupal::logger('personify')->info('Personify request to %method. Arguments %json. Response %body', [
        '%method' => $method,
        '%json' => json_encode($json),
        '%body' => $content,
      ]);

      return json_decode($content);
    }
    catch (\Exception $e) {
      watchdog_exception('personify', $e);
    }
    return [];
  }
566243
public function callAction($method, $parameters)
    {
        $response = null;
        $this->method = $method;

        $result = parent::callAction($method, $parameters);

        if ($this->returnsArray) {
            if (!is_array($result)) {
                abort(500, 'Bad API response data.');
            }

            // Return JSON for AJAX and GET requests
            if (request()->ajax() || 'index' === $method || 'show' === $method) {
                $response = response()->json($result);

            // Return redirect-back and flash data for normal requests.
            } else {
                $response = empty($this->redirectUrl) ? back() : redirect($this->redirectUrl);
                foreach ($result as $key => $value) {
                    $response->with($key, $value);
                }
                if ('store' !== $method || isset($result['error'])) {
                    $response->withInput();
                }
            }
        } else {
            $response = $result;
        }

        return $response;
    }
232127
public function fromJson(string $json): array
    {
        if (!$this->isEmptyValue($json)) {

            if ($decode = json_decode(trim($json), true) and json_last_error() == JSON_ERROR_NONE)
                $this->result = $decode;
            else
                $this->setError(json_last_error(), json_last_error_msg());
        }

        return $this->result;
    }
1341681
protected function get($method = null)
	{
		if (is_null($method)) return $this->getRoutes();

		return array_get($this->routes, $method, array());
	}
186328
public static function fromJson($json)
    {
        $responseData = json_decode($json, true);

        if (! $responseData) {
            return new Response(false, ['invalid-json']);
        }

        if (isset($responseData['success']) && $responseData['success'] == true) {
            return new Response(true);
        }

        if (isset($responseData['error-codes']) && is_array($responseData['error-codes'])) {
            return new Response(false, $responseData['error-codes']);
        }

        return new Response(false);
    }
862486
public function getMethod($method) {

        $method = strtolower($method);

        if ( method_exists($this, $method) ) {

            return $method;

        } else if ( method_exists($this, 'any') ) {

            return 'any';

        } else {

            return null;

        }

    }
729246
public function parameterize($method)
    {
        $parameterArray = array();
        switch ($method) {
            case 'create':
                if (!is_null($this->getPayment())) {
                    $parameterArray['payment'] = $this->getPayment();
                } else {
                    $parameterArray['token'] = $this->getToken();
                }
                $parameterArray['amount'] = $this->getAmount();
                $parameterArray['currency'] = $this->getCurrency();
                $parameterArray['description'] = $this->getDescription();
                if (!is_null($this->getClient())) {
                    $parameterArray['client'] = $this->getClient();
                }
                if(!is_null($this->getSource())) {
                    $parameterArray['source'] = $this->getSource();
                }
                break;
            case 'getOne':
                $parameterArray['count'] = 1;
                $parameterArray['offset'] = 0;
                break;
            case 'getAll':
                $parameterArray = $this->getFilter();
                break;
            case 'delete':
                break;
        }

        return $parameterArray;
    }
146423
public static function jsonToArray($json = false) {

        if ($json && Validate::isJson($json)) {

            $object = json_decode($json);
            return self::objectToArray($object);
        }

        return false;
    }
315421
private function doPayPalRequest($method)
    {
        // Setup PayPal API Request Payload
        $this->createRequestPayload($method);

        try {
            $response = $this->makeHttpRequest();

            return \GuzzleHttp\json_decode($response, true);
        } catch (\Exception $e) {
            $message = $e->getMessage();
        }

        return [
            'type'    => 'error',
            'message' => $message,
        ];
    }
756847
private function doPayPalRequest($method)
    {
        // Setup PayPal API Request Payload
        $this->createRequestPayload($method);

        try {
            // Perform PayPal HTTP API request.
            $response = $this->makeHttpRequest();

            return $this->retrieveData($method, $response);
        } catch (\Exception $e) {
            $message = collect($e->getTrace())->implode('\n');
        }

        return [
            'type'    => 'error',
            'message' => $message,
        ];
    }
292388
public function newJsonRequest($method, $url, $data = array())
	{
		return $this->newRequest($method, $url, $data, Request::ENCODING_JSON);
	}
157681
protected function objectMethodExists($object, $method)
    {
        if (method_exists($object, 'methodExists')) {
            return $object->methodExists($method);
        }

        return method_exists($object, $method);
    }
816173
public static function fromJson($json)
    {
        $object = json_decode($json);

        $sale = new Sale();
        $sale->populate($object);

        return $sale;
    }
884986
private function parseJson($json)
    {
        $jsonPayload = json_decode($json, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new ParserException('Error parsing JSON: '
                . json_last_error_msg());
        }

        return $jsonPayload;
    }
26270
public static function inboundsPage($json)
    {
        $fields = Deserialize::_fromJson($json);

        $result = new Api\Page();
        $result->setPage($fields->page);
        $result->setSize($fields->page_size);
        $result->setTotalSize($fields->count);
        $result->setContent(
            array_map(
                function ($s) {
                    return Deserialize::_moSmsFromFields($json, $s);
                },
                $fields->inbounds
            )
        );

        return $result;
    }
262375
public function normalize(MethodDoc $method) : array
    {
        $docTags = [];

        if (count($method->getTagList())) {
            $docTags['tags'] = $method->getTagList();
        }

        return [
                'summary' => sprintf('"%s" json-rpc method', $method->getMethodName()),
            ]
            + $this->getDescriptionDoc($method)
            + $docTags
            + [
                'operationId' => $method->getIdentifier(),
                'consumes' => ['application/json'],
                'produces' => ['application/json'],
                'parameters' => [
                    [
                        'in' => 'body',
                        'name' => 'JsonRpc request',
                        'required' => true,
                        'schema' => $this->requestDocTransformer->normalize($method)
                    ]
                ],
                'responses' => [
                    '200' => [
                        'description' => 'JSON-RPC response',
                        'schema' => $this->responseDocNormalizer->normalize($method),
                    ]
                ]
            ]
        ;
    }
250300
protected function getBody($method)
    {
        $file = $this->getArgument("file");
        if (!is_null($file)) {
            return "file:$file";
        }
        if (count($this->getArguments($method)) > 0) {
            return json_encode($this->getArguments($method));
        }
        return "";
    }