Skip to content

Instantly share code, notes, and snippets.

@m4dc4p
Last active September 26, 2015 00:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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