Add some basic code

This commit is contained in:
Ben Shiller 2024-10-10 22:04:34 -05:00
parent 7f7a63f379
commit caa9a46c1b
Signed by: shillerben
GPG Key ID: 7B4602B1FBF82986
10 changed files with 136 additions and 13 deletions

4
.formatter.exs Normal file
View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

36
.gitignore vendored
View File

@ -1,12 +1,26 @@
# ---> Elixir # The directory Mix will write compiled artifacts to.
/_build /_build/
/cover
/deps
/doc
/.fetch
erl_crash.dump
*.ez
*.beam
/config/*.secret.exs
.elixir_ls/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
elixir_rss-*.tar
# Temporary files, for example, from tests.
/tmp/

View File

@ -1,3 +1,21 @@
# elixir-rss # ElixirRss
RSS reader written in Elixir
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `elixir_rss` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:elixir_rss, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/elixir_rss>.
RSS reader written in elixir

18
lib/elixir_rss.ex Normal file
View File

@ -0,0 +1,18 @@
defmodule ElixirRss do
@moduledoc """
Documentation for `ElixirRss`.
"""
@doc """
Hello world.
## Examples
iex> ElixirRss.hello()
:world
"""
def hello do
:world
end
end

14
lib/fetch_rss.ex Normal file
View File

@ -0,0 +1,14 @@
defmodule ElixirRss.Fetch do
def fetch(url) do
url
|> HTTPoison.get()
|> handle_response()
end
defp handle_response({:ok, %{status_code: 200, body: body}}) do
{:ok, body}
end
defp handle_response({_, %{status_code: _, body: body}}) do
{:error, body}
end
end

27
mix.exs Normal file
View File

@ -0,0 +1,27 @@
defmodule ElixirRss.MixProject do
use Mix.Project
def project do
[
app: :elixir_rss,
version: "0.1.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:httpoison, "~> 2.2.0"}
]
end
end

11
mix.lock Normal file
View File

@ -0,0 +1,11 @@
%{
"certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"},
"hackney": {:hex, :hackney, "1.20.1", "8d97aec62ddddd757d128bfd1df6c5861093419f8f7a4223823537bad5d064e2", [:rebar3], [{:certifi, "~> 2.12.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~> 6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~> 1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~> 1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.4.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~> 1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "fe9094e5f1a2a2c0a7d10918fee36bfec0ec2a979994cff8cfe8058cd9af38e3"},
"httpoison": {:hex, :httpoison, "2.2.1", "87b7ed6d95db0389f7df02779644171d7319d319178f6680438167d7b69b1f3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "51364e6d2f429d80e14fe4b5f8e39719cacd03eb3f9a9286e61e216feac2d2df"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~> 0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}

8
test/elixir_rss_test.exs Normal file
View File

@ -0,0 +1,8 @@
defmodule ElixirRssTest do
use ExUnit.Case
doctest ElixirRss
test "greets the world" do
assert ElixirRss.hello() == :world
end
end

8
test/fetch_rss_test.exs Normal file
View File

@ -0,0 +1,8 @@
defmodule ElixirRss.FetchTest do
use ExUnit.Case
doctest ElixirRss.Fetch
test "fetch url" do
assert ElixirRss.Fetch.fetch("https://shillerben.com") |> elem(0) == :ok
end
end

1
test/test_helper.exs Normal file
View File

@ -0,0 +1 @@
ExUnit.start()