예제 #1
0
 /**
  * Post message on shacknews.
  * Handles urlencoding
  * Optional parentid parameter, if replying to an existing post
  * @return int post id of succesful post
  * @throws Exception on parse or PRL error
  */
 public static function post($username, $password, $body, $parentId = null)
 {
     $fields = 'content_type_id=17&content_id=17';
     $fields .= '&body=' . urlencode($body);
     if (!empty($parentId)) {
         $fields .= '&parent_id=' . urlencode($parentId);
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, "ShackAPI 0.1");
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
     curl_setopt($ch, CURLOPT_URL, ShackAPI::apiUrl);
     $result = curl_exec($ch);
     return ShackApi::parseResponse($result);
 }
예제 #2
0
 private function post($post)
 {
     try {
         print "\n---------\n";
         print $post->body;
         print "\n---------\n";
         return ShackApi::post($this->username, $this->password, $post->body, $this->parentId);
     } catch (Exception $e) {
         print "--> exception while posting {$e}\n";
         while (true) {
             print "--> exception caused sleep 120 secs\n";
             sleep(120);
             return ShackApi::post($this->username, $this->password, $post->body, $this->parentId);
         }
     }
 }