Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions elixir/sample_mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule Elixir.MixProject do
use Mix.Project

def project do
[
app: :elixir,
version: "0.1.0",
elixir: "~> 1.12",
compilers: Mix.compilers(),
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# ...

def deps do
[
# TODO: Add this into your project and check the latest version from: https://hexdocs.pm/aws/readme.html#installation
{:aws, "~> 0.13.0"},
{:hackney, "~> 1.18"}
]
end

# ...
end
47 changes: 47 additions & 0 deletions elixir/services/textract.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule Elixir.Textract do
@moduledoc """
A sample code example in Elixir.
"""

@doc """
Analyze document.
> Copy this function into your Elixir project and copy the `deps/0` in `mix_sample.exs` into your `mix.exs`.

## Examples
# Run this to try out `analyze_document/3`/`analyze_document/4`
YourProject.Textract.analyze_document("access_key", "secret_key", "region", "path")

> More explanations here: https://docs.aws.amazon.com/textract/latest/dg/how-it-works-analyzing.html

Example provided by @enkr1 | [email protected]

"""
def analyze_document(access_key, secret_key, region, png_path \\ "/path/to/png") do
case AWS.Client.create(access_key, secret_key, region)
|> AWS.Textract.analyze_document(%{
"Document" => %{"Bytes" => png_path |> File.read!() |> Base.encode64()},
"FeatureTypes" => ["TABLES", "FORMS"]
}) do
{
:ok,
%{
"AnalyzeDocumentModelVersion" => _,
"Blocks" => blocks,
"DocumentMetadata" => _
} = _result_map,
response = _map_with_encoded_body_str
} ->
# ...
response |> IO.inspect(label: "response")

{:error, {_key, %{body: reason}} = reason_tupple} ->
# ...
reason_tupple |> IO.inspect(label: "reason_tupple")
{:error, reason}

edge_case ->
edge_case |> IO.inspect(label: "edge_case")
{:error, "Something went wrong when extracting the file ..."}
end
end
end