Example #1
0
 public function post($url, $data, $headers = array())
 {
     $success = false;
     for ($i = 0; $i < $this->retries && !$success; $i++) {
         try {
             $result = parent::post($url, $data, $headers);
             $success = true;
         } catch (Exception $e) {
             $success = false;
         }
     }
     if (!$success) {
         throw $e;
     }
     return $result;
 }
Example #2
0
 /**
  * Gets a new API key from the bridge
  * Hint: You have to press the button on the bridge first and then
  * call this function
  *
  * @param $bridgeAddress string The IP or FQDN to the hue bridge
  * @return string with the API key
  * @throws HueError If no connection to the bridge could be established
  *          or the bridge refused to give one
  * @throws InvalidArgumentException If the bridge address is not valid
  **/
 public static function fetchAPIAccessKey($bridgeAddress)
 {
     if (strlen($bridgeAddress) == 0) {
         throw new InvalidArgumentException('Parameter $bridgeAddress is empty');
     }
     $pest = new Pest('http://' . $bridgeAddress . '/api');
     $data = json_encode(array('devicetype' => 'phpHue'));
     $result = json_decode($pest->post('', $data), true);
     if (is_null($result)) {
         throw new HueError('No connection to the Hue bridge');
     } else {
         if (array_key_exists('error', $result[0])) {
             throw new HueError($result[0]['error']['description']);
         } else {
             if (array_key_exists('success', $result[0])) {
                 return $result[0]['success']['username'];
             } else {
                 throw new HueError('Something went terribly bad. Should not happen');
             }
         }
     }
 }
Example #3
0
 /**
  * Perform an HTTP POST
  *
  * @param string $url
  * @param array $data
  * @param array $headers
  * @return string
  */
 public function post($url, $data, $headers = array())
 {
     return parent::post($url, $this->jsonEncode($data), $headers);
 }
Example #4
0
 /**
  * Отправка SMS-сообщения нескольким адрессатам
  *
  * @access public
  * @static
  *
  * @param string  $sessionID ID сессии. @see getSessionID_St
  * @param string  $sourceAddres отправитель. До 11 латинских символов или до 15 цифровых.
  * @param array   $destinationAddresses массив строк адресов назначения. (Код страны+код сети+номер телефона, Пример: 79031234567
  * @param string  $data Текст сообщения
  * @param mixed   $sendDate дата отправки сообщения. Строка вида (YYYY-MM-DDTHH:MM:SS) или Timestamp. Необязательный параметр.
  * @param integer $validity Время жизни сообщения в минутах. Необязательный параметр
  * 
  * @return array массив идентификаторов сообщений
  * @throws SMSError_Exception
  */
 public static function sendBulk_St($sessionID, $sourceAddres, $destinationAddresses, $data, $sendDate = null, $validity = 0)
 {
     if (gettype($destinationAddresses) == "string") {
         $destinationAddresses = array($destinationAddresses);
     }
     $pest = new Pest(SMSClient::m_baseURL);
     $result = array();
     try {
         $result = json_decode($pest->post('/Sms/SendBulk', SMSClient::createRequestParameters($sessionID, $sourceAddres, $destinationAddresses, $data, $sendDate, $validity)), true);
     } catch (Exception $e) {
         $errorInfo = json_decode($e->getMessage());
         unset($pest);
         throw new SMSError_Exception($errorInfo->Desc, $errorInfo->Code);
     }
     unset($pest);
     return $result;
 }
Example #5
0
$phonenumber = "4712345678";
// Modify to a valid mobile number.
$description = "This info was input with a REST PUT request";
$messagetext = "Hello! This message was sent by posting to the Intouch REST API.";
$sendernumber = "IntouchAPI";
// Must be a valid sendernumber set up for your account
// Setting up Pest with URL for the Intouch API and basic HTTP authentication
require_once '../Pest.php';
$pest = new Pest('http://intouchapi.pswin.com/1/');
$pest->setupAuth($user . "@" . $logindomain, $password);
$pest->curl_opts[CURLOPT_FOLLOWLOCATION] = false;
// Not supported on hosts running safe_mode!
echo "<h1>1. Creating a contact in the address book</h1>";
try {
    $contactdata = array('Firstname' => $firstname, 'Lastname' => $lastname, 'PhoneNumber' => $phonenumber);
    $contactjson = $pest->post('/contacts', $contactdata);
    $contactarray = json_decode($contactjson, true);
    $contactId = $contactarray[ContactId];
    echo "<br>Created contact with id: " . $contactId;
} catch (Exception $e) {
    echo "<br>Caught exception when creating contact : " . $e->getMessage() . "<br>";
}
echo "<h1>2. Getting the contact by its phonenumber and updating it.</h1>";
try {
    $contactjson = $pest->get('/contacts/phonenumber/' . $phonenumber);
    $contactarray = json_decode($contactjson, true);
    echo "<br>Retrieved contact with id: " . $contactarray[ContactId] . ", should be identical with " . $contactId . " from part 1.<br>";
    $contactarray[Description] = $description;
    $contactjson = json_encode($contactarray);
    $pest->put('/contacts/' . $contactarray[ContactId], $contactjson);
    echo "<br>Updated contact<br>";
Example #6
0
 public function post($url, $data, $headers = array())
 {
     return parent::post($url, $data, $headers);
 }
Example #7
0
 public function get_keys()
 {
     // Generate merchant hash code
     $hash = HashGenerator::generate($this->merchant_id, $this->merchant_hash_key, $this->settlement_type, $this->order_id, $this->gross_amount);
     // populate parameters for the post request
     $data = array('SETTLEMENT_TYPE' => '01', 'MERCHANT_ID' => $this->merchant_id, 'ORDER_ID' => $this->order_id, 'SESSION_ID' => $this->session_id, 'GROSS_AMOUNT' => $this->gross_amount, 'PREVIOUS_CUSTOMER_FLAG' => $this->previous_customer_flag, 'CUSTOMER_STATUS' => $this->customer_status, 'MERCHANTHASH' => $hash, 'PROMO_ID' => $this->promo_id, 'CUSTOMER_SPECIFICATION_FLAG' => $this->billing_address_different_with_shipping_address, 'EMAIL' => $this->email, 'FIRST_NAME' => $this->first_name, 'LAST_NAME' => $this->last_name, 'POSTAL_CODE' => $this->postal_code, 'ADDRESS1' => $this->address1, 'ADDRESS2' => $this->address2, 'CITY' => $this->city, 'COUNTRY_CODE' => $this->country_code, 'PHONE' => $this->phone, 'SHIPPING_FLAG' => $this->required_shipping_address, 'SHIPPING_FIRST_NAME' => $this->shipping_first_name, 'SHIPPING_LAST_NAME' => $this->shipping_last_name, 'SHIPPING_ADDRESS1' => $this->shipping_address1, 'SHIPPING_ADDRESS2' => $this->shipping_address2, 'SHIPPING_CITY' => $this->shipping_city, 'SHIPPING_COUNTRY_CODE' => $this->shipping_country_code, 'SHIPPING_POSTAL_CODE' => $this->shipping_postal_code, 'SHIPPING_PHONE' => $this->shipping_phone, 'SHIPPING_METHOD' => $this->shipping_method, 'CARD_NO' => $this->card_no, 'CARD_EXP_DATE' => $this->card_exp_date, 'FINISH_PAYMENT_RETURN_URL' => $this->finish_payment_return_url, 'UNFINISH_PAYMENT_RETURN_URL' => $this->unfinish_payment_return_url, 'ERROR_PAYMENT_RETURN_URL' => $this->error_payment_return_url, 'LANG_ENABLE_FLAG' => $this->lang_enable_flag, 'LANG' => $this->lang, 'enable_3d_secure' => $this->enable_3d_secure);
     // data query string only without commodity
     $query_string = http_build_query($data);
     // Build Commodity
     if (isset($this->commodity)) {
         $commodity_query_string = $this->build_commodity_query_string($this->commodity);
         $query_string = "{$query_string}&{$commodity_query_string}";
     }
     // Build Installment Banks
     if (isset($this->installment_banks)) {
         foreach ($this->installment_banks as $bank) {
             $query_string = "{$query_string}&installment_banks[]={$bank}";
         }
     }
     // Build Installment Terms
     if (isset($this->installment_terms)) {
         foreach ($this->installment_terms as $install) {
             $query_string = "{$query_string}&installment_terms[]={$install}";
         }
     }
     // Build Promo Bins
     if (isset($this->promo_bins)) {
         foreach ($this->promo_bins as $bin) {
             $query_string = "{$query_string}&promo_bins[]={$bin}";
         }
     }
     // Build Point Banks
     if (isset($this->point_banks)) {
         foreach ($this->point_banks as $bank) {
             $query_string = "{$query_string}&point_banks[]={$bank}";
         }
     }
     $client = new Pest(self::REQUEST_KEY_URL);
     $result = $client->post('', $query_string);
     $key = $this->extract_keys_from($result);
     return $key;
 }
function post_data($data_array)
{
    $CI =& get_instance();
    $CI->load->model('sync_server/sync_server_model', 'plugin_model');
    $config = $CI->plugin_model->get_rest_server_url()->row();
    $rest_client = new Pest($config->rest_server_url);
    $result = $rest_client->post('/sync_sms', $data_array);
    return $result;
}