Allows to manually check if API key is valid or not

@param string $apiKey Akismet API key
@param string $url    The front page or home URL of the instance making the request

@throws InvalidArgumentException
@return boolean
544842
public function keyCheck($apiKey = null, $url = null)
    {
        if ($apiKey === null || $url === null) {
            throw new InvalidArgumentException('Both apiKey and site URL cannot be null');
        }

        return $this->connection->keyCheck($apiKey, $url);
    }
397235
public function has($key)
    {
        /* If $key is not valid string throws InvalidArgumentException */
        if (!$this->isString($key)) {
            throw new InvalidArgumentException('Cache key must be not empty string');
        }

        if ($this->getRaw($key)) {
            return true;
        }

        return false;
    }
418603
public function __isset($key)
    {
        if ($this->flag == self::ARRAY_AS_PROPS) {
            return $this->offsetExists($key);
        }

        if (in_array($key, $this->protectedProperties)) {
            throw new \InvalidArgumentException('$key is a protected property, use a different key');
        }

        return isset($this->$key);
    }
349540
def api_key(self, api_key):
        
        if api_key is None:
            raise ValueError("Invalid value for `api_key`, must not be `None`")
        if api_key is not None and len(api_key) > 1000:
            raise ValueError("Invalid value for `api_key`, length must be less than or equal to `1000`")

        self._api_key = api_key
663940
public function useKeyAsIndex($key, $normalize = false)
    {
        if (null === $key) {
            $this->indexKey = null;
            return;
        }

        if (true !== $normalize && !$this->isValidNodeName($key)) {
            throw new \InvalidArgumentException(sprintf('%s is an invalid node name', $key));
        }

        $this->indexKey = $normalize ? $this->normalizer->normalize($key) : $key;
    }
1232472
public void setApiKey(String apiKey) {
        for (Authentication auth : authentications.values()) {
            if (auth instanceof ApiKeyAuth) {
                ((ApiKeyAuth) auth).setApiKey(apiKey);
                return;
            }
        }
        throw new RuntimeException("No API key authentication configured!");
    }
1093167
public function update($params = null, $apiKey = null)
    {
        if (!isset($params['webhook']) || !is_array($params['webhook'])) {
            $clone = $params;
            unset($params);
            $params['webhook'] = $clone;
        }

        return self::_update(get_class(), $params);
    }
841592
public function setApiKey($key)
    {
        $this->apiKey = $key;
        return $this->apiKey === $key ? true : false;
    }
770446
public function setApiKey($apikey)
    {
        if (isset($this->emailPassword)) {
            throw new \Exception(
                "EmailPassword already set."
            );
		}
		$this->apikey = $apikey . ':';
		return $this;
    }
324154
def verify_api_key
      return :false if invalid_options?
      value = http_post(
        Net::HTTP.new(self.class.host, self.class.port, options[:proxy_host], options[:proxy_port]),
        'verify-key',
        {
          :key  => self.options[:api_key],
          :blog => self.options[:blog]
        }.to_query
      )
      self.verified_key = (value == 'valid') ? true : :false
    end
678501
public static function validateKey($key): void
    {
        if (!is_string($key)) {
            throw new InvalidArgumentException(sprintf(
                'Cache key must be string, "%s" given',
                is_object($key) ? get_class($key) : gettype($key)
            ));
        }
        if (!isset($key[0])) {
            throw new InvalidArgumentException('Cache key length must be greater than zero');
        }
        if (isset($key[strcspn($key, '{}()/\@:')])) {
            throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key));
        }
    }
673701
public function deleteService($apiKey)
    {
        ValidationUtility::ensureStringOrInteger('$apiKey', $apiKey);

        $this->callServiceOwnerDeleteApi(
            self::$SERVICE_DELETE_API_PATH . $apiKey);
    }
480779
public function setUrl(?string $url): void
	{
		if ($this->locale === null) {
			throw new InvalidArgumentException('Locale must be set before calling setUrl');
		}
		if ($this->isLink === null) {
			throw new InvalidArgumentException("'isLink' must be set before calling setUrl");
		}
		if (!$this->isLink && Strings::match($url, '/[^A-Za-z0-9_-]/')) {
			throw new InvalidArgumentException('URL contains invalid characters');
		}

		$completeUrl = !$this->isLink && $this->parent && $url !== null ?
			$this->parent->completeUrl . '/' . $url
			: $url;

		/* @var $repository PagesRepository */
		$repository = $this->getRepository();
		$page = $repository->getByUrl($completeUrl, $this->locale->name);
		if ($page !== null && $page !== $this) {
			throw new UniqueConstraintViolationException("Page with '$url' exists");
		}
		$this->url = $url;
	}
1328434
public function login($login, $api_key)
    {
        if (empty($login) || !is_string($login)) {
            throw new \InvalidArgumentException('Argument "login" cannot be empty and must be a string');
        }

        if (empty($login) || !is_string($api_key)) {
            throw new \InvalidArgumentException('Argument "api_key" cannot be empty and must be a string');
        }

        $this->auth = [
            'login'         => $login,
            'password_hash' => $api_key,
        ];
    }
185239
private function executeQuery(string $url): AddressCollection
    {
        $content = $this->getUrlContents($url);
        $json = json_decode($content, true);

        if (isset($json['error'])) {
            switch ($json['error']['code']) {
                case static::CODE_BAD_IP:
                    throw new InvalidArgument('The API call should include a valid IP address.');
                case static::CODE_BAD_KEY:
                    throw new InvalidCredentials('The API call should include a API key parameter.');
                case static::CODE_NOT_AUTHORIZED:
                    throw new InvalidCredentials('The API key associated with your request was not recognized.');
                case static::CODE_ACCOUNT_INACTIVE:
                    throw new InvalidCredentials('The API key has not been approved or has been disabled.');
                case static::CODE_LIMIT_EXCEEDED:
                    throw new QuotaExceeded('The service you have requested is over capacity.');
                default:
                    throw new InvalidServerResponse(sprintf(
                        'GeoIPs error %s%s%s%s - query: %s',
                        $json['error']['code'],
                        isset($json['error']['status']) ? ', '.$json['error']['status'] : '',
                        isset($json['error']['message']) ? ', '.$json['error']['message'] : '',
                        isset($json['error']['notes']) ? ', '.$json['error']['notes'] : '',
                        $url
                    ));
            }
        }

        if (!is_array($json) || empty($json) || empty($json['response']) || empty($json['response']['code'])) {
            throw InvalidServerResponse::create($url);
        }

        $response = $json['response'];

        // Check response code
        switch ($response['code']) {
            case static::CODE_SUCCESS:
                // everything is ok
                break;
            case static::CODE_NOT_FOUND:
                return new AddressCollection([]);
            default:
                throw new InvalidServerResponse(sprintf(
                    'The GeoIPs API returned unknown result code "%s" for query: "%s".',
                    $response['code'],
                    $url
                ));
        }

        // Make sure that we do have proper result array
        if (empty($response['location']) || !is_array($response['location'])) {
            return new AddressCollection([]);
        }

        $location = array_map(function ($value) {
            return '' === $value ? null : $value;
        }, $response['location']);

        $adminLevels = [];

        if (null !== $location['region_name'] || null !== $location['region_code']) {
            $adminLevels[] = [
                'name' => $location['region_name'],
                'code' => $location['region_code'],
                'level' => 1,
            ];
        }

        if (null !== $location['county_name']) {
            $adminLevels[] = [
                'name' => $location['county_name'],
                'level' => 2,
            ];
        }

        $results = Address::createFromArray([
            'providedBy' => $this->getName(),
            'country' => $location['country_name'],
            'countryCode' => $location['country_code'],
            'adminLevels' => $adminLevels,
            'locality' => $location['city_name'],
            'latitude' => $location['latitude'],
            'longitude' => $location['longitude'],
            'timezone' => $location['timezone'],
        ]);

        return new AddressCollection([$results]);
    }
795775
public function setApiKey($apiKey)
    {
        $apiKey = trim($apiKey);

        if (!preg_match('/^(live|test)_\w{30,}$/', $apiKey)) {
            throw new ApiException("Invalid API key: '{$apiKey}'. An API key must start with 'test_' or 'live_' and must be at least 30 characters long.");
        }

        $this->apiKey = $apiKey;
        $this->oauthAccess = false;
        return $this;
    }
882470
protected function apiRequest($url, $params = array()) {
        if(! isset($params['api_key']) && $this->hasAttribute('api_key'))
            $params['key'] = $this->getAttribute('api_key');

        $query = http_build_query($params, '&');

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url . '?' . $query);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }