iOS engineer who likes clean, simple designs and sans-serif.

Loading

Pulling Jobs From Greenhouse.io

Here’s a quick Javascript snippet I wrote for pulling jobs from Greenhouse for GA.
Saving for future reference… but you also can host GA’s jobs on your site. :)

I decided to parse the JSON using business logic and then create my own array of job objects.

<script>
    var GA_Greenhouse = {

      populateCareers: function (data) {
        html = '';
        jobList = [];
        locationsUS = ["Boston", "Los Angeles", "New York", "San Francisco", "Washington, DC"];
        locationsINTL = ["Hong Kong", "London", "Sydney"];

        // Load jobs as objects in a joblist array, ignore empty offices and departments
        jQuery.each(data.offices, function (i, office) {
          jQuery.each(office.departments, function (j, dept) {
            jQuery.each(dept.jobs, function (k, job) {
              var location_list = job.location.name.replace(/, /g,',').split(',');
              jQuery.each(location_list, function (l, loc) {
                console.log("|"+loc+"|"+office.name+"|"+job.title+"|");
                if (loc == office.name) {
                  var oJob = {
                    location: office.name,
                    location_safe: office.name.split(' ').join('_'),
                    position: job.title,
                    url: job.absolute_url
                  };
                  jobList.push(oJob);
                };

              }); // loc
            }); // job
          }); // dept
        }); // location

        // Use underscore.js to sort jobs by position alphabetically
        jobListByPosition = _.sortBy( jobList, 'position' );

        // Show US locations first, then International
        locationsOrdered = locationsUS.concat(locationsINTL);

        jQuery.each( locationsOrdered, function(i, loc) {
          var column_count = 0;
          jQuery.each( jobListByPosition, function(j, job) {
            html_header = '<div id="'+ job.location_safe +'"><h3 class="has-padding">'+ job.location +'</h3>';
            html_row = '<div class="grid-row has-padding three">';
            html_close = '</div>';
           
            if ( loc == job.location ) {
              if (html =='') {
                html = html_header + html_row;
              };
              column_count ++;

              html += '  <div class="column gallery-mini-item">';
              html += '    <div class="mini-product">';
              html += '      <p class="title">';
              html += '        <a href="' + job.url + '" target="_blank">' + job.position + '</a>';
              html += '      </p>';
              html += '    </div>';
              html += '  </div>';

              if (column_count == 3) {
                html += html_close;
                html += html_row;
                column_count = 0;
              }
            };
          });
          html += html_close;
          html += html_close;
          jQuery('.career-listings').append(html);
          html= '';
        });

      } // populateCareers

    }; // GA_Greenhouse

  </script>
 
  <script type="application/javascript" src="https://api.greenhouse.io/v1/boards/generalassembly/embed/offices?callback=GA_Greenhouse.populateCareers"></script>

Leave a Comment