Request token action.

@param string $namespace namespace of request
@param array $parameters request parameters
@return ResponseInterface response from Fitbit API
336419
private function tokenRequest($namespace, $parameters)
    {
        $client = new Client([
            'headers' => [
                'content-type' => 'application/x-www-form-urlencoded',
                'Authorization' => 'Basic '. base64_encode($this->clientId . ':' . $this->secret),
            ]
        ]);

        return $client->post(self::FITBIT_API_URL . $namespace . '?' . http_build_query($parameters));
    }
1023148
public function attachNamespace($namespace, $paths)
    {
        if (isset($this->namespaces[$namespace])) {
            if (is_array($paths)) {
                $this->namespaces[$namespace] = array_merge($this->namespaces[$namespace], $paths);
            } else {
                $this->namespaces[$namespace][] = $paths;
            }
        } else {
            $this->namespaces[$namespace] = (array) $paths;
        }

        return $this;
    }
1249645
public function setNamespace($namespace)
    {
        if ($namespace === null || $namespace === '' || $namespace === '\\') {
            $this->namespace = null;

            return;
        }

        if ($namespace[0] === '\\') {
            $namespace = substr($namespace, 1);
        }

        if ($this->isNamespaceValid($namespace) !== true) {
            throw new InvalidArgumentException('Namespace name is not valid.');
        }

        $this->namespace = $namespace;
    }
761836
private function _invoke(array $parameters)
    {
        $actionName = $parameters["Action"];
        $response = array();
        $responseBody = null;
        $statusCode = 200;

        /* Submit the request and read response body */
        try {

        	if (empty($this->_config['ServiceURL'])) {
        		throw new OffAmazonPaymentsService_Exception(
        			array ('ErrorCode' => 'InvalidServiceURL',
        				   'Message' => "Missing serviceUrl configuration value. You may obtain a list of valid MWS URLs by consulting the MWS Developer's Guide, or reviewing the sample code published along side this library."));
        	}

            /* Add required request parameters */
            $parameters = $this->_addRequiredParameters($parameters);

            $shouldRetry = true;
            $retries = 0;
            do {
                try {
                        $response = $this->_httpPost($parameters);
                        if ($response['Status'] === 200) {
                            $shouldRetry = false;
                        } else {
                            if ($response['Status'] === 500 || $response['Status'] === 503) {
                            	

                            	$errorResponse = OffAmazonPaymentsService_Model_ErrorResponse::fromXML($response['ResponseBody']);
                            	
                            	$errors = $errorResponse->getError();
                            	$shouldRetry = ($errors[0]->getCode() === 'RequestThrottled') ? false : true;
                            	
                            	if ($shouldRetry) {
                            		$this->_pauseOnRetry(++$retries, $response['Status']);
                            	} else {
                            		throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                            	}
                            } else {
                                throw $this->_reportAnyErrors($response['ResponseBody'], $response['Status'], $response['ResponseHeaderMetadata']);
                            }
                       }
                /* Rethrow on deserializer error */
                } catch (Exception $e) {

                    if ($e instanceof OffAmazonPaymentsService_Exception) {
                        throw $e;
                    } else {

                        throw new OffAmazonPaymentsService_Exception(array('Exception' => $e, 'Message' => $e->getMessage()));
                    }
                }

            } while ($shouldRetry);

        } catch (OffAmazonPaymentsService_Exception $se) {
            throw $se;
        } catch (Exception $t) {
            throw new OffAmazonPaymentsService_Exception(array('Exception' => $t, 'Message' => $t->getMessage()));
        }

        return array ('ResponseBody' => $response['ResponseBody'], 'ResponseHeaderMetadata' => $response['ResponseHeaderMetadata']);
    }
473255
public function setNamespace($namespace)
    {
        if (is_string($namespace) === false) {
            $msg = "The namespace argument must be a string.";
            throw new InvalidArgumentException($msg);
        } elseif ($namespace === '') {
            $msg = "The namespace argument must be a non-empty string.";
            throw new InvalidArgumentException($msg);
        } else {
            $this->namespace = $namespace;
        }
    }
30039
protected function bindToNamespace($request, $url, $namespace)
    {
        $array  = explode('|', $url, 3);
        $class  = !empty($array[0]) ? $array[0] : $this->router->config('default_controller');
        $method = !empty($array[1]) ? $array[1] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[2])) {
            $this->parseUrlParams($request, $array[2], $param);
        }

        return new CallbackDispatch($request, $this, [$namespace . '\\' . Loader::parseName($class, 1), $method], $param);
    }
21576
public function toNamespacedString($namespace, array $aliased_classes, $this_class, $use_phpdoc_format)
    {
        $intersection_types = $this->getNamespacedIntersectionTypes(
            $namespace,
            $aliased_classes,
            $this_class,
            $use_phpdoc_format
        );

        return $this->param_name . $intersection_types;
    }
854492
private function getParametersForNameSpace($namespace)
    {
        $parameters = array();
        foreach ($this->parameters as $key => $value) {
            if (0 === strpos($key, $namespace . ':')) {
                $parameters[substr($key, strlen($namespace) + 1)] = $value;
            }
        }
        return $parameters;
    }
19624
public function policies($namespace = null)
    {
        if (is_null($namespace)) {
            $namespace = config('sleeping_owl.policies_namespace', '\\App\\Policies\\');
        }

        $policies = [];
        $preparedPolicies = collect($this->policies);

        foreach ($this->sections as $model => $section) {
            if ($preparedPolicies->has($section)) {
                $policies[$section] = $preparedPolicies->get($section);
                continue;
            }

            $policies[$section] = $namespace.class_basename($section).'SectionModelPolicy';
        }

        return $policies;
    }
759884
public function request(
        $url,
        array $parameters = [],
        $method = SocialConnectClient::GET,
        array $headers = [],
        array $options = []
    ) {
        switch ($method) {
            case SocialConnectClient::GET:
                $response = $this->_client->get(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::POST:
                $response = $this->_client->post(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::PUT:
                $response = $this->_client->put(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            case SocialConnectClient::DELETE:
                $response = $this->_client->delete(
                    $url,
                    $parameters,
                    ['headers' => $headers]
                );
                break;
            default:
                throw new InvalidArgumentException("Method {$method} is not supported");
        }

        return new Response(
            $response->getStatusCode(),
            (string)$response->getBody(),
            $response->getHeaders()
        );
    }
1110625
public function get(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface
    {
        if (count($parameters) > 0) {
            $path .= '?' . http_build_query($parameters);
        }

        $response = $this->httpClient->sendRequest(
            $this->requestBuilder->create('GET', $path, $requestHeaders)
        );

        $statusCode = $response->getStatusCode();
        if ($statusCode !== 200) {
            $errorResponse = $response->getBody()->__toString();
            $errorMessage = !empty($errorResponse) ? $errorResponse : "Invalid Auspost API response.";

            throw new EndpointServiceError($errorMessage);
        }

        return $response;
    }
870180
public function registerNamespace($namespace, $path)
    {
        $namespace = trim($namespace, '\\');
        $this->_namespaces[$namespace] = (array) $path;

        krsort($this->_namespaces, SORT_STRING);

        return $this;
    }
459465
public function ns($nameSpace)
    {
        // If ! exist try to load a configuration file 
        if ( !isset($this->nameSpaces[$nameSpace]) ) {
            // short sanitize of nameSpace
            if (!filter_var( $nameSpace,FILTER_VALIDATE_REGEXP, 
                array('options'=>array('regexp' => '/^[\w]+$/')))) {
                    throw new InvalidArgumentException("Invalid configuration name.",400);
            }
            $this->nameSpaces[$nameSpace] = new ContextNameSpace($this->loadArrayFromIniFile($nameSpace));
        }
        
        return $this->nameSpaces[$nameSpace];
    }
1169123
public static function namespaceAll(array $permissions, string $namespace) : array
    {
        InvalidArgumentException::verifyAllInstanceOf(__METHOD__, 'permissions', $permissions, IPermission::class);

        $namespacedPermissions = [];

        foreach ($permissions as $permission) {
            $permission = $permission->inNamespace($namespace);

            $namespacedPermissions[$permission->getName()] = $permission;
        }

        return $namespacedPermissions;
    }
1145641
public static function getNamespace($tokens)
    {
        $count = count($tokens);
        $i = 0;
        $namespace = '';
        $namespace_ok = false;
        while ($i < $count) {
            $token = $tokens[$i];
            if (is_array($token) && $token[0] === T_NAMESPACE) {
                // Found namespace declaration
                while (++$i < $count) {
                    if ($tokens[$i] === ';') {
                        $namespace_ok = true;
                        $namespace = trim($namespace);
                        break;
                    }
                    $namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
                }
                break;
            }
            $i++;
        }
        if (!$namespace_ok) {
            return null;
        } else {
            return $namespace;
        }
    }
1191701
protected function mergeNamespaceGroup(array $action, $namespace = null)
    {
        if (isset($namespace, $action['uses'])) {
            $action['uses'] = $this->prependGroupNamespace($action['uses'], $namespace);
        }

        return $action;
    }
1154700
public function findNamespace(string $namespace): string
	{
		$allNamespaces = $this->getNamespaces();

		$expr = preg_replace_callback(
			'{([^:]+|)}',
			function ($matches)
			{
				return preg_quote($matches[1]) . '[^:]*';
			},
			$namespace
		);

		$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);

		if (empty($namespaces))
		{
			throw new NamespaceNotFoundException(sprintf('There are no commands defined in the "%s" namespace.', $namespace));
		}

		$exact = \in_array($namespace, $namespaces, true);

		if (\count($namespaces) > 1 && !$exact)
		{
			throw new NamespaceNotFoundException(sprintf('The namespace "%s" is ambiguous.', $namespace));
		}

		return $exact ? $namespace : reset($namespaces);
	}