auth() public static méthode

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
 /**
  * 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;
 }
 /**
  * Get all referral accounts
  * @return string response from the API call*/
 public function getReferralAccounts()
 {
     //the base uri for api requests
     $_queryBuilder = Configuration::$BASEURI;
     //prepare query string for API call
     $_queryBuilder = $_queryBuilder . '/referral/accounts';
     //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;
 }
Exemple #3
0
 /**
  * @param Request $request
  *
  * @return Request
  */
 public function setupRequest(Request $request)
 {
     $request->auth($this->username, $this->password, $this->method);
     return $request;
 }
 /**
  * Reseller Account
  * @param  string     $clientUserId        Required parameter: Example: 
  * @param  string     $username            Required parameter: Example: 
  * @param  string     $password            Required parameter: Example: 
  * @param  string     $userEmail           Required parameter: Example: 
  * @param  string     $userPhone           Required parameter: Example: 
  * @param  string     $userFirstName       Required parameter: Example: 
  * @param  string     $userLastName        Required parameter: Example: 
  * @param  string     $accountName         Required parameter: Example: 
  * @param  string     $country             Required parameter: Example: 
  * @return string response from the API call*/
 public function updateResellerAccount($clientUserId, $username, $password, $userEmail, $userPhone, $userFirstName, $userLastName, $accountName, $country)
 {
     //check that all required arguments are provided
     if (!isset($clientUserId, $username, $password, $userEmail, $userPhone, $userFirstName, $userLastName, $accountName, $country)) {
         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 . '/reseller/accounts/{client_user_id}';
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array('client_user_id' => $clientUserId));
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($_queryBuilder, array('username' => $username, 'password' => $password, 'user_email' => $userEmail, 'user_phone' => $userPhone, 'user_first_name' => $userFirstName, 'user_last_name' => $userLastName, 'account_name' => $accountName, 'country' => $country));
     //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::put($_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;
 }
 /**
  * RazorpayClient constructor.
  * @param $key
  * @param $secret
  */
 public function __construct($key, $secret)
 {
     $this->key = $key;
     $this->secret = $secret;
     Request::auth($this->key, $this->secret);
 }
 public function testBasicAuthentication()
 {
     Request::auth('user', 'password');
     $response = Request::get('http://mockbin.com/request');
     $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $response->body->headers->authorization);
 }
 /**
  * Update subaccount
  * @param  int             $subaccountId         Required parameter: Example: 
  * @param  string|null     $password             Optional parameter: Example: 
  * @param  string|null     $email                Optional parameter: Example: 
  * @param  string|null     $phoneNumber          Optional parameter: Example: 
  * @param  string|null     $firstName            Optional parameter: Example: 
  * @param  string|null     $lastName             Optional parameter: Example: 
  * @param  bool|null       $accessUsers          Optional parameter: Example: true
  * @param  bool|null       $accessBilling        Optional parameter: Example: true
  * @param  bool|null       $accessReporting      Optional parameter: Example: true
  * @param  bool|null       $accessContacts       Optional parameter: Example: false
  * @param  bool|null       $accessSettings       Optional parameter: Example: true
  * @return string response from the API call*/
 public function updateSubaccount($subaccountId, $password = NULL, $email = NULL, $phoneNumber = NULL, $firstName = NULL, $lastName = NULL, $accessUsers = true, $accessBilling = true, $accessReporting = true, $accessContacts = false, $accessSettings = true)
 {
     //check that all required arguments are provided
     if (!isset($subaccountId)) {
         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 . '/subaccounts/{subaccount_id}';
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array('subaccount_id' => $subaccountId));
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($_queryBuilder, array('password' => $password, 'email' => $email, 'phone_number' => $phoneNumber, 'first_name' => $firstName, 'last_name' => $lastName, 'access_users' => null != $accessUsers ? var_export($accessUsers, true) : true, 'access_billing' => null != $accessBilling ? var_export($accessBilling, true) : true, 'access_reporting' => null != $accessReporting ? var_export($accessReporting, true) : true, 'access_contacts' => null != $accessContacts ? var_export($accessContacts, true) : false, 'access_settings' => null != $accessSettings ? var_export($accessSettings, true) : true));
     //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::put($_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;
 }