Convenient wrapper library around the API for Ruby.


Add this line to your application's Gemfile:

gem 'pnut'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pnut


The goal of the project is to provide a convenient method for every possible endpoint. For example, if you want to fetch the global timeline and get back struct containing "meta" and "data" as described in the official documentation of the API:

require "pnut"

pnut =
response =

p response.meta # meta response with HTTP status code etc.
p # data response, an array of the current posts

Most endpoints need a proper Bearer token for authorization. Simply initialize like this to get access:

pnut = "YOURTOKEN")

If we didn't implement an endpoint yet (check the Gems docs to see what is available), you can use the request method to send custom requests:

require "pnut"

pnut =

For POST, DELETE, etc. request, the method signature provides the following, with the data parameter defaulting to JSON:

  method: "POST",
  data: {
    text: "Der Test[tm]"

As a more thorough example, one can request an AppStream access token (where the endpoint expects form-data instead of JSON) and get the body of the response unparsed as a string like this:

  json: false,
  method: "POST",
  raw_response: true,
  data: {
    client_id: "YOUR_CLIENT_ID",
    client_secret: "YOUR_CLIENT_SECRET",
    grant_type: "client_credentials"

App Streams

We support a light abstraction over pnut's App Streams, standing on the shoulders of EventMachine and faye-websocket. Given you already have a valid app access token and created a stream with corresponding stream key, you can start it like this:

require "pnut/app_stream"

Pnut::AppStream.start(access_token: "", stream_key: "")

Having every stream message printed to STDOUT is not that useful in itself, therefor you can provide a custom handler to react to them yourself:

require "pnut/app_stream"

def my_handler(msg)
  p JSON.parse(msg)

  access_token: "",
  stream_key: "",
  handler: method(:my_handler)


After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.