Unirest\Request::auth PHP Method

auth() public static method

Set authentication method to use
public static auth ( string $username = '', string $password = '', integer $method = CURLAUTH_BASIC )
$username string authentication username
$password string authentication password
$method integer authentication method
    public static function auth($username = '', $password = '', $method = CURLAUTH_BASIC)
    {
        self::$auth['user'] = $username;
        self::$auth['pass'] = $password;
        self::$auth['method'] = $method;
    }

Usage Example

 /**
  * Get list of searched contact list
  * @param  string     $q     Required parameter: Your keyword or query.
  * @return string response from the API call*/
 public function searchContactList($q)
 {
     //check that all required arguments are provided
     if (!isset($q)) {
         throw new \InvalidArgumentException("One or more required arguments were NULL.");
     }
     //the base uri for api requests
     $_queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $_queryBuilder = $_queryBuilder . '/search/contacts-lists';
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($_queryBuilder, array('q' => $q));
     //validate and preprocess url
     $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
     //prepare headers
     $_headers = array('user-agent' => 'ClickSendSDK');
     //set HTTP basic auth parameters
     Request::auth(Configuration::$username, Configuration::$key);
     //and invoke the API call request to fetch the response
     $response = Request::get($_queryUrl, $_headers);
     //Error handling using HTTP status codes
     if ($response->code == 400) {
         throw new APIException('BAD_REQUEST', 400, $response->body);
     } else {
         if ($response->code == 401) {
             throw new APIException('UNAUTHORIZED', 401, $response->body);
         } else {
             if ($response->code == 403) {
                 throw new APIException('FORBIDDEN', 403, $response->body);
             } else {
                 if ($response->code == 404) {
                     throw new APIException('NOT_FOUND', 404, $response->body);
                 } else {
                     if ($response->code == 405) {
                         throw new APIException('METHOD_NOT_FOUND', 405, $response->body);
                     } else {
                         if ($response->code == 429) {
                             throw new APIException('TOO_MANY_REQUESTS', 429, $response->body);
                         } else {
                             if ($response->code == 500) {
                                 throw new APIException('INTERNAL_SERVER_ERROR', 500, $response->body);
                             } else {
                                 if ($response->code < 200 || $response->code > 206) {
                                     //[200,206] = HTTP OK
                                     throw new APIException("HTTP Response Not OK", $response->code, $response->body);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response->body;
 }
All Usage Examples Of Unirest\Request::auth