Skip to content

Commit

Permalink
Merge pull request #12 from saleyn/master
Browse files Browse the repository at this point in the history
Fix credo issues and github actions
  • Loading branch information
alexandrubagu committed Nov 22, 2022
2 parents edad278 + 61e2074 commit 8a2b780
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
42 changes: 26 additions & 16 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
name: Elixir CI

on: push
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

container:
image: elixir:1.9.1-slim

name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ['25.1']
elixir: ['1.13.4', '1.14.1']
steps:
- uses: actions/checkout@v1
- name: Install Dependencies
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Run Tests
run: mix test
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Install Dependencies
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get
- name: Run Credo Checks
run: mix credo
- name: Run Tests
run: mix test
27 changes: 16 additions & 11 deletions lib/simplehttp.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule SimpleHttp do
@moduledoc """
Implements a simple HTTP client that uses inets application included in the OTP.
"""
alias SimpleHttp.Request
alias SimpleHttp.Response
alias SimpleHttp.Exception.BadArgument
Expand Down Expand Up @@ -200,20 +203,22 @@ defmodule SimpleHttp do
raise RuntimeError, message: "Cannot start httpc: #{inspect(error)}"
end

if options != [] do
case (profile && :httpc.set_options(options, pid)) || :httpc.set_options(options) do
:ok ->
:ok

{:error, err} ->
raise BadArgument,
message: "Error setting httpc options #{inspect(options)}: #{inspect(err)}"
end
end
options != [] && set_httpc_options(profile, pid, options)

{profile || :inets, args}
end

defp set_httpc_options(profile, pid, options) do
case (profile && :httpc.set_options(options, pid)) || :httpc.set_options(options) do
:ok ->
:ok

{:error, err} ->
raise BadArgument,
message: "Error setting httpc options #{inspect(options)}: #{inspect(err)}"
end
end

defp add_body_or_params_to_request(%Request{args: args} = request) do
case Keyword.pop(args, :body) do
{nil, _} ->
Expand Down Expand Up @@ -264,7 +269,7 @@ defmodule SimpleHttp do
defp debug?(%Request{args: args} = request) do
case Keyword.get(args, :debug) do
nil -> request
_ -> IO.inspect(request)
_ -> IO.puts("Request: #{inspect(request, pretty: true)}")
end
end
end

0 comments on commit 8a2b780

Please sign in to comment.