∴ikura

An ikura app — part II

As we continue from the
first post, right away we are
confronted with some busy-work. For our bonegram application to
work, we need to create a Twitter app.
The details of this can be google’d, but from our efforts, we will
get a Twitter app customer key, customer secret, a token, and a token
secret; four required things for working with Twitter’s API.
Also, the Twitter app needs to have ‘Read, Write and Access direct
messages’ privileges set.

With those four configurations, we update our ‘dev.config’
accordingly:

Now that those details are out of the way, let’s re-acquaint
ourselves with some goals.

When ikura calls our bonegram HTTP endpoint, in turn, we want to
call Twitter and get as many new & relevant tweets about injured
Twitter users as possible. Twitter will give us the user’s
handle (eg. @foobar), their tweet-text, and some other useful things
to work with; things necessary for bonegram to send them a nice
tweet.

To parse Twitter’s API replies, we will use an Erlang library
called ‘jsx’ for converting JSON to usable Erlang terms. Along
those same lines, we want to utilize an existing oauth library so we
don’t have to write code for making proper API calls. We make the
following edits to the project’s ‘rebar.config’ file:

The code in ‘src/bonegram_lib.erl’ is a slathering of sequential
specifics that:

calls Twitter’s search API with a query.

digests the JSON that Twitter returns.

Our query is “-almost broke my arm :(” — which is good enough
for now as it covers the criteria we care about.

Our new module works simply enough: it gathers broken-bone related
tweets from the last several days. And all this happens
via bonegram_lib:new/0. The other exported function, new/1,
performs nearly the same task, only it takes an id as its argument.
We will use new/1 to gather tweets since the last time
bonegram ran the call. And we accomplished all this, in a mere 81
lines of code.

In the next blog-post of the series, we will wire a few things
together, play with what we have so far, and dive into the ikura
configuration.