Packages
An Elixir library for searching and fetching controlled vocabulary authority terms
Current section
38 Versions
Jump to
Current section
38 Versions
Compare versions
7
files changed
+67
additions
-28
deletions
| @@ -46,6 +46,13 @@ config :authoritex, | |
| 46 46 | Authoritex.LOC.SubjectHeadings, |
| 47 47 | Authoritex.LOC |
| 48 48 | ] |
| 49 | + |
| 50 | + # Authoritex uses httpoison_retry https://github.com/mgwidmann/httpoison_retry |
| 51 | + # Override the config in your application if needed |
| 52 | + config :httpoison_retry, |
| 53 | + max_attempts: 3, |
| 54 | + wait: 1_000, |
| 55 | + retry_unknown_errors: false |
| 49 56 | ``` |
| 50 57 | |
| 51 58 | ## Usage |
| @@ -19,8 +19,7 @@ | |
| 19 19 | <<"lib/authoritex/mock.ex">>,<<"lib/authoritex/getty">>, |
| 20 20 | <<"lib/authoritex/getty/ulan.ex">>,<<"lib/authoritex/getty/tgn.ex">>, |
| 21 21 | <<"lib/authoritex/getty/base.ex">>,<<"lib/authoritex/getty/aat.ex">>, |
| 22 | - <<"lib/mix">>,<<"lib/authoritex.ex">>,<<"mix.exs">>,<<"README.md">>, |
| 23 | - <<"LICENSE.md">>]}. |
| 22 | + <<"lib/authoritex.ex">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE.md">>]}. |
| 24 23 | {<<"licenses">>,[<<"MIT">>]}. |
| 25 24 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/nulib/authoritex">>}]}. |
| 26 25 | {<<"name">>,<<"authoritex">>}. |
| @@ -30,6 +29,11 @@ | |
| 30 29 | {<<"optional">>,false}, |
| 31 30 | {<<"repository">>,<<"hexpm">>}, |
| 32 31 | {<<"requirement">>,<<"~> 1.6.2">>}], |
| 32 | + [{<<"app">>,<<"httpoison_retry">>}, |
| 33 | + {<<"name">>,<<"httpoison_retry">>}, |
| 34 | + {<<"optional">>,false}, |
| 35 | + {<<"repository">>,<<"hexpm">>}, |
| 36 | + {<<"requirement">>,<<"~> 1.0.0">>}], |
| 33 37 | [{<<"app">>,<<"jason">>}, |
| 34 38 | {<<"name">>,<<"jason">>}, |
| 35 39 | {<<"optional">>,false}, |
| @@ -40,4 +44,4 @@ | |
| 40 44 | {<<"optional">>,false}, |
| 41 45 | {<<"repository">>,<<"hexpm">>}, |
| 42 46 | {<<"requirement">>,<<"~> 0.6">>}]]}. |
| 43 | - {<<"version">>,<<"0.3.0">>}. |
| 47 | + {<<"version">>,<<"0.4.0">>}. |
| @@ -11,6 +11,7 @@ defmodule Authoritex.FAST.Base do | |
| 11 11 | ] do |
| 12 12 | @behaviour Authoritex |
| 13 13 | |
| 14 | + import HTTPoison.Retry |
| 14 15 | import SweetXml, only: [sigil_x: 2] |
| 15 16 | |
| 16 17 | @impl Authoritex |
| @@ -31,9 +32,13 @@ defmodule Authoritex.FAST.Base do | |
| 31 32 | end |
| 32 33 | |
| 33 34 | def fetch(id) do |
| 34 | - case id |
| 35 | + request = |
| 36 | + id |
| 35 37 | |> add_trailing_slash() |
| 36 | - |> HTTPoison.get([{"Content-Type", "application/json;"}], []) do |
| 38 | + |> HTTPoison.get([{"Content-Type", "application/json;"}], []) |
| 39 | + |> autoretry() |
| 40 | + |
| 41 | + case request do |
| 37 42 | {:ok, response} -> |
| 38 43 | parse_fetch_result(response) |
| 39 44 | |
| @@ -54,6 +59,7 @@ defmodule Authoritex.FAST.Base do | |
| 54 59 | "&rows=#{max_results}", |
| 55 60 | [{"Content-Type", "application/json;"}] |
| 56 61 | ) |
| 62 | + |> autoretry() |
| 57 63 | |
| 58 64 | case request do |
| 59 65 | {:ok, %{body: response, status_code: 200}} -> |
| @@ -2,6 +2,8 @@ defmodule Authoritex.GeoNames do | |
| 2 2 | @moduledoc "Authoritex implementation for GeoNames webservice" |
| 3 3 | @behaviour Authoritex |
| 4 4 | |
| 5 | + import HTTPoison.Retry |
| 6 | + |
| 5 7 | @http_uri_base "https://sws.geonames.org/" |
| 6 8 | |
| 7 9 | @error_codes %{ |
| @@ -37,14 +39,18 @@ defmodule Authoritex.GeoNames do | |
| 37 39 | def fetch(id) do |
| 38 40 | @http_uri_base <> geoname_id = id |
| 39 41 | |
| 40 | - case HTTPoison.get( |
| 42 | + request = |
| 43 | + HTTPoison.get( |
| 41 44 | "http://api.geonames.org/getJSON", |
| 42 45 | [{"User-Agent", "Authoritex"}], |
| 43 46 | params: [ |
| 44 47 | geonameId: geoname_id, |
| 45 48 | username: username() |
| 46 49 | ] |
| 47 | - ) do |
| 50 | + ) |
| 51 | + |> autoretry() |
| 52 | + |
| 53 | + case request do |
| 48 54 | {:ok, %{body: response, status_code: 200}} -> |
| 49 55 | parse_fetch_result(response) |
| 50 56 | |
| @@ -58,7 +64,8 @@ defmodule Authoritex.GeoNames do | |
| 58 64 | |
| 59 65 | @impl Authoritex |
| 60 66 | def search(query, max_results \\ 30) do |
| 61 | - case HTTPoison.get( |
| 67 | + request = |
| 68 | + HTTPoison.get( |
| 62 69 | "http://api.geonames.org/searchJSON", |
| 63 70 | [{"User-Agent", "Authoritex"}], |
| 64 71 | params: [ |
| @@ -66,7 +73,10 @@ defmodule Authoritex.GeoNames do | |
| 66 73 | username: username(), |
| 67 74 | maxRows: max_results |
| 68 75 | ] |
| 69 | - ) do |
| 76 | + ) |
| 77 | + |> autoretry() |
| 78 | + |
| 79 | + case request do |
| 70 80 | {:ok, %{body: response, status_code: 200}} -> |
| 71 81 | {:ok, parse_search_result(response)} |
| @@ -11,6 +11,7 @@ defmodule Authoritex.Getty.Base do | |
| 11 11 | ] do |
| 12 12 | @behaviour Authoritex |
| 13 13 | |
| 14 | + import HTTPoison.Retry |
| 14 15 | import SweetXml, only: [sigil_x: 2] |
| 15 16 | |
| 16 17 | @impl Authoritex |
| @@ -72,6 +73,7 @@ defmodule Authoritex.Getty.Base do | |
| 72 73 | |> String.trim() |
| 73 74 | ] |
| 74 75 | ) |
| 76 | + |> autoretry() |
| 75 77 | end |
| 76 78 | |
| 77 79 | defp parse_sparql_result({:ok, %{body: response, status_code: 200}}) do |
Loading more files…