Skip to content
Permalink
Browse files

Code for step 1

  • Loading branch information
akoutmos committed Jan 7, 2020
0 parents commit 05473345df8f5b42cf88920c532fd05a342a3fd2
Showing with 171 additions and 0 deletions.
  1. +5 −0 .formatter.exs
  2. +24 −0 .gitignore
  3. +21 −0 README.md
  4. +46 −0 lib/mock_api.ex
  5. +18 −0 lib/payments_client.ex
  6. +19 −0 lib/payments_client/application.ex
  7. +29 −0 mix.exs
  8. +8 −0 test/payments_client_test.exs
  9. +1 −0 test/test_helper.exs
@@ -0,0 +1,5 @@
# Used by "mix format"
[
line_length: 120,
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
@@ -0,0 +1,24 @@
# The directory Mix will write compiled artifacts to.
/_build/

# 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").
payments_client-*.tar

@@ -0,0 +1,21 @@
# PaymentsClient

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `payments_client` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:payments_client, "~> 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/payments_client](https://hexdocs.pm/payments_client).

@@ -0,0 +1,46 @@
defmodule PaymentsClient.MockAPI do
def create_payment(user_id, new_payment_info) do
Process.sleep(random_latency())

%{
status: 201,
user_id: user_id,
payment: new_payment_info
}
end

# Do something with the resp here
def handle_create_payment(_resp), do: nil

def delete_payment(user_id, payment_id) do
Process.sleep(random_latency())

%{
status: 204,
user_id: user_id,
id: payment_id
}
end

# Do something with the resp here
def handle_delete_payment(_resp), do: nil

def charge_payment(user_id, payment_id, amount) do
Process.sleep(random_latency())

%{
status: 200,
user_id: user_id,
amount: amount,
id: payment_id,
payment_processed: Enum.random(~w(success failed))
}
end

# Do something with the resp here
def handle_charge_payment(_resp), do: nil

defp random_latency do
Enum.random(100..400)
end
end
@@ -0,0 +1,18 @@
defmodule PaymentsClient do
@moduledoc """
Documentation for PaymentsClient.
"""

@doc """
Hello world.
## Examples
iex> PaymentsClient.hello()
:world
"""
def hello do
:world
end
end
@@ -0,0 +1,19 @@
defmodule PaymentsClient.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false

use Application

def start(_type, _args) do
children = [
# Starts a worker by calling: PaymentsClient.Worker.start_link(arg)
# {PaymentsClient.Worker, arg}
]

# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: PaymentsClient.Supervisor]
Supervisor.start_link(children, opts)
end
end
29 mix.exs
@@ -0,0 +1,29 @@
defmodule PaymentsClient.MixProject do
use Mix.Project

def project do
[
app: :payments_client,
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {PaymentsClient.Application, []}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
@@ -0,0 +1,8 @@
defmodule PaymentsClientTest do
use ExUnit.Case
doctest PaymentsClient

test "greets the world" do
assert PaymentsClient.hello() == :world
end
end
@@ -0,0 +1 @@
ExUnit.start()

0 comments on commit 0547334

Please sign in to comment.
You can’t perform that action at this time.