Fetch all results from an api call.

@param \Bitbucket\Api\ApiInterface $api
@param string                      $method
@param array                       $parameters

@throws \Http\Client\Exception

@return array
173256
public function fetchAll(ApiInterface $api, $method, array $parameters = [])
    {
        // get the perPage from the api
        $perPage = $api->getPerPage();

        // set parameters per_page to max to minimize number of requests
        $api->setPerPage(100);

        try {
            $result = $this->fetch($api, $method, $parameters)['values'];

            while ($this->hasNext()) {
                $next = $this->fetchNext();
                $result = array_merge($result, $next['values']);
            }
        } finally {
            // restore the perPage
            $api->setPerPage($perPage);
        }

        return $result;
    }
542185
public function getByRequestParts(
        string $host,
        string $method,
        RequestParts $requestParts
    ): array {
        $json = json_encode($requestParts->getParameters()['json']);
        $formattedUrl = rtrim($host, '/').'/'.ltrim($requestParts->getUrl(), '/');
        $method = strtoupper($method);
        $headers = [];
        foreach ($requestParts->getParameters()['headers'] ?? [] as $header => $value) {
            $headers[] = "$header: $value";
        }

        $c = curl_init();
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($c, CURLOPT_URL, $formattedUrl);
        curl_setopt($c, CURLOPT_HEADER, false);
        curl_setopt($c, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($c, CURLOPT_ENCODING, 'gzip, deflate');

        if (!in_array($method, ['GET', 'HEAD'])) {
            curl_setopt($c, CURLOPT_POSTFIELDS, $json);
            $headers[] = 'Content-Type: application/json';
            $headers[] = 'Content-Length: '.strlen($json);
        }

        curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
        $content = curl_exec($c);
        $responseCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
        curl_close($c);

        if (
            'HEAD' !== $method &&
            false === $content
        ) {
            throw ConnectionException::buildConnectExceptionByUrl($requestParts->getUrl());
        }

        return [
            'code' => (int) $responseCode,
            'body' => empty($content)
                ? []
                : json_decode($content, true),
        ];
    }
203278
public function rawApi($apiSubUrl, $method = 'GET', $params = [], array $headers = [])
    {
        if (is_string($params)) {
            $headers[] = 'Content-Length: ' . mb_strlen($params);
            $headers[] = 'Host: webmaster.yandex.ru';
            $headers[] = $method . ' ' . parse_url($this->apiBaseUrl, PHP_URL_PATH) . $apiSubUrl . ' HTTP/1.1';
            $this->setCurlOptions([CURLOPT_POSTFIELDS => $params]);
            $params = [];
        }
        return $this->api($apiSubUrl, $method, $params, $headers);
    }
1177136
protected function getCallParams($controller, $method, $params)
		{
			// variables
			$values     = is_array($params) ? $params : explode('/', $params);
			$ref        = new ReflectionMethod($controller, $method);
			$params     = $ref->getParameters();
			$args       = [];
	
			// map route segments to the method's parameters
			foreach ($params as /** @var \ReflectionParameter */ $param)
			{
				// parse signature [match, optional, type, name, default]
				preg_match('/<(required|optional)> (?:([\\\\a-z\d_]+) )?(?:\\$(\w+))(?: = (\S+))?/i', (string)$param, $matches);
	
				// assign untyped segments
				if ($matches[2] == null)
				{
					$args[$matches[3]] = array_shift($values);
				}
			}
	
			// append any remaining values
			return array_merge($args, $values);
		}
820506
public function api($method, $path, array $parameters = array(), $multipart = false, $appOnlyAuth = false, $internal = false)
    {
        $result = $this->twitter->api($method, $path, $parameters, $multipart, $appOnlyAuth, $internal);
        
        return $this->reformatResult($result);
    }
429384
public function fetchAll($query, $parameters = array())
    {
        try {
            if (self::$profiling) {
                $timer = $this->initProfiler();
            }

            $rows = array();
            $query = $this->prepare($query, $parameters);
            $rs = mysqli_query($this->connection, $query);
            if (is_bool($rs)) {
                throw new DbException('fetchAll() failed: ' . mysqli_error($this->connection) . ' : ' . $query);
            }

            while ($row = mysqli_fetch_array($rs, MYSQLI_ASSOC)) {
                $rows[] = $row;
            }
            mysqli_free_result($rs);

            if (self::$profiling && isset($timer)) {
                $this->recordQueryProfile($query, $timer);
            }
            return $rows;
        } catch (Exception $e) {
            throw new DbException("Error query: " . $e->getMessage());
        }
    }
364259
protected function _mapFnInlineParams($method, &$apiparams)
  {
    $method_template = $method;
    $match           = [];
    if (preg_match_all('/[A-Z_]{2,}/', $method, $match)) {
      foreach ($match[0] as $param) {
        $param_l = strtolower($param);
        if ($param_l === 'resumeid') {
          $param_l = 'resumeId';
        }
        $method_template = str_replace($param, ':' . $param_l, $method_template);
        if (! isset($apiparams[$param_l])) {
          for ($i = 0; $i < 26; $i++) {
            $method_template = str_replace(chr(65 + $i), '_' . chr(97 + $i), $method_template);
          }
          throw new \Exception(
            'To call the templated method "' . $method_template
            . '", specify the parameter value for "' . $param_l . '".'
          );
        }
        $method  = str_replace($param, $apiparams[$param_l], $method);
        unset($apiparams[$param_l]);
      }
    }

    return [$method, $method_template];
  }
1096253
public function request($method, $params = [])
    {
        return $this->getClient()->request($method, array_merge($params, $this->getAuth()->getAuthParams()));
    }
740754
public function callAction($method, $parameters)
    {
        $this->responseArray['type'] = Response::TYPE_CONTENT;
        $this->responseArray['method'] = Request::method();
        $this->responseArray['code'] = Response::NO_ERROR;

        if (isset($this->requiredFields[$method]) and is_array($this->requiredFields[$method])) {
            $this->validateParameters($this->requiredFields[$method]);
        }

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

        if ($response instanceof RedirectResponse) {
            $this->responseArray['type'] = Response::TYPE_REDIRECT;
            $this->responseArray['targetUrl'] = $response->getTargetUrl();
            $this->responseArray['code'] = $response->getStatusCode();
        } else {
            if ($response instanceof View) {
                return new JsonResponse($response->render());
            } else {
                if ($response instanceof JsonResponse) {
                    return $response;
                }
            }
        }

        return (new Response(config('app.debug')))->createResponse($this->responseArray);
    }
1245025
public function fetch(array $parameters = [])
    {
        $this->api->setPerPage(100);

        $results = $this->processRequest($parameters);

        while ($this->nextToken) {
            $results = array_merge($results, $this->processRequest($parameters));
        }

        return $results;
    }
232801
private function call( $method, $api, $body ) {
    $key = $this->generateHookKey( $method, $api );
    if (array_key_exists($key, $this->hookMap)) {
      call_user_func([$this, $this->hookMap[$key]], $body);
    }
  }
1064466
protected function getApiUrl($method) {
    static $READ_ONLY_CALLS =
      array('admin.getallocation' => 1,
            'admin.getappproperties' => 1,
            'admin.getbannedusers' => 1,
            'admin.getlivestreamvialink' => 1,
            'admin.getmetrics' => 1,
            'admin.getrestrictioninfo' => 1,
            'application.getpublicinfo' => 1,
            'auth.getapppublickey' => 1,
            'auth.getsession' => 1,
            'auth.getsignedpublicsessiondata' => 1,
            'comments.get' => 1,
            'connect.getunconnectedfriendscount' => 1,
            'dashboard.getactivity' => 1,
            'dashboard.getcount' => 1,
            'dashboard.getglobalnews' => 1,
            'dashboard.getnews' => 1,
            'dashboard.multigetcount' => 1,
            'dashboard.multigetnews' => 1,
            'data.getcookies' => 1,
            'events.get' => 1,
            'events.getmembers' => 1,
            'fbml.getcustomtags' => 1,
            'feed.getappfriendstories' => 1,
            'feed.getregisteredtemplatebundlebyid' => 1,
            'feed.getregisteredtemplatebundles' => 1,
            'fql.multiquery' => 1,
            'fql.query' => 1,
            'friends.arefriends' => 1,
            'friends.get' => 1,
            'friends.getappusers' => 1,
            'friends.getlists' => 1,
            'friends.getmutualfriends' => 1,
            'gifts.get' => 1,
            'groups.get' => 1,
            'groups.getmembers' => 1,
            'intl.gettranslations' => 1,
            'links.get' => 1,
            'notes.get' => 1,
            'notifications.get' => 1,
            'pages.getinfo' => 1,
            'pages.isadmin' => 1,
            'pages.isappadded' => 1,
            'pages.isfan' => 1,
            'permissions.checkavailableapiaccess' => 1,
            'permissions.checkgrantedapiaccess' => 1,
            'photos.get' => 1,
            'photos.getalbums' => 1,
            'photos.gettags' => 1,
            'profile.getinfo' => 1,
            'profile.getinfooptions' => 1,
            'stream.get' => 1,
            'stream.getcomments' => 1,
            'stream.getfilters' => 1,
            'users.getinfo' => 1,
            'users.getloggedinuser' => 1,
            'users.getstandardinfo' => 1,
            'users.hasapppermission' => 1,
            'users.isappuser' => 1,
            'users.isverified' => 1,
            'video.getuploadlimits' => 1);
    $name = 'api';
    if (isset($READ_ONLY_CALLS[strtolower($method)])) {
      $name = 'api_read';
    } else if (strtolower($method) == 'video.upload') {
      $name = 'api_video';
    }
    return self::getUrl($name, 'restserver.php');
  }
164304
protected function getMDApiParams($apiName, $operation, $api, $method)
    {
        $params = array_keys($operation['parameters']);
        $params = $this->applyFilter('DocMDParams', $params, compact('operation', 'api', 'method'));
        return $params;
    }
823511
public function call($resource, $params = array(), $method = 'GET')
    {
        if (!empty($params) && is_array($params)) {
          $queryString = http_build_query($params);
        }
        else {
          $queryString = '';
        }

        $requestUrl = self::API_URL . $resource . ((strtolower($method) == 'get') ? '?' . $queryString : '');

        $curl = curl_init();

        $curl_options = array(
          CURLOPT_USERPWD => $this->getAuthenticationString(),
          CURLOPT_RETURNTRANSFER => 1,
          CURLOPT_URL => $requestUrl,
          CURLOPT_TIMEOUT => 30,
          CURLOPT_CONNECTTIMEOUT => 30,
          CURLOPT_HTTPHEADER => array('Accept: application/xml'),
        );

        if (strtolower($method) == 'post') {
          $curl_options[CURLOPT_POST] = 1;
          $curl_options[CURLOPT_POSTFIELDS] = $params;
        }

        curl_setopt_array($curl, $curl_options);
        $response = curl_exec($curl);
        $curl_info = curl_getinfo($curl);

        //@todo test for curl error
        if ($errno = curl_errno($curl)) {
          $error_message = $errno . ': ' . curl_strerror($errno);
          throw new Exception($error_message, $errno);
        }
        curl_close($curl);

        //@todo test for any non 200 response
        if ($curl_info['http_code'] != 200) {
            throw new Exception("Response: Bad response - HTTP Code:". $curl_info['http_code']);
        }

        $xmlObject = simplexml_load_string($response);

        if ($xmlObject === false) {
            throw new Exception("Response: Response was not valid XML");
        }

        return $xmlObject;
    }
1182007
protected function call($method, array $params = array())
    {
        $this->init();

        // Prepare headers
        $this->soapClient->__setSoapHeaders($this->getSessionHeader());

        $result = $this->logcall($method, $params);
        if (!isset($result->result)) {
            return array();
        }

        return $result->result;
    }
1079205
private function handleRequest(MethodInterface $method)
    {
        $result = $this->client->sendRequest(
            $method,
            $method->getMethod(),
            $method->getAction(),
            $this->getOptions($method)
        );

        if ($method instanceof MethodResultCollectionInterface) {
            return $this->mapper->mapCollection($result, $method);
        }

        return $this->mapper->map($result, $method->createResultObject());
    }
117473
private function processMethod($method, array $options, array $headers, array $body = [])
    {
        if ($method === 'get') {
            if ($body !== []) {
                throw new \Exception('Issuing a GET request with a body');
            }
            $options[CURLOPT_HTTPGET] = 1;
        } elseif ($method === 'post') {
            $data_string = json_encode($body);

            $options[CURLOPT_POST] = 1;
            $options[CURLOPT_POSTFIELDS] = $data_string;

            array_push($headers, 'Content-Type: application/json');
            array_push($headers, 'Content-Length: ' . strlen($data_string));
        } else {
            throw new \Exception('Unrecognized method ' . strtoupper($method));
        }

        return [$options, $headers];
    }