Your Turn

Back to the Transformation

So, back to our problem. We have to write the function GithubIssues.fetch, which transforms a user name and project into a data structure containing that project’s issues. The HTTPoison page on GitHub gives us a clue,[22] and we write a new module, Issues.GithubIssues:

 defmodule​ Issues.GithubIssues ​do
  @user_agent [ {​"​​User-agent"​, ​"​​Elixir dave@pragprog.com"​} ]
 
 def​ fetch(user, project) ​do
  issues_url(user, project)
  |> HTTPoison.get(@user_agent)
  |> handle_response
 end
 
 def​ issues_url(user, project) ​do
 "​​https://api.github.com/repos/​​#{​user​}

Get Programming Elixir 1.2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.