예제 #1
0
파일: DieselUp.php 프로젝트: xcopy/dieselup
 /**
  * @throws ErrorException
  * @throws LengthException
  */
 protected function post()
 {
     // get arguments
     $argv = $_SERVER['argv'];
     // remove first argument (i.e. path)
     array_shift($argv);
     if (!count($argv)) {
         // topic ID is required argument
         throw new \LengthException('Not enough arguments');
     }
     // request topic page
     $response = $this->request(static::getUrl(['showtopic' => $argv[0]]));
     $document = new \DOMDocument();
     $document->loadHTML($response);
     $xpath = new \DomXpath($document);
     // find latest post(s)
     $deleteLinks = $xpath->query('//a[contains(@href, "javascript:delete_post")]');
     // any posts?
     // todo: delete ONLY "UP" post
     if ($deleteLinks->length) {
         /** @var $lastLink \DOMElement */
         $lastLink = $deleteLinks->item($deleteLinks->length - 1);
         preg_match('/https?:[^\']+/', $lastLink->getAttribute('href'), $matches);
         // delete last UP post
         if (!empty($matches)) {
             $this->output->writeln('<comment>Deleting last UP</comment>');
             $this->request($matches[0]);
         }
     }
     $replyParams = ['Post' => 'UP'];
     $replyForms = $xpath->query('//form[contains(@name, "REPLIER")]');
     $hiddenInputs = $xpath->query('.//input[contains(@type, "hidden")]', $replyForms->item(0));
     foreach ($hiddenInputs as $input) {
         /** @var $input \DOMElement */
         $replyParams[$input->getAttribute('name')] = $input->getAttribute('value');
     }
     $this->output->writeln('<info>Posting new UP</info>');
     // and reply new UP post
     $this->request(static::getUrl(), Method::POST, Body::form($replyParams));
 }
예제 #2
0
 /**
  * Create inbound sms
  * @param  string     $url     Required parameter: Your url
  * @return string response from the API call*/
 public function createInboundSms($url)
 {
     //check that all required arguments are provided
     if (!isset($url)) {
         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 . '/sms/inbound';
     //validate and preprocess url
     $_queryUrl = APIHelper::cleanUrl($_queryBuilder);
     //prepare headers
     $_headers = array('user-agent' => 'ClickSendSDK');
     //prepare parameters
     $_parameters = array('url' => $url);
     //set HTTP basic auth parameters
     Request::auth(Configuration::$username, Configuration::$key);
     //and invoke the API call request to fetch the response
     $response = Request::post($_queryUrl, $_headers, Request\Body::form($_parameters));
     //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;
 }