CareerBuilder API DOT NET Code

Sample Code Download Here

This post regarding CareerBuilder REST service consumption from Dot Net.

For consuming any REST Service first we should know the URL of respective REST service. If service provider is providing any public key or private key you need to get it from service provider before using REST service.

This key trick will applicable for CareerBuilder  REST service too. To obtain a key visit the CareerBuilder site http://api.careerbuilder.com, you can get your own private key.

After receiving your Private key you can start integrating CareerBuilder REST service to your Application.  I created sample application for “JobSearch” functionality. In sample application I created a TextBox for searching jobs from CareerBuilder Service method there are lot of search criteria’s available in the service but I used only “Skill” parameter according to your requirement you can use any number of parameters.

I created a Model class to bind the individual job. Finally ListJobs method will returns the

List<Jobs> as a generic list which I am binding to a gridview.

Note : I removed my private key and replaced with xxxxxx values. You can use your private key in that place.


public static string devKey = "XXXXXXXXXXXXXXXXXXXX";
 public static string URL = "http://api.careerbuilder.com/v1/jobsearch";

#region JobSearch Web Reuest
 private XmlDocument ListJobSearch()
 {
 XmlDocument xDoc = new XmlDocument();
 string outString = string.Empty;
 try
 {
 string _url = URL + "?DeveloperKey=" + devKey + "&Skills=" + txtSkill.Text + "";
 WebRequest objRequest = WebRequest.Create(_url);
 objRequest.Method = "GET";
 objRequest.ContentType = "application/xml";
 WebResponse objResponse = objRequest.GetResponse();
 outString = new StreamReader(objResponse.GetResponseStream()).ReadToEnd();
 xDoc.LoadXml(outString);
 }
 catch (Exception ex)
 {
 throw ex;
 }
 return xDoc;
 }
 #endregion

 In the above code snippet I am trying to call the REST service with user entered skill captured from textbox. this will return xml value. I just taken the xml and converted it to xml document and converted xml document to List<jobs> in ListJobs method mentioned bellow.

</pre>
#region ListJobs Method
 private List<JobSearchModel> ListJobs()
 {
 List<JobSearchModel> objList = new List<JobSearchModel>();
 XmlDocument xDoc = ListJobSearch();
 try
 {
 XmlNodeList objNoe = xDoc.SelectNodes("/ResponseJobSearch/Results/JobSearchResult");
 foreach (XmlNode xn in objNoe)
 {
 JobSearchModel objSearchMode = new JobSearchModel();
 objSearchMode.Company = xn["Company"].InnerText;
 objSearchMode.JobTitle = xn["JobTitle"].InnerText;
 objSearchMode.CompanyDID = xn["CompanyDID"].InnerText;
 objSearchMode.CompanyDetailsURL = xn["CompanyDetailsURL"].InnerText;
 objSearchMode.ONetFriendlyTitle = xn["ONetFriendlyTitle"].InnerText;
 objSearchMode.DescriptionTeaser = xn["DescriptionTeaser"].InnerText;
 objSearchMode.EmploymentType = xn["EmploymentType"].InnerText;
 objSearchMode.JobDetailsURL = xn["JobDetailsURL"].InnerText;
 objSearchMode.JobServiceURL = xn["JobServiceURL"].InnerText;
 objSearchMode.Location = xn["Location"].InnerText;
 objSearchMode.PostedDate = xn["PostedDate"].InnerText;
 objSearchMode.Pay = xn["Pay"].InnerText;
 objSearchMode.SimilarJobsURL = xn["SimilarJobsURL"].InnerText;
 objSearchMode.CompanyImageURL = xn["CompanyImageURL"].InnerText;

objList.Add(objSearchMode);
 }
 }
 catch (Exception ex)
 {
 throw ex;
 }
 return objList;
 }
 #endregion
<pre>

After converting XmlDocument to List<T> I am just binding this List to GridView. This gridview will display every job. You can design your own format to display the jobs.

Comments are inevitable.

Advertisements

About tvskumar2000

Tvs always cooooool
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s