   end
 
   # Returns github page url or rubygems gem page url
-  # TODO: check if github page really exists
   defp gem_page(gem) do
     api_url = "https://rubygems.org/api/v1/gems/#{gem}.json"
     response = HTTPoison.get! api_url

      json = JSX.decode! response.body
      repo = get_repo_name(json["homepage_uri"]) || get_repo_name(json["source_code_uri"])

      if is_nil(repo), do: json["project_uri"], else: "https://github.com/#{repo}"
    end
  end


      |> List.last
    end
  end

  defp github_exists?(repo) do
    HTTPoison.start
    case HTTPoison.head("https://github.com/#{repo}") do
      {:ok, %HTTPoison.Response{status_code: 200, body: _}} ->
        true
      {:ok, %HTTPoison.Response{status_code: 404}} ->
        false
      {:error, %HTTPoison.Error{reason: _}} ->
        false
    end
  end
end
