Packages

Environment configuration parser. Purely functional, server free.

Current section

Files

Jump to
analytics_3i lib analytics_3i parsers content.ex
Raw

lib/analytics_3i/parsers/content.ex

defmodule Analytics3i.Parsers.Content do
use Analytics3i.Parsers.Base
alias Analytics3i.{Parsers.ContentParser}
require Logger
@endpoint "/content"
def request(id, opts \\ %{}, connector \\ &Connector.request/5) when is_map(opts) do
payload = request_body(id, opts)
result = case connector.(:post, @endpoint, payload, [], [hackney: [pool: :connector_store_pool]]) do
{:ok, body} ->
case body |> ContentParser.parse_body(id) do
{:ok, data} -> {:ok, data}
{:error, e} -> {:error, e}
end
{:error, e} -> {:error, e}
:timeout -> {:error, :timeout}
_ -> {:error, nil}
end
end
def request_body(id, opts) do
options = Map.merge %{
timeZone: "+03:00",
# mappingDefinition: %{index: "news_actual", type: "news", locale: "ru"},
collection: %{ name: "news" },
id: id,
query: "",
fields: ~w(
author.value
parent
created_date
modified_date
source_site
source_type
speech_to_text
sentiment.value
url
id
_id
polarity
text
images
original_image
entities
persons
others.value
others.polarity
others.count
others.data_id
organizations
categories.value
categories.data_id
),
highlightFields: ~w(text),
sorts: ~w(),
from: 0,
size: 1,
withId: true,
withTitle: true,
withSnippet: false,
withRank: true,
highlightTitle: false,
highlighterPreTags: ["<span data-term>"],
highlighterPostTags: ["</span>"]
}, opts
Logger.debug("Content options ##{id}: #{inspect options}")
options
end
end