├── README.md └── src └── indeed.php /README.md: -------------------------------------------------------------------------------- 1 | # indeed-php 2 | 3 | A client library for using the Indeed Jobsearch API 4 | 5 | ### API Credentials 6 | 7 | The Indeed API needs to be called with your Indeed publisher number. You must pass this 8 | to the `Indeed` constructor. 9 | 10 | ```php 11 | require 'src/indeed.php'; 12 | 13 | $client = new Indeed("YOUR_PUBLISHER_NUMBER"); 14 | ``` 15 | 16 | If you do not have a publisher number, you can receive one by heading to the 17 | [Indeed Publisher Portal](https://ads.indeed.com/jobroll/xmlfeed). 18 | 19 | 20 | ### Performing a Job Search 21 | 22 | ```php 23 | require 'src/indeed.php'; 24 | 25 | $client = new Indeed("YOUR_PUBLISHER_NUMBER"); 26 | 27 | $params = array( 28 | "q" => "php", 29 | "l" => "austin", 30 | "userip" => "1.2.3.4", 31 | "useragent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2)" 32 | ); 33 | 34 | $results = $client->search($params); 35 | ``` 36 | 37 | ### Retrieving Job Details 38 | 39 | ```php 40 | require 'src/indeed.php'; 41 | 42 | $client = new Indeed("YOUR_PUBLISHER_NUMBER"); 43 | 44 | $params = array( 45 | "jobkeys" => array("5898e9d8f5c0593f", "c2c41f024581eae5"), 46 | ); 47 | 48 | $results = $client->jobs($params); 49 | ``` 50 | 51 | ### API Paramaters 52 | 53 | #### Job Search 54 | 55 | **q** - 56 | Query. By default terms are ANDed. To see what is possible, use our [advanced search](http://www.indeed.com/advanced_search) page to perform a search and then check the url for the q value. 57 | 58 | **l** - 59 | Location. Use a postal code or a "city, state/province/region" combination. 60 | 61 | **userip** - 62 | The IP number of the end-user to whom the job results will be displayed. *This field is required*. 63 | 64 | **useragent** - 65 | The User-Agent (browser) of the end-user to whom the job results will be displayed. This can be obtained from the "User-Agent" HTTP request header from the end-user. *This field is required*. 66 | 67 | **format** - 68 | Format. Which output format of the API you wish to use. The options are "xml" and "json.". Default is "json". `Indeed` requests and parses a json repsonse by default. If you with to use the xml format, requests will be performed with the **raw** parameter set to `True`, see **raw**. 69 | 70 | **raw** - 71 | A boolean. Receive the raw json/xml response from the Indeed API. Use in addition with *format* to specify which response format you would like. Default is `False` 72 | 73 | **sort** - 74 | Sort by relevance or date. Default is relevance. 75 | 76 | **radius** - 77 | Distance from search location ("as the crow flies"). Default is 25. 78 | 79 | **start** - 80 | Start results at this result number, beginning with 0. Default is 0. 81 | 82 | **limit** - 83 | Maximum number of results returned per query. Default is 10, Maximum is 25 84 | 85 | **fromage** - 86 | Number of days back to search. 87 | 88 | **highlight** - 89 | Setting this value to 1 will bold terms in the snippet that are also present in q. Default is 0. 90 | 91 | **filter** - 92 | Filter duplicate results. 0 turns off duplicate job filtering. Default is 1. 93 | 94 | **latlong** - 95 | If latlong=1, returns latitude and longitude information for each job result. Default is 0. 96 | 97 | **co** - 98 | Search within country specified. Default is *us*. 99 | 100 | 101 | #### Job Details 102 | 103 | **jobkeys** - 104 | Job keys. A list of job keys specifying the jobs to look up. *This parameter is required*. 105 | 106 | **format** - 107 | Format. Which output format of the API you wish to use. The options are "xml" and "json.". Default is "json". `Indeed` requests and parses a json repsonse by default. If you with to use the xml format, requests will be performed with the **raw** parameter set to `True`, see **raw**. 108 | 109 | **raw** - 110 | A boolean. Receive the raw json/xml response from the Indeed API. Use in addition with *format* to specify which response format you would like. Default is `False` 111 | -------------------------------------------------------------------------------- /src/indeed.php: -------------------------------------------------------------------------------- 1 | publisher = $publisher; 14 | $this->version = $version; 15 | } 16 | 17 | public function search($args){ 18 | return $this->process_request(self::API_SEARCH_ENDPOINT, $this->validate_args(self::$API_SEARCH_REQUIRED, $args)); 19 | } 20 | 21 | public function jobs($args){ 22 | $valid_args = $this->validate_args(self::$API_JOBS_REQUIRED, $args); 23 | $valid_args["jobkeys"] = implode(",", $valid_args['jobkeys']); 24 | return $this->process_request(self::API_JOBS_ENDPOINT, $valid_args); 25 | } 26 | 27 | private function process_request($endpoint, $args){ 28 | $format = (array_key_exists("format", $args) ? $args["format"] : self::DEFAULT_FORMAT); 29 | $raw = ($format == "xml" ? true : (array_key_exists("raw", $args) ? $args["raw"] : false)); 30 | $args["publisher"] = $this->publisher; 31 | $args["v"] = $this->version; 32 | $args["format"] = $format; 33 | $c = curl_init(sprintf("%s?%s", $endpoint, http_build_query($args))); 34 | curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); 35 | $result = curl_exec($c); 36 | curl_close($c); 37 | $r = (!$raw ? json_decode($result, $assoc = true) : $result); 38 | return $r; 39 | } 40 | 41 | private function validate_args($required_fields, $args){ 42 | foreach($required_fields as $field){ 43 | if(is_array($field)){ 44 | $has_one_required = false; 45 | foreach($field as $f){ 46 | if(array_key_exists($f, $args)){ 47 | $has_one_required = True; 48 | break; 49 | } 50 | } 51 | if(!$has_one_required){ 52 | throw new Exception(sprintf("You must provide one of the following %s", implode(",", $field))); 53 | } 54 | } elseif(!array_key_exists($field, $args)){ 55 | throw new Exception("The field $field is required"); 56 | } 57 | } 58 | return $args; 59 | } 60 | 61 | } --------------------------------------------------------------------------------