25 Oct 2013, 03:43
Rick_cropped_mini_pragsmall

Rick DeNatale (14 posts)

Working through the chapter.

I think I’ve followed everything, but when I run idx -S mix

ex(1)> Issues.GithubIssues.fetch("elixir-lang", "elixir") ** (UndefinedFunctionError) undefined function: Issues.GithubIssues.fetch/2 Issues.GithubIssues.fetch("elixir-lang", "elixir") erl_eval.erl:569: :erl_eval.do_apply/6 src/elixir.erl:138: :elixir.eval_forms/3

Which is the same problem which was given to solve at the end to section 12.5.

There seems to be something needed in the application configuration to get lib/issues/github_issues.exs recognized and compiled.

If I issue the command

c "lib/issues/github_issues.exs"

before I do Issues.GithubIssues.fetch("elixir-lang", "elixir") then it does work, but this produces a file Elixir.issues.GithubIssues.beam in the top level directory of the project, while the other beam files are in the ebin directory. Neither this nor the “need” to manually compile this file seems right, but I can’t figure out how I’m supposed to do this.

I also notice that the file name for this file is given on page 130 as “project/1/issues/lib/issues/github_issues.ex” Is this supposed to be .exs ? I tried both ways but .ex didn’t work

25 Oct 2013, 11:47
Mac 128k logic board 96x96_pragsmall

Roger Turner (7 posts)

All files in my /lib/issues/ directory are .ex, with .exs only for the top level mix.exs and the files in /test/

I decided to try the Erlang inets/httpc library referenced on page 128, so my github_issues.ex is:

  defmodule Issues.GithubIssues do

    @user_agent [ { 'User-agent', 'Elixir ...' } ]

    def fetch(user, project) do
      case {:ok, {{_version, status, _reasonPhrase}, _headers, body}} =
      :httpc.request(:get, {issues_url(user, project), @user_agent}, [], [body_format: :binary]) do
        {:ok, {{_, 200, _}, _, _}} ->
          { :ok, body }
        _ ->
          { :error, body }
      end 
    end

    def issues_url(user, project),
      do: 'https://api.github.com/repos/#{user}/#{project}/issues'

  end

which required

  def application do
    [ mod: { Issues, [] },
      applications: [ :inets, :ssl ]
    ]
  end

in mix.exs

26 Oct 2013, 19:28
Rick_cropped_mini_pragsmall

Rick DeNatale (14 posts)

Thanks Roger. I changed the filetype to .ex and it now works.

  You must be logged in to comment