Skip to content

Commit 0547334

Browse files
committed
Code for step 1
0 parents  commit 0547334

9 files changed

+171
-0
lines changed

.formatter.exs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Used by "mix format"
2+
[
3+
line_length: 120,
4+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
5+
]

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
payments_client-*.tar
24+

README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# PaymentsClient
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `payments_client` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:payments_client, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at [https://hexdocs.pm/payments_client](https://hexdocs.pm/payments_client).
21+

lib/mock_api.ex

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
defmodule PaymentsClient.MockAPI do
2+
def create_payment(user_id, new_payment_info) do
3+
Process.sleep(random_latency())
4+
5+
%{
6+
status: 201,
7+
user_id: user_id,
8+
payment: new_payment_info
9+
}
10+
end
11+
12+
# Do something with the resp here
13+
def handle_create_payment(_resp), do: nil
14+
15+
def delete_payment(user_id, payment_id) do
16+
Process.sleep(random_latency())
17+
18+
%{
19+
status: 204,
20+
user_id: user_id,
21+
id: payment_id
22+
}
23+
end
24+
25+
# Do something with the resp here
26+
def handle_delete_payment(_resp), do: nil
27+
28+
def charge_payment(user_id, payment_id, amount) do
29+
Process.sleep(random_latency())
30+
31+
%{
32+
status: 200,
33+
user_id: user_id,
34+
amount: amount,
35+
id: payment_id,
36+
payment_processed: Enum.random(~w(success failed))
37+
}
38+
end
39+
40+
# Do something with the resp here
41+
def handle_charge_payment(_resp), do: nil
42+
43+
defp random_latency do
44+
Enum.random(100..400)
45+
end
46+
end

lib/payments_client.ex

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
defmodule PaymentsClient do
2+
@moduledoc """
3+
Documentation for PaymentsClient.
4+
"""
5+
6+
@doc """
7+
Hello world.
8+
9+
## Examples
10+
11+
iex> PaymentsClient.hello()
12+
:world
13+
14+
"""
15+
def hello do
16+
:world
17+
end
18+
end

lib/payments_client/application.ex

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule PaymentsClient.Application do
2+
# See https://hexdocs.pm/elixir/Application.html
3+
# for more information on OTP Applications
4+
@moduledoc false
5+
6+
use Application
7+
8+
def start(_type, _args) do
9+
children = [
10+
# Starts a worker by calling: PaymentsClient.Worker.start_link(arg)
11+
# {PaymentsClient.Worker, arg}
12+
]
13+
14+
# See https://hexdocs.pm/elixir/Supervisor.html
15+
# for other strategies and supported options
16+
opts = [strategy: :one_for_one, name: PaymentsClient.Supervisor]
17+
Supervisor.start_link(children, opts)
18+
end
19+
end

mix.exs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
defmodule PaymentsClient.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :payments_client,
7+
version: "0.1.0",
8+
elixir: "~> 1.9",
9+
start_permanent: Mix.env() == :prod,
10+
deps: deps()
11+
]
12+
end
13+
14+
# Run "mix help compile.app" to learn about applications.
15+
def application do
16+
[
17+
extra_applications: [:logger],
18+
mod: {PaymentsClient.Application, []}
19+
]
20+
end
21+
22+
# Run "mix help deps" to learn about dependencies.
23+
defp deps do
24+
[
25+
# {:dep_from_hexpm, "~> 0.3.0"},
26+
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
27+
]
28+
end
29+
end

test/payments_client_test.exs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defmodule PaymentsClientTest do
2+
use ExUnit.Case
3+
doctest PaymentsClient
4+
5+
test "greets the world" do
6+
assert PaymentsClient.hello() == :world
7+
end
8+
end

test/test_helper.exs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ExUnit.start()

0 commit comments

Comments
 (0)