token = $params; } elseif(is_array($params)) { $this->username = isset($params['username']) ? $params['username'] : ''; $this->password = isset($params['password']) ? $params['password'] : ''; } $this->ua = "Gubb.net PHP class v".$this->version." (http://avazio.com/gubb) - brandon (at) avazio (dot) com"; } function populateLists() { $this->lists = $this->submit("list/get_all", array('filter_status' => 'all') ); } function handleError($http_code, $error) { print "GUBB ERROR: (HTTP Code = $http_code) ".strip_tags($error)."
\n"; print_r($this); } function addItem($list, $note) { foreach($this->lists as $thislist) { if($thislist['id'] == $list || $thislist['name'] == $list) { print "Adding to list ".$thislist['id']."\n"; $this->submit('item/create', array( 'id' => $thislist['id'], 'note' => $note ) ); return true; } } print "List not found"; return false; } function submit($api_name, $params = '') { $ext = 'php'; $url = $this->api_base . "/$api_name.$ext"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, $this->ua); if($this->token) { $params['api_key'] = $this->token; }; $postfields = ''; foreach($params as $key => $value) { $postfields .= $key."=".urlencode($value)."&"; } // Get rid of the trailing & $postfields = preg_replace("/&$/", '', $postfields); curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $content_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE); curl_close($curl); if($http_code != 200) { $this->handleError($http_code, $content); return false; } else { return unserialize($content); } } } ?>