Programming Elixir, chapter 13, github issue

Hi, i’m going through the Programming Elixir book, i have the first edition, and don’t know how much changed… Anyway, in chapter 12 there we are building simple client for Github API, many of you probably done that. I’m stuck at getting any response other than :econnrefused here. This is my code:

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
  def issues_url(_, _) do
    "http://api.github.com/repos/elixir-lang/elixir/issues"
  end

  def handle_response{%{status_code: 200, body: body}} do
    {:ok,    body}
  end
  def handle_response{%{status_code: ___, body: body}} do
    {:error, body}
  end
end

I’ve hardcoded the url to make sure there is no error there. i got this from iex:

D:\DEV\PRJ\elixir\issues>iex -S mix
Eshell V7.2.1  (abort with ^G)
Compiled lib/issues/github_issues.ex
Interactive Elixir (1.2.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Issues.GithubIssues.fetch('elixir-lang', 'elixir')
** (HTTPoison.Error) :econnrefused
    (httpoison) lib/httpoison.ex:66: HTTPoison.request!/5
       (issues) lib/issues/github_issues.ex:6: Issues.GithubIssues.fetch/2
iex(1)>

From what i understand, github is giving me 401 or 403 because of some reason. I think its because somehow i screwed user agent header. But i can’t figure it out since yesterday. Can anyone, please, be kind enough to tell me what did i wote wong?

PS. here link to my repo if it’s helpfull https://github.com/sztosz/github-issues

2 Likes

Hi @sztosz. It seems to me that the url is invalid. Would you mind trying https://api.github.com/repos/elixir-lang/elixir/issues?

5 Likes

Thank you so much!!!

i didn’t notice that when i go to the http in browser it redirects me to https (the secure one). :smiley:

Briliant, i’m in your debt :heart:

2 Likes

Oh, you’re not. Glad to be of help! :slight_smile:

1 Like