public function setUp()
 {
     $configuration = (include __DIR__ . '/config.php');
     $client = new Client($configuration['contacts_login']);
     $client->setPasswordHash($configuration['contacts_password']);
     if ($this->proxy instanceof Native) {
         $proxy = new Native($configuration['contacts_host']);
     } else {
         $proxy = new Curl($configuration['contacts_host']);
     }
     $this->contactsFactory = new ContactsFactory($proxy, $this->getClient());
 }
 /**
  * Login
  *
  * @return SMSApi\Api\SmsFactory;
  */
 public function login()
 {
     $client = new Client($this->config['login']);
     $client->setPasswordHash(md5($this->config['password']));
     $proxy = null;
     if ($this->config['second_channel']) {
         $proxy = new Native('https://api2.smsapi.pl');
     }
     $smsapi = new SmsFactory($proxy);
     $smsapi->setClient($client);
     return $smsapi;
 }
 /**
  * @param $file
  * @return array
  */
 protected function prepareRequestHeaders($file)
 {
     $headers = array();
     $headers['User-Agent'] = 'smsapi-php-client';
     $headers['Accept'] = '';
     if ($this->isFileValid($file)) {
         $headers['Content-Type'] = 'multipart/form-data; boundary=' . $this->boundary;
     } else {
         $headers['Content-Type'] = 'application/x-www-form-urlencoded';
     }
     if ($this->basicAuthentication) {
         $headers['Authorization'] = 'Basic ' . base64_encode($this->basicAuthentication->getUsername() . ':' . $this->basicAuthentication->getPassword());
     }
     return $headers;
 }
Exemple #4
0
 /**
  * Prepare client configuration
  * @return SMSApi\Client
  * @throws ConfigurationException
  */
 private function getClient()
 {
     $login = $this->getParam('login');
     $passwordHash = $this->getParam('passwd_hash');
     $token = $this->getParam('token');
     if (empty($token) && (empty($login) || empty($passwordHash))) {
         throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "token" or "login" and "passwd_pash" parameters properly.');
     }
     $client = null;
     if (!empty($token)) {
         $client = Client::createFromToken($token);
     } else {
         $client = new Client($login);
         $client->setPasswordHash($passwordHash);
     }
     return $client;
 }
 /**
  * @return string
  */
 protected function paramsLoginToQuery()
 {
     return "username="******"&password=" . $this->client->getPassword();
 }