This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleDNS do | |
use GenServer | |
# | |
# Server | |
# | |
def start do | |
GenServer.start __MODULE__, :ok | |
end | |
def get_entry(pid, hostname) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleDNS do | |
def start do | |
pid = spawn __MODULE__, :loop, [%{}] | |
{:ok, pid} | |
end | |
def get_entry(pid, hostname) do | |
send pid, {self(), {:get_entry, hostname}} | |
get_response pid | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleDNS do | |
def start do | |
pid = spawn __MODULE__, :loop, [%{}] | |
{:ok, pid} | |
end | |
def get_entry(pid, hostname) do | |
send pid, {self(), {:get_entry, hostname}} | |
get_response pid | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def call(conn, _opts) do | |
:random.seed :erlang.monotonic_time() | |
rand_number = (:random.uniform * 100) |> Float.round(2) | |
{:ok, rand_json} = [rand_number: rand_number] |> JSON.encode | |
conn | |
|> put_resp_content_type("application/json") | |
|> send_resp(200, rand_json) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleDNS do | |
def start do | |
pid = spawn __MODULE__, :loop, [%{}] | |
{:ok, pid} | |
end | |
def get_entry(pid, hostname) do | |
send pid, {self(), {:get_entry, hostname}} | |
get_response pid | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "As a user who has not logged in", do | |
it "Should NOT be able to do a post", do | |
assert result_of_post == :failed | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "As a user who has not logged in", do | |
user | |
before do | |
assert user.loggedIn? == false | |
end | |
it "Should NOT be able to do a post", do | |
result = user.post "Some message" | |
assert result == :failed | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
securitySchemes: | |
- oauth_2_0: | |
description: | | |
Dropbox supports OAuth 2.0 for authenticating all API requests. | |
type: OAuth 2.0 | |
describedBy: | |
headers: | |
Authorization: | |
description: | | |
Used to send a valid OAuth 2 access token. Do not use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defimpl Simple.StreamReader, for: List do | |
def read_line([a|_]) do | |
a | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defprotocol Simple.StreamReader do | |
def read_line(stream) | |
end | |
defmodule Simple.Socket do | |
defstruct socket: nil | |
end | |
defimpl Simple.StreamReader, for: Simple.Socket do | |
def read_line(simple_socket) do |