Giter VIP home page Giter VIP logo

usajobs's Introduction

USAJobs

a PHP utility class for USAJobs' new Search API (circa October 2015)

Contents

Frequently Asked Questions

Tutorial

Frequently Asked Questions

Q. WHAT IS THIS EXACTLY?

USAJobs announced they would replace their existing Search API in October 2015 January 2016. Although the new API is not much more complicated, there were enough differences (i.e. required request headers) that making a PHP utility/helper class seemed potentially helpful to others.

This is a work in progress, and if other PHP developers want to help identify and/or resolve issues, please feel free to do so.

Q. WHERE CAN I GET AN API KEY?

You can request an API Key from the USAJobs.gov Developer website.

Please don't contact me about issues with your API Key. I do not work for USAJobs, and will not be able to help you.

Q. WHY DO I GET A 503/SERVICE UNAVAILABLE ERROR WHEN I USE YOUR CLASS?

You're probably not using any query parameters to filter the results. For some reason, when you run a query for job listings without any filtering, the USAJobs server returns a 503 error (presumably timing out before it can return the results?).

Fortunately, if you add one query parameter (e.g. Organization=TR) to filter search results, that prevents the 503 Error from happening.

So, stop being a jerk by asking for all jobs listed on USAJobs.gov ("I kid, I kid, I joke with you." - Triumph the Insult Comic Dog), and make more reasonable requests by narrowing your query with parameters before invoking the getJobListing() method.

Not sure what query parameters you can use? USAJobs.gov has fairly decent documentation.

Tutorial

To use the USAJobs utility class in your PHP code, you must first include it.

<?php

	require_once 'USAJobs.class.php';

To use this class, you must have an API Key. If you don't have an API Key, you can request one from the USAJobs.gov Developer website.

Once you have your API Key, use it to initialize an instance/object of our USAJobs class, like so:

	// initialize the object with email address and API Key you received from USAJobs website
	$objUSAJobs = new USAJobs("YourEmailAddress","YourAPIKeyValue");

IMPORTANT NOTE: If you invoke the getJobListing() method without first setting any query filtering parameters, the USAJobs web server will return a 503 Error/Service Unavailable error.

In the next step of our example, I'm going to limit my search results to jobs within the Department of Interior that contain the keyword of "archeologist."

	// let's set a keyword parameter
	$objUSAJobs->setKeyword("archeologist");
	
	// let's limit our search to jobs listed within the Department of The Interior
	$objUSAJobs->setOrganization("IN");

Once you've set your query parameters as desired, use the getJobListing() method to get the matching search results. The results will be returned in JSON format, so you'll probably want to decode them if you want to do any further manipulation on the server side.

	// retrieve the job listings that match our criteria
	$jobsJSON = $objUSAJobs->getJobListing();
	
	// since results are in JSON format, we must decode them
	$jobs = json_decode($jobsJSON);
?>

In the example above, $jobs is a complex PHP variable. I'd suggest dumping it with a print_r function to get a sense of the structure returned by the Search API. You'll find it contains both the job listings and metadata about the query.

usajobs's People

Contributors

mrandrewmills avatar

Stargazers

Matthew Martin avatar

Watchers

Matthew Martin avatar  avatar

usajobs's Issues

QA issue in CreateURLParameters method

if ($this->radius != "") {
$URLParams = $URLParams . "KeywordFilter=" . $this->keywordFilter;
}
if ($this->fields != "") {
$URLParams = $URLParams . "KeywordFilter=" . $this->keywordFilter;
}

Pretty sure it should be these instead:

if ($this->radius != "") {
$URLParams = $URLParams . "&Radius=" . $this->radius;
}
if ($this->fields != "") {
$URLParams = $URLParams . "&Fields=" . $this->fields;
}

add validation code to setters

Some of the properties have specific data types/values. User_agent, for example, must be an email address.

We need to add code that validates input through the setters, for each properties unique characteristics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.