Skip to content

Commit

Permalink
Merge pull request #35 from WTTJ/fix/list-get-member-timeout-case
Browse files Browse the repository at this point in the history
fix(list): handle mailchimp timeout on list#get_member
  • Loading branch information
duartejc authored Oct 3, 2023
2 parents db1287e + e095573 commit d389114
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
11 changes: 6 additions & 5 deletions lib/mailchimp/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,15 @@ defmodule Mailchimp.List do
|> String.downcase()
|> md5

{:ok, response} = HTTPClient.get(href <> "/#{subscriber_id}")

case response do
%Response{status_code: 200, body: body} ->
case HTTPClient.get(href <> "/#{subscriber_id}") do
{:ok, %Response{status_code: 200, body: body}} ->
{:ok, Member.new(body)}

%Response{status_code: _, body: body} ->
{:ok, %Response{status_code: _, body: body}} ->
{:error, body}

{:error, %Error{reason: reason}} ->
{:error, reason}
end
end

Expand Down
23 changes: 13 additions & 10 deletions lib/mailchimp/member.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Mailchimp.Member do
alias Mailchimp.Link
alias HTTPoison.Response
alias HTTPoison.{Error, Response}
alias Mailchimp.HTTPClient

@moduledoc """
Expand Down Expand Up @@ -115,14 +115,15 @@ defmodule Mailchimp.Member do
|> Map.delete(:links)
|> Map.delete(:__struct__)

{:ok, response} = HTTPClient.put(href, Jason.encode!(attrs))

case response do
%Response{status_code: 200, body: body} ->
case HTTPClient.put(href, Jason.encode!(attrs)) do
{:ok, %Response{status_code: 200, body: body}} ->
{:ok, new(body)}

%Response{status_code: _, body: body} ->
{:ok, %Response{status_code: _, body: body}} ->
{:error, body}

{:error, %Error{reason: reason}} ->
{:error, reason}
end
end

Expand All @@ -141,14 +142,16 @@ defmodule Mailchimp.Member do
def update_tags(user = %__MODULE__{links: %{"update" => %Link{href: href}}, tags: tags})
when is_list(tags) do
attrs = %{tags: tags}
{:ok, response} = HTTPClient.post(href <> "/tags", Jason.encode!(attrs))

case response do
%Response{status_code: 204, body: _body} ->
case HTTPClient.post(href <> "/tags", Jason.encode!(attrs)) do
{:ok, %Response{status_code: 204, body: _body}} ->
{:ok, user}

%Response{status_code: _code, body: body} ->
{:ok, %Response{status_code: _, body: body}} ->
{:error, body}

{:error, %Error{reason: reason}} ->
{:error, reason}
end
end

Expand Down

0 comments on commit d389114

Please sign in to comment.