PooleApp.com

serving dynamic data to your static sites

Examples

Getting your data couldn't be simpler. Here are some examples of using Poole to deliver comments for your blog in some popular techniques.

Getting your data with CURL

Perhaps the simplest example of how to download all of the data submitted to one of your forms and save it in a file.

curl http://pooleapp.com/data/{API-SECRET}.json > data.json

JavaScript in the browser

Although exposing your API secret in the browser will allow others to detect a way to also query your data, Poole's API is read only so your data is not exposed to the threat of being destroyed.

// Javascript using jQuery
var thispage = document.location.href;
$.getJSON('http://pooleapp.com/data/{API-SECRET}.json', function(d) {
  $.each(d, function(key, val) {
    //do stuff
  });
});

Using NodeJS, Gulp and Jekyll

Jekyll v2.0 brought support for data files. This method uses a Gulp task to retrieve comments data from Poole and then save them as a data source for Jekyll to use in a standard build.

The Gulp task in a typical gulpfile.js file

// Get comments data from Poole
gulp.task("comments", function() {
  
  // set up the request to get comments as YAML
  var options = {
    hostname: 'pooleapp.com',
    port: 80,
    path: '/data/{API-SECRET}.yaml',
    method: 'GET',
  };

  // Go and get data
  http.get(options, function(res) {
    
    var body = '';
    res.on('data', function(chunk) {
        body += chunk;
    });
    res.on('end', function() {
      
      // Save the comments for jekyll to use as a data source
      fs.writeFile('./src/_data/comments.yml', body, function(err) {
        if(err) {
          console.log(err);
        } else {
          console.log("Comments data saved.");
        }
      });

    });
  });
});

Jekyll uses the data file to add comments to the correct posts

This assumes that Gulp has saved the comments data to the file _data/comments.yml

<ul>
  {% for comment in site.data.comments.sessions %}
    {% if comment.path == page.url %}
    <li>
      <time datetime="{{ comment.created | date_to_xmlschema }}">
        {{ comment.created | date_to_long_string  }}
      </time>
      <a href="{{ comment.url }}">{{ comment.name }}</a>
      <p>{{ comment.name }}</p>
      <div>
        {{ comment.comment }}
      </div>
    </li>
    {% endif %}
  {% endfor %}
</ul>