diff --git a/lib/decentralised_book_index/sync/data_transformers/author_transformer.ex b/lib/decentralised_book_index/sync/data_transformers/author_transformer.ex index 126aed3..59838e2 100644 --- a/lib/decentralised_book_index/sync/data_transformers/author_transformer.ex +++ b/lib/decentralised_book_index/sync/data_transformers/author_transformer.ex @@ -1,22 +1,20 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.AuthorTransformer do def from_json(json_body) do - attrs = + json_body = if Map.has_key?(json_body, "data") do - %{ - id: get_in(json_body, ["data", "id"]), - name: get_in(json_body, ["data", "attributes", "name"]), - description: get_in(json_body, ["data", "attributes", "description"]), - avatar_url: get_in(json_body, ["data", "attributes", "avatar_url"]), - } + json_body["data"] else - %{ - id: get_in(json_body, ["id"]), - name: get_in(json_body, ["attributes", "name"]), - description: get_in(json_body, ["attributes", "description"]), - avatar_url: get_in(json_body, ["attributes", "avatar_url"]), - } + json_body end + attrs = + %{ + id: get_in(json_body, ["id"]), + name: get_in(json_body, ["attributes", "name"]), + description: get_in(json_body, ["attributes", "description"]), + avatar_url: get_in(json_body, ["attributes", "avatar_url"]) + } + {:ok, attrs} end end diff --git a/lib/decentralised_book_index/sync/data_transformers/publisher_transformer.ex b/lib/decentralised_book_index/sync/data_transformers/publisher_transformer.ex index 77a14e1..0b52f2b 100644 --- a/lib/decentralised_book_index/sync/data_transformers/publisher_transformer.ex +++ b/lib/decentralised_book_index/sync/data_transformers/publisher_transformer.ex @@ -1,22 +1,20 @@ defmodule DecentralisedBookIndex.Sync.DataTransformers.PublisherTransformer do def from_json(json_body) do - attrs = + json_body = if Map.has_key?(json_body, "data") do - %{ - id: get_in(json_body, ["data", "id"]), - name: get_in(json_body, ["data", "attributes", "name"]), - inserted_at: get_in(json_body, ["data", "attributes", "inserted_at"]), - updated_at: get_in(json_body, ["data", "attributes", "updated_at"]), - } + json_body["data"] else - %{ - id: get_in(json_body, ["id"]), - name: get_in(json_body, ["attributes", "name"]), - inserted_at: get_in(json_body, ["attributes", "inserted_at"]), - updated_at: get_in(json_body, ["attributes", "updated_at"]), - } + json_body end + attrs = + %{ + id: get_in(json_body, ["id"]), + name: get_in(json_body, ["attributes", "name"]), + inserted_at: get_in(json_body, ["attributes", "inserted_at"]), + updated_at: get_in(json_body, ["attributes", "updated_at"]) + } + {:ok, attrs} end end