Skip to content

Instantly share code, notes, and snippets.

@m4dc4p
Last active September 26, 2015 00:54
Show Gist options
  • Save m4dc4p/750435b04d055717717b to your computer and use it in GitHub Desktop.
Save m4dc4p/750435b04d055717717b to your computer and use it in GitHub Desktop.
An example of using the HiringThing API using C# and .NET
using System.Net;
using System.Web.Script.Serialization;
using System.Text;
//Method to return active jobs
protected Job[] GetJobsFromTheApplicantTracker()
{
const string API_Key = "Insert API Key Here";
const string API_Password = "Insert API Password Here";
const string url = "https://<Insert Host Here>/remote/jobs/active.json";
using (var wc = new WebClient())
{
//Attach crendentials to WebClient header
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(API_Key + ":" + API_Password));
wc.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
JavaScriptSerializer serializer = new JavaScriptSerializer();
//Deserialize returned JSON as cast to Job classes
var result = serializer.Deserialize<Job[]>(wc.DownloadString(url));
//Return array of job classes
return result;
}
}
//A job class, will cast returned jobs, only selecting fields we need. All more properties by matching field names in JSON
public class Job
{
public string Title { get; set; }
public string Abstract { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Description { get; set; }
public string URL { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment