├── EntryArgs.php ├── README.markdown ├── WufooApiExamples.php ├── WufooApiWrapper.php ├── WufooApiWrapperBase.php ├── WufooValueObjects.php └── index.php /EntryArgs.php: -------------------------------------------------------------------------------- 1 | getFilterString(); 30 | } 31 | 32 | /** 33 | * gets the query string for your entry args. 34 | * 35 | * @return void 36 | * @author Timothy S Sabat 37 | */ 38 | public function getArgsAsQueryString() { 39 | foreach ($this as $key => $value) { 40 | if(is_array($key)) { 41 | $ret.= $this->getNumeredFilters().'&'; 42 | } else { 43 | if ($value) $ret.= $key.'='.$value.'&'; 44 | } 45 | } 46 | return rtrim($ret, '&'); 47 | } 48 | 49 | private function getNumeredFilters() { 50 | $count = 1; 51 | foreach ($this->filters as $filter) { 52 | $ret.='Filter'.$count.'='.$filter.'&'; 53 | $count++; 54 | } 55 | return rtrim($ret, '&'); 56 | } 57 | 58 | /** 59 | * sets the start page for your args 60 | * 61 | * @param int $pageStart the page you want to begin from 62 | * @return void 63 | * @author Timothy S Sabat 64 | */ 65 | public function setPageStart($pageStart) { 66 | if (!is_numeric($pageStart)) 67 | throw new WufooException('Page start must be numeric. You chose: '.$pageStart, '400'); 68 | if ($pageStart < 0) 69 | throw new WufooException('Page start must be zero or greater: '.$pageStart, '400'); 70 | $this->pageStart = floor($pageStart); 71 | } 72 | 73 | /** 74 | * sets the page size 75 | * 76 | * @param int $pageSize between 1 and 100 inclusive 77 | * @return void 78 | * @author Timothy S Sabat 79 | */ 80 | public function setPageSize($pageSize) { 81 | if (!is_numeric($pageSize)) 82 | throw new WufooException('Page size must be numeric. You chose: '.$pageSize, '400'); 83 | if ($pageSize < 1) 84 | throw new WufooException('Page size must be one or greater. You chose: '.$pageSize, '400'); 85 | if ($pageSize > 100) 86 | throw new WufooException('Page size must be less than 100. You chose: '.$pageSize, '400'); 87 | $this->pageSize = floor($pageSize); 88 | } 89 | 90 | /** 91 | * Sets the field on which you wish to filter 92 | * 93 | * @param string int $id the ID value of the field, as gathered from WufooApiWrapper::getFields 94 | * @return void 95 | * @author Timothy S Sabat 96 | */ 97 | public function setSort($id) { 98 | $this->sort = $sort; 99 | } 100 | 101 | /** 102 | * Sets the sort direction for your filters 103 | * 104 | * @param string $direction either ASC or DESC 105 | * @return void 106 | * @author Timothy S Sabat 107 | */ 108 | public function setSortDirection($direction) { 109 | if ($direction != 'ASC' || $direction != 'DESC') 110 | throw new WufooException('Sort Direction must be either ASC or DESC. You chose: '.$direction, '400'); 111 | $this->sortDirection = floor($direction); 112 | } 113 | 114 | /** 115 | * Sets the match type 116 | * 117 | * @param string $match either AND or OR 118 | * @return void 119 | * @author Timothy S Sabat 120 | */ 121 | public function setMatch($match) { 122 | if (strtolower($match) !== 'and' || strtolower($match) !== 'or') { 123 | throw new WufooException('Invalid match. You chose: '.$match.'. Match may only be AND or OR', '400'); 124 | } 125 | } 126 | 127 | } 128 | 129 | /** 130 | * You don't need to directly call this class. Used to encapsulate the filter string. 131 | * 132 | * @package default 133 | * @author Timothy S Sabat 134 | */ 135 | class Filter { 136 | 137 | private $id; 138 | private $operator; 139 | private $value; 140 | 141 | public function __construct($id, $operator, $value) { 142 | $this->id = str_replace('Filter', '', $id); 143 | $this->operator = $operator; 144 | $this->value = $value; 145 | } 146 | 147 | public function getFilterString() { 148 | return $this->getField().'+'.$this->getOperator().'+'.$this->getValue(); 149 | } 150 | 151 | private function getField() { 152 | $ret = $this->id; 153 | if (is_numeric($this->id)) { 154 | $ret = 'Field'.$this->id; 155 | } 156 | return $ret; 157 | } 158 | 159 | private function getOperator() { 160 | 161 | $ret = strtolower(str_replace('_', ' ', $this->operator)); 162 | if (in_array($ret, $this->getWhiteList())) { 163 | $ret = str_replace(' ', '_', $ret); 164 | $ret = str_replace('_null', '_NULL', $ret); 165 | } else { 166 | throw new WufooException('Invalid Filter Operator: '.$this->operator, '400'); 167 | } 168 | return ucfirst($ret); 169 | } 170 | 171 | private function getValue() { 172 | return urlencode($this->value); 173 | } 174 | 175 | private function getWhiteList() { 176 | return array( 177 | 'contains', 'does not contain', 'begins with', 'ends with', 178 | 'is less than', 'is greater than', 'is on', 'is before', 'is after', 179 | 'is not equal to', 'is equal to', 'is not null'); 180 | } 181 | 182 | 183 | } 184 | ?> -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | 19 | ###Wufoo PHP API Wrapper 20 | 21 | The Wufoo PHP API plugin is meant to help make working with the Wufoo API easier for PHP developers. It doesn't do anything that working directly with the API can't do, it just provides an abstraction layer making getting the information you need easier. 22 | 23 | ### WufooApiExamples.php 24 | 25 | The download comes with a file called WufooApiExamples.php. This file is simply shows how each API call is made. To test out Wufoo APIs, instantiate this class with your API Key and Subdomain, then try making calls to the public methods. You can `print_r` the resulting values to see what comes back from a successful (or failing) API call. 26 | 27 | ### Basics 28 | 29 | The API Wrapper is a collection of functions each for using a specific API. For example, this is how you would get data on your account's users: 30 | 31 | $wrapper = new WufooApiWrapper($apiKey, $subdomain); 32 | print_r($wrapper->getUsers()); 33 | 34 | Some APIs need more information to be able to return the information they are supposed to. For example, the Entries API needs to know what form to return data from. Each will be documented below. 35 | 36 | ### Full API Documentation 37 | 38 | Available here: http://wufoo.com/docs/api/v3/ 39 | 40 | Each API returns its own set of specific information which is all documented on Wufoo.com for reference. 41 | 42 | ### Users 43 | 44 | Information about all users: 45 | 46 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain')); //create the class 47 | print_r($wrapper->getUsers()); 48 | 49 | Full documentation: http://wufoo.com/docs/api/v3/users/ 50 | 51 | ### Forms 52 | 53 | Information about all forms: 54 | 55 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 56 | print_r($wrapper->getForms($identifier = null)); //No identifier needed to retrieve all forms, otherwise pass in a form URL or hash 57 | 58 | Information about a specific form: 59 | 60 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 61 | print_r($wrapper->getForms($identifier = 'k4j9jw')); //Identifier can be either a form hash or form URL. 62 | 63 | Full documentation: http://wufoo.com/docs/api/v3/forms/ 64 | 65 | ### Entries 66 | 67 | Entries from a form: 68 | 69 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 70 | print_r($wrapper->getEntries('k4j9jw', 'forms', 'Filter1=EntryId+Is_equal_to+1')); //Notice the filter 71 | 72 | Entries from a report: 73 | 74 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 75 | print_r($wrapper->getReportEntries('k4j9jw', 'Filter1=EntryId+Is_equal_to+1')); //Notice the filter 76 | 77 | Entries POST to a form: 78 | 79 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 80 | //NOTE: Create WufooSubmitFields for the $postArray values 81 | $postArray = array(new WufooSubmitField('Field1', 'Booyah!'), new WufooSubmitField('Field1', '/files/myFile.txt', $isFile = true)); 82 | print_r($wrapper->entryPost('f83u4d', $postArray)); 83 | 84 | Full documentation: http://wufoo.com/docs/api/v3/forms/post/ 85 | Full documentation: http://wufoo.com/docs/api/v3/entries/ 86 | 87 | ### Fields 88 | 89 | Fields of a form: 90 | 91 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 92 | print_r($wrapper->getFields('j9js9r')); //Identifier is a form URL or hash 93 | 94 | Fields of a report: 95 | 96 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 97 | print_r($wrapper->getReportFields('j9js9r')); //Identifier is a reporyt URL or hash 98 | 99 | Bear in mind that fields may have `SubFields`, as is the case when using Wufoo-provided fields like Name, which has First and Last as subfields. Testing for SubFields and looping through those within the main loop while processing the data is a good idea. 100 | 101 | Full documentation: http://wufoo.com/docs/api/v3/fields/ 102 | 103 | ### Comments 104 | 105 | Comments are entered in the Wufoo.com Entry Manager. 106 | 107 | Get comments from a form: 108 | 109 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 110 | print_r($wrapper->getComments('j9js9r', $entryId = '1')); //You may remove the $entryId parameter to get all comments for a form by EntryId. 111 | 112 | Full documentation: http://wufoo.com/docs/api/v3/comments/ 113 | 114 | ### Reports 115 | 116 | Information about all reports: 117 | 118 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 119 | print_r($wrapper->getReports()); 120 | 121 | Information about single form: 122 | 123 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 124 | print_r($wrapper->getReports('a5u8r9')); 125 | 126 | Full documentation: http://wufoo.com/docs/api/v3/reports/ 127 | 128 | ###Web Hook 129 | 130 | Add a Web Hook to a form: 131 | 132 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 133 | print_r($wrapper->webHookPut('a5u8r9', 'http://coolguy.com/webhooker/', 'key', $metadata = false); 134 | 135 | Delete a Web Hook from a form: 136 | 137 | $wrapper = new WufooApiWrapper('KUUI-22JI-ENID-IREW', 'yoursubdomain'); //create the class 138 | print_r($wrapper->webHookDelete($formIdentifier = '432j83j', $hash = 'a5u8r9')); 139 | 140 | Full documentation: http://wufoo.com/docs/api/v3/webhooks/ 141 | -------------------------------------------------------------------------------- /WufooApiExamples.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 18 | $this->subdomain = $subdomain; 19 | $this->domain = $domain; 20 | } 21 | 22 | public function getForms($identifier = null) { 23 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 24 | return $wrapper->getForms($identifier); 25 | } 26 | 27 | public function getFields($identifier) { 28 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 29 | return $wrapper->getFields($identifier); 30 | } 31 | 32 | public function getEntries($identifier) { 33 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 34 | return $wrapper->getEntries($identifier); 35 | } 36 | 37 | public function getEntryCount($identifier) { 38 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 39 | return $wrapper->getEntryCount($identifier); 40 | } 41 | 42 | public function getUsers() { 43 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 44 | return $wrapper->getUsers(); 45 | } 46 | 47 | public function getReports($identifier = null) { 48 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 49 | return $wrapper->getReports($identifier); 50 | } 51 | 52 | public function getWidgets($identifier) { 53 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 54 | return $wrapper->getWidgets($identifier); 55 | } 56 | 57 | public function getReportFields($identifier) { 58 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 59 | return $wrapper->getReportFields($identifier); 60 | } 61 | 62 | public function getReportEntries($identifier) { 63 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 64 | return $wrapper->getReportEntries($identifier); 65 | } 66 | 67 | public function getReportEntryCount($identifier) { 68 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 69 | return $wrapper->getReportEntryCount($identifier); 70 | } 71 | 72 | public function getComments($identifier) { 73 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 74 | return $wrapper->getComments($identifier); 75 | } 76 | 77 | public function entryPost($identifier, $postArray = '') { 78 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 79 | $postArray = array(new WufooSubmitField('Field1', 'Booyah!'), new WufooSubmitField('Field1', '/files/myFile.txt', $isFile = true)); 80 | return $wrapper->entryPost($identifier, $postArray); 81 | } 82 | 83 | public function webHookPut($identifier, $urlToAdd, $handshakeKey, $metadata = false) { 84 | $wrapper = new WufooApiWrapper($this->apiKey, $this->subdomain, $this->domain); 85 | return $wrapper->webHookPut($identifier, $urlToAdd, $handshakeKey, $metadata = false); 86 | } 87 | 88 | } 89 | 90 | ?> -------------------------------------------------------------------------------- /WufooApiWrapper.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 28 | $this->subdomain = $subdomain; 29 | $this->domain = $domain; 30 | } 31 | 32 | /* ------------------------------- 33 | PUBLIC GET CALLS 34 | ------------------------------- */ 35 | 36 | /** 37 | * Gets all permitted users. See http://wufoo.com/docs/api/v3/users/ 38 | * 39 | * @return array of User Value Objects by Hash 40 | * @author Timothy S Sabat 41 | */ 42 | public function getUsers() { 43 | $url = $this->getFullUrl('users'); 44 | return $this->getHelper($url, 'User', 'Users'); 45 | } 46 | 47 | /** 48 | * Gets all forms permitted to user. 49 | * 50 | * @param string $formIdentifier can be the url or hash. Remember, the URL changes with the form title, so it's best to use the hash. 51 | * @return array of Form Value Objects by hash 52 | * @author Timothy S Sabat 53 | */ 54 | public function getForms($formIdentifier = null) { 55 | $url = ($formIdentifier) ? $this->getFullUrl('forms/'.$formIdentifier) : $this->getFullUrl('forms'); 56 | return $this->getHelper($url, 'Form', 'Forms'); 57 | } 58 | 59 | /** 60 | * Gets all fields for a given form or report by url or hash. Remember, the URL changes with the form/report title, so it's best to use the hash. 61 | * 62 | * @param string $formIdentifier A URL or Hash 63 | * @param string $from can be left as 'forms'. The call getReportFields uses this parameter. 64 | * @return WufooFieldCollection Value Object 65 | * @author Timothy S Sabat 66 | */ 67 | public function getFields($formIdentifier, $from = 'forms') { 68 | $url = $this->getFullUrl($from.'/'.$formIdentifier.'/fields'); 69 | $this->curl = new WufooCurl(); 70 | $fields = json_decode($this->curl->getAuthenticated($url, $this->apiKey)); 71 | $fieldHelper = new WufooFieldCollection(); 72 | 73 | foreach ($fields->Fields as $field) { 74 | $fieldHelper->Fields[$field->ID] = new WufooField($field); 75 | $fieldHelper->Hash[$field->ID] = $field; 76 | if ($field->SubFields) { 77 | foreach ($field->SubFields as $subfield) { 78 | $fieldHelper->Hash[$subfield->ID] = $subfield; 79 | } 80 | } 81 | } 82 | return $fieldHelper; 83 | } 84 | 85 | /** 86 | * Gets all entries from a given form or report by url or hash. Remember, the URL changes with the form/report title, so it's best to use the hash. 87 | * 88 | * @param string $identifier a URL or Hash 89 | * @param string $from can be left as 'forms'. The call getReportFields uses this parameter. 90 | * @param string $getArgs a URL encoded string to filter entries. 91 | * @param string $index determines the key of the return hash 92 | * @return array of Form/Report Value Objects by hash 93 | * @author Timothy S Sabat 94 | */ 95 | public function getEntries($identifier, $from = 'forms', $getArgs = '', $index = 'EntryId') { 96 | $url = $this->getFullUrl($from.'/'.$identifier.'/entries'); 97 | $url.= ($getArgs) ? '?'. ltrim($getArgs, '?') : ''; 98 | return $this->getHelper($url, 'Entry', 'Entries', $index); 99 | } 100 | 101 | /** 102 | * Gets entry count for a given form or report by url or hash. Remember, the URL changes with the form/report title, so it's best to use the hash. 103 | * 104 | * @param string $identifier a URL or Hash 105 | * @param string $from can be left as 'forms'. The call getReportFields uses this parameter. 106 | * @param string $getArgs a URL encoded string to filter entries. 107 | * @return int entry count 108 | * @author Timothy S Sabat 109 | */ 110 | public function getEntryCount($identifier, $from = 'forms', $getArgs = '') { 111 | $url = $this->getFullUrl($from.'/'.$identifier.'/entries/count'); 112 | $url.= ($getArgs) ? '?'. ltrim($getArgs, '?') : ''; 113 | $this->curl = new WufooCurl(); 114 | $countObject = json_decode($this->curl->getAuthenticated($url, $this->apiKey)); 115 | return $countObject->EntryCount; 116 | } 117 | 118 | /** 119 | * Gets the entry count for a specific day. 120 | * 121 | * 122 | * @param string $identifier a URL or Hash 123 | * @return int today's entry count 124 | * @author Baylor Rae' 125 | */ 126 | public function getEntryCountToday($identifier) { 127 | $url = $this->getFullUrl($from.'/'.$identifier) . '?includeTodayCount=true'; 128 | $this->curl = new WufooCurl(); 129 | $countObject = json_decode($this->curl->getAuthenticated($url, $this->apiKey)); 130 | 131 | $ret = 0; 132 | if (isset($countObject->EntryCountToday)) { 133 | $ret = $countObject->EntryCountToday; 134 | } elseif (isset($countObject->Forms[0]->EntryCountToday)) { 135 | $ret = $countObject->Forms[0]->EntryCountToday; 136 | } 137 | 138 | return $ret; 139 | } 140 | 141 | /** 142 | * Gets all reports permitted to user. 143 | * 144 | * @param string $reportIdentifier can be the url or hash. Remember, the URL changes with the report title, so it's best to use the hash. 145 | * @return array of Report Value Objects by hash. 146 | * @author Timothy S Sabat 147 | */ 148 | public function getReports($reportIdentifier) { 149 | $url = ($reportIdentifier) ? $this->getFullUrl('reports/'.$reportIdentifier) : $this->getFullUrl('reports'); 150 | return $this->getHelper($url, 'Report', 'Reports'); 151 | } 152 | 153 | /** 154 | * Gets all widgets permitted to user. 155 | * 156 | * @param string string $reportIdentifier can be the url or hash. Remember, the URL changes with the report title, so it's best to use the hash. 157 | * @return array of Widget Value Objects by hash. 158 | * @author Timothy S Sabat 159 | */ 160 | public function getWidgets($reportIdentifier) { 161 | $url = $this->getFullUrl('reports/'.$reportIdentifier.'/widgets'); 162 | return $this->getHelper($url, 'Widget', 'Widgets'); 163 | } 164 | 165 | /** 166 | * Gets all fields for a given report by url or hash. Notice this is a facade for getFields() call. 167 | * 168 | * @param string $reportIdentifier can be the url or hash. Remember, the URL changes with the report title, so it's best to use the hash. 169 | * @return array of Field Value Objects by hash. 170 | * @author Timothy S Sabat 171 | */ 172 | public function getReportFields($reportIdentifier) { 173 | return $this->getFields($reportIdentifier, 'reports'); 174 | } 175 | 176 | /** 177 | * Gets all entries for a given report by url or hash. Notice this is a facade for getFields() call. 178 | * 179 | * @param string $reportIdentifier can be the url or hash. Remember, the URL changes with the report title, so it's best to use the hash. 180 | * @param string $getArgs a URL encoded string to filter entries. 181 | * @return array of Entry Value Objects by EntryId. 182 | * @author Timothy S Sabat 183 | */ 184 | public function getReportEntries($reportIdentifier, $getArgs = '') { 185 | return $this->getEntries($reportIdentifier, 'reports', $getArgs); 186 | } 187 | 188 | /** 189 | * Gets entry count for a given report by url or hash. Notice this is a facade for getEntryCount. 190 | * 191 | * @param string $reportIdentifier can be the url or hash. Remember, the URL changes with the report title, so it's best to use the hash. 192 | * @param string $getArgs a URL encoded string to filter entries. 193 | * @return array of Entry Value Objects by EntryId. 194 | * @author Timothy S Sabat 195 | */ 196 | public function getReportEntryCount($reportIdentifier, $getArgs = '') { 197 | return $this->getEntryCount($reportIdentifier, 'reports', $getArgs); 198 | } 199 | 200 | /** 201 | * Gets comments for a given form and (optionally) entry. 202 | * 203 | * @param string $formIdentifier 204 | * @param string $entryId (optional). If provided, narrows the filter to the entry id. 205 | * @return array of Comment Value Objects by EntryId 206 | * @author Timothy S Sabat 207 | */ 208 | public function getComments($formIdentifier, $entryId = null) { 209 | if ($entryId) { 210 | $url = $this->getFullUrl('forms/'.$formIdentifier.'/comments/'.$entryId); 211 | } else { 212 | $url = $this->getFullUrl('forms/'.$formIdentifier.'/comments'); 213 | } 214 | return $this->getHelper($url, 'Comment', 'Comments', 'CommentId'); 215 | } 216 | 217 | /** 218 | * submits an entry to your form 219 | * 220 | * @param string $formIdentifier a URL or Hash 221 | * @param string $wufooSubmitFields an associative array containing array('FieldX' => Y) 222 | * @return an object containing info about your submission or submission failure 223 | * @author Timothy S Sabat 224 | */ 225 | public function entryPost($formIdentifier, $wufooSubmitFields) { 226 | $url = $this->getFullUrl('forms/'.$formIdentifier.'/entries'); 227 | $postParams = array(); 228 | foreach ($wufooSubmitFields as $field) { 229 | $postParams[$field->getId()] = $field->getValue(); 230 | } 231 | $curl = new WufooCurl(); 232 | $response = $curl->postAuthenticated($postParams, $url, $this->apiKey); 233 | return new PostResponse($response); 234 | } 235 | 236 | /** 237 | * returns an API key for a given email, password, 238 | * 239 | * @param string $email 240 | * @param string $password 241 | * @param string $subdomain 242 | * @return void 243 | * @author Timothy S Sabat 244 | */ 245 | public function getLogin($email, $password, $integrationKey, $subdomain = '') { 246 | $args = array('email' => $email, 'password' => $password, 'integrationKey' => $integrationKey, 'subdomain' => $subdomain); 247 | $url = 'http://wufoo.com/api/v3/login/'; 248 | $response = $curl->postAuthenticated($args, $url, null); 249 | return new PostResponse($response); 250 | } 251 | 252 | 253 | public function webHookPut($formIdentifier, $webHookUrl, $handshakeKey, $metadata = false) { 254 | $url = $this->getFullUrl('forms/'.$formIdentifier.'/webhooks'); 255 | $this->curl = new WufooCurl(); 256 | $args = array('url' => $webHookUrl, 'handshakeKey' => $handshakeKey, 'metadata' => $metadata); 257 | $result = json_decode($this->curl->putAuthenticated($args, $url, $this->apiKey)); 258 | return new WebHookResponse($result->WebHookPutResult->Hash); 259 | } 260 | 261 | public function webHookDelete($formIdentifier, $hash) { 262 | $url = $this->getFullUrl('forms/'.$formIdentifier.'/webhooks/'.$hash); 263 | $this->curl = new WufooCurl(); 264 | $result = json_decode($this->curl->deleteAuthenticated(array(), $url, $this->apiKey)); 265 | return new WebHookResponse($result->WebHookDeleteResult->Hash); 266 | } 267 | } 268 | 269 | ?> -------------------------------------------------------------------------------- /WufooApiWrapperBase.php: -------------------------------------------------------------------------------- 1 | curl = new WufooCurl(); 13 | $response = $this->curl->getAuthenticated($url, $this->apiKey); 14 | $response = json_decode($response); 15 | $className = 'Wufoo'.$type; 16 | foreach ($response->$iterator as $obj) { 17 | $arr[$obj->$index] = new $className($obj); 18 | } 19 | return $arr; 20 | } 21 | 22 | protected function getFullUrl($url) { 23 | return 'https://'.$this->subdomain.'.'.$this->domain.'/api/v3/'.$url.'.json'; 24 | } 25 | } 26 | 27 | 28 | class WufooCurl { 29 | 30 | public function __construct() { 31 | //TIMTODO: set timout 32 | } 33 | 34 | public function getAuthenticated($url, $apiKey) { 35 | $this->curl = curl_init($url); 36 | $this->setBasicCurlOptions(); 37 | 38 | curl_setopt($this->curl, CURLOPT_USERPWD, $apiKey.':footastical'); 39 | 40 | $response = curl_exec($this->curl); 41 | $this->setResultCodes(); 42 | $this->checkForCurlErrors(); 43 | $this->checkForGetErrors($response); 44 | curl_close($this->curl); 45 | return $response; 46 | } 47 | 48 | public function postAuthenticated($postParams, $url, $apiKey) { 49 | $this->curl = curl_init($url); 50 | $this->setBasicCurlOptions(); 51 | 52 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data', 'Expect:')); 53 | curl_setopt($this->curl, CURLOPT_POST, true); 54 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postParams); 55 | curl_setopt($this->curl, CURLOPT_USERPWD, $apiKey.':footastical'); 56 | 57 | $response = curl_exec($this->curl); 58 | $this->setResultCodes(); 59 | $this->checkForCurlErrors(); 60 | $this->checkForPostErrors($response); 61 | curl_close($this->curl); 62 | return $response; 63 | } 64 | 65 | //http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php 66 | public function putAuthenticated($postParams, $url, $apiKey) { 67 | $this->curl = curl_init($url); 68 | $this->setBasicCurlOptions(); 69 | 70 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data', 'Expect:')); 71 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'PUT'); 72 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($postParams)); 73 | curl_setopt($this->curl, CURLOPT_USERPWD, $apiKey.':footastical'); 74 | 75 | $response = curl_exec($this->curl); 76 | $this->setResultCodes(); 77 | $this->checkForCurlErrors(); 78 | $this->checkForPutErrors($response); 79 | curl_close($this->curl); 80 | return $response; 81 | } 82 | 83 | //http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php 84 | public function deleteAuthenticated($postParams, $url, $apiKey) { 85 | $this->curl = curl_init($url); 86 | $this->setBasicCurlOptions(); 87 | 88 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data', 'Expect:')); 89 | curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, 'DELETE'); 90 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($postParams)); 91 | curl_setopt($this->curl, CURLOPT_USERPWD, $apiKey.':footastical'); 92 | 93 | $response = curl_exec($this->curl); 94 | $this->setResultCodes(); 95 | $this->checkForCurlErrors(); 96 | //GET and DELETE both expect 200 response for success 97 | $this->checkForGetErrors($response); 98 | curl_close($this->curl); 99 | return $response; 100 | } 101 | 102 | public function setBasicCurlOptions() { 103 | //http://bugs.php.net/bug.php?id=47030 104 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false); 105 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); 106 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); 107 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); 108 | curl_setopt($this->curl, CURLOPT_USERAGENT, 'Wufoo API Wrapper'); 109 | curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 110 | } 111 | 112 | private function setResultCodes() { 113 | $this->ResultStatus = curl_getinfo($this->curl); 114 | } 115 | 116 | private function checkForCurlErrors() { 117 | if(curl_errno($this->curl)) { 118 | throw new WufooException(curl_error($this->curl), curl_errno($this->curl)); 119 | } 120 | } 121 | 122 | private function checkForGetErrors($response) { 123 | switch ($this->ResultStatus['http_code']) { 124 | case 200: 125 | //ignore, this is good. 126 | break; 127 | case 401: 128 | throw new WufooException('(401) Forbidden. Check your API key.', 401); 129 | break; 130 | default: 131 | $this->throwResponseError($response); 132 | break; 133 | } 134 | } 135 | 136 | private function checkForPutErrors($response) { 137 | switch ($this->ResultStatus['http_code']) { 138 | case 201: 139 | //ignore, this is good. 140 | break; 141 | case 401: 142 | throw new WufooException('(401) Forbidden. Check your API key.', 401); 143 | break; 144 | default: 145 | $this->throwResponseError($response); 146 | break; 147 | } 148 | } 149 | 150 | private function checkForPostErrors($response) { 151 | switch ($this->ResultStatus['http_code']) { 152 | case 200: 153 | case 201: 154 | //ignore, this is good. 155 | break; 156 | case 401: 157 | throw new WufooException('(401) Forbidden. Check your API key.', 401); 158 | break; 159 | default: 160 | $this->throwResponseError($response); 161 | break; 162 | } 163 | } 164 | 165 | private function throwResponseError($response) { 166 | if ($response) { 167 | $obj = json_decode($response); 168 | throw new WufooException('('.$obj->HTTPCode.') '.$obj->Text, $this->ResultStatus['HTTP_CODE']); 169 | } else { 170 | throw new WufooException('(500) This is embarrassing... We did not anticipate this error type. Please contact support here: support@wufoo.com', 500); 171 | } 172 | return $response; 173 | } 174 | 175 | } 176 | 177 | /** 178 | * Thrown by WufooCurl calls. 179 | * 180 | * @package default 181 | * @author Timothy S Sabat 182 | */ 183 | class WufooException extends Exception { 184 | 185 | public function __construct($message, $code) { 186 | parent::__construct($message, $code); 187 | } 188 | 189 | }; 190 | 191 | ?> -------------------------------------------------------------------------------- /WufooValueObjects.php: -------------------------------------------------------------------------------- 1 | $value) { 8 | $this->setProperty($key, $value, (isset($obj->ID) ? $obj->ID : '')); 9 | } 10 | } 11 | } 12 | 13 | protected function setProperty($key, $value, $parentId) { 14 | $this->$key = $value; 15 | } 16 | 17 | } 18 | 19 | class WufooFieldCollection { 20 | 21 | public $Fields = array(); 22 | public $Hash = array(); 23 | 24 | public function getField($id) { 25 | return $this->Hash[$id]; 26 | } 27 | 28 | public function getParent($subfield) { 29 | return $this->Fields[$subfield->ParentID]; 30 | } 31 | 32 | } 33 | 34 | class WufooUser extends ValueObject { 35 | 36 | public function __construct($obj = null) { 37 | parent::__construct($obj); 38 | } 39 | 40 | public $Name; 41 | public $IsPublic; 42 | public $Url; 43 | public $Description; 44 | public $DateCreated; 45 | public $DateUpdated; 46 | public $Hash; 47 | public $LinkFields; 48 | public $LinkEntries; 49 | public $LinkEntriesCount; 50 | public $LinkWidgets; 51 | 52 | } 53 | 54 | class WufooField extends ValueObject { 55 | 56 | public function __construct($obj = null) { 57 | parent::__construct($obj); 58 | } 59 | 60 | public $Title; 61 | public $Type; 62 | public $ID; 63 | 64 | protected function setProperty($key, $value, $parentID) { 65 | switch ($key) { 66 | case 'SubFields': 67 | if ($value) { 68 | foreach ($value as $subfield) { 69 | $subfield->ParentID = $parentID; 70 | $this->SubFields[$subfield->ID] = $subfield; 71 | } 72 | } 73 | break; 74 | case 'Choices': 75 | foreach ($value as $choice) { 76 | $this->Choices[] = $choice; 77 | } 78 | break; 79 | default: 80 | $this->$key = $value; 81 | break; 82 | } 83 | } 84 | 85 | 86 | } 87 | 88 | class WufooSubfield extends ValueObject { 89 | 90 | public function __construct($obj = null) { 91 | parent::__construct($obj); 92 | } 93 | 94 | public $ID; 95 | public $Label; 96 | } 97 | 98 | class WufooChoice extends ValueObject { 99 | 100 | public function __construct($obj = null) { 101 | parent::__construct($obj); 102 | } 103 | 104 | public $Score; 105 | public $Label; 106 | } 107 | 108 | class WufooEntry extends ValueObject { 109 | 110 | public function __construct($obj = null) { 111 | parent::__construct($obj); 112 | } 113 | 114 | } 115 | 116 | class WufooForm extends ValueObject { 117 | 118 | public function __construct($obj = null) { 119 | parent::__construct($obj); 120 | } 121 | 122 | public $Name; 123 | public $Description; 124 | public $RedirectMessage; 125 | public $Url; 126 | public $Email; 127 | public $IsPublic; 128 | public $Language; 129 | public $StartDate; 130 | public $EndDate; 131 | public $EntryLimit; 132 | public $DateCreated; 133 | public $DateUpdated; 134 | public $Hash; 135 | } 136 | 137 | class WufooReport extends ValueObject { 138 | 139 | public function __construct($obj = null) { 140 | parent::__construct($obj); 141 | } 142 | 143 | public $Name; 144 | public $Description; 145 | public $RedirectMessage; 146 | public $Url; 147 | public $Email; 148 | public $IsPublic; 149 | public $Language; 150 | public $StartDate; 151 | public $EndDate; 152 | public $EntryLimit; 153 | public $DateCreated; 154 | public $DateUpdated; 155 | public $Hash; 156 | } 157 | 158 | class WufooWidget extends ValueObject { 159 | 160 | public function __construct($obj = null) { 161 | parent::__construct($obj); 162 | } 163 | 164 | public $Name; 165 | public $Size; 166 | public $Type; 167 | public $TypeDesc; 168 | public $Hash; 169 | } 170 | 171 | class WufooComment extends ValueObject { 172 | public function __construct($obj = null) { 173 | parent::__construct($obj); 174 | } 175 | 176 | public $CommentId; 177 | public $CommentedBy; 178 | public $DateCretaed; 179 | public $EntryId; 180 | public $Text; 181 | 182 | } 183 | 184 | /* ------------------------------- 185 | Entry POST 186 | ------------------------------- */ 187 | 188 | /** 189 | * A bit of logic to ensure that field IDs are sent with proper prefix 190 | * 191 | * @author Timothy S Sabat 192 | */ 193 | class WufooSubmitField { 194 | private $id; 195 | private $value; 196 | private $isFile; 197 | 198 | public function __construct($id, $value, $isFile = false) { 199 | $this->id = $id; 200 | $this->value = $value; 201 | $this->isFile = $isFile; 202 | } 203 | 204 | public function getId() { 205 | $ret = str_replace('Field', '', $this->id); 206 | if (is_numeric($ret)) { 207 | $ret = 'Field'.$ret; 208 | } 209 | return $ret; 210 | } 211 | 212 | public function getValue() { 213 | if ($this->isFile) { 214 | return "@$this->value"; 215 | } else { 216 | return $this->value; 217 | } 218 | } 219 | 220 | } 221 | 222 | class PostResponse { 223 | public $Success; 224 | public $ErrorText; 225 | public $EntryLink; 226 | public $FieldErrors; 227 | 228 | public function __construct($response) { 229 | $response = json_decode($response); 230 | foreach ($response as $key => $value) { 231 | $this->$key = $value; 232 | } 233 | } 234 | } 235 | 236 | class WebHookResponse { 237 | public $Hash; 238 | 239 | public function __construct($hash) { 240 | $this->Hash = $hash; 241 | } 242 | } 243 | 244 | 245 | 246 | ?> -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | $_GET['method']($_GET['id'])); 14 | 15 | function print_a($subject){ 16 | echo str_replace("=>","⇒",str_replace("Array","Array",nl2br(str_replace(" ","   ",print_r($subject,true)))) . '
'); 17 | } 18 | 19 | ?> --------------------------------------------------------------------------------