Revert "Add remote context processing (#2) [WIP]"
This reverts commit aac4127aeb
.
This commit is contained in:
parent
aac4127aeb
commit
688731cdb0
7 changed files with 4 additions and 83 deletions
|
@ -46,47 +46,7 @@ defmodule JSON.LD.Context do
|
|||
|
||||
# 3.2) If context is a string, [it's interpreted as a remote context]
|
||||
defp do_update(%JSON.LD.Context{} = active, local, remote, options) when is_binary(local) do
|
||||
# 3.2.1)
|
||||
local = absolute_iri(local, base(active))
|
||||
|
||||
# 3.2.2)
|
||||
if local in remote do
|
||||
raise JSON.LD.RecursiveContextInclusionError,
|
||||
message: "Recursive context inclusion: #{local}"
|
||||
end
|
||||
remote = remote ++ [local]
|
||||
|
||||
# 3.2.3)
|
||||
document_loader = options.document_loader || JSON.LD.DocumentLoader.Default
|
||||
|
||||
document = try do
|
||||
case apply(document_loader, :load, [local, options]) do
|
||||
{:ok, result} -> result.document
|
||||
{:error, reason} -> raise JSON.LD.LoadingRemoteContextFailedError,
|
||||
message: "Could not load remote context (#{local}): #{inspect reason}"
|
||||
end
|
||||
rescue
|
||||
e -> raise JSON.LD.LoadingRemoteContextFailedError,
|
||||
message: "Could not load remote context: #{inspect e}"
|
||||
end
|
||||
document = cond do
|
||||
is_map(document) -> document
|
||||
is_binary(document) -> case Poison.decode(document) do
|
||||
{:ok, result} -> result
|
||||
{:error, reason} -> raise JSON.LD.InvalidRemoteContextError,
|
||||
message: "Context is not a valid JSON document: #{inspect reason}"
|
||||
end
|
||||
true -> raise JSON.LD.InvalidRemoteContextError,
|
||||
message: "Context is not a valid JSON object: #{inspect document}"
|
||||
end
|
||||
local = case document["@context"] do
|
||||
nil -> raise JSON.LD.InvalidRemoteContextError,
|
||||
message: "Invalid remote context: No @context key in #{inspect document}"
|
||||
value -> value
|
||||
end
|
||||
|
||||
# 3.2.4) - 3.2.5)
|
||||
do_update(active, local, remote, options)
|
||||
# TODO: fetch remote context and call recursively with remote updated
|
||||
end
|
||||
|
||||
# 3.4) - 3.8)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
defmodule JSON.LD.DocumentLoader do
|
||||
@moduledoc """
|
||||
Loader used to retrieve remote documents and contexts.
|
||||
|
||||
as specified at <https://www.w3.org/TR/json-ld-api/#idl-def-LoadDocumentCallback>
|
||||
"""
|
||||
|
||||
alias JSON.LD.DocumentLoader.RemoteDocument
|
||||
|
||||
@callback load(String.t, JSON.LD.Options.t) :: {:ok, RemoteDocument.t} | {:error, any}
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
defmodule JSON.LD.DocumentLoader.Default do
|
||||
@behaviour JSON.LD.DocumentLoader
|
||||
|
||||
alias JSON.LD.DocumentLoader.RemoteDocument
|
||||
|
||||
def load(url, _options) do
|
||||
with {:ok, res} <- HTTPoison.get(url, [accept: "application/ld+json"],
|
||||
[follow_redirect: true]),
|
||||
{:ok, data} <- Poison.decode(res.body)
|
||||
do
|
||||
result = %RemoteDocument{
|
||||
document: data,
|
||||
document_url: res.request_url,
|
||||
}
|
||||
{:ok, result}
|
||||
else
|
||||
{:error, reason} -> {:error, reason}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule JSON.LD.DocumentLoader.RemoteDocument do
|
||||
@type t :: %JSON.LD.DocumentLoader.RemoteDocument{context_url: String.t,
|
||||
document_url: String.t,
|
||||
document: any}
|
||||
|
||||
defstruct context_url: nil,
|
||||
document_url: nil,
|
||||
document: nil
|
||||
end
|
1
mix.exs
1
mix.exs
|
@ -61,7 +61,6 @@ defmodule JSON.LD.Mixfile do
|
|||
[
|
||||
{:rdf, "~> 0.3"},
|
||||
{:poison, "~> 3.0"},
|
||||
{:httpoison, "~> 0.13"},
|
||||
{:dialyxir, "~> 0.4", only: [:dev, :test], runtime: false},
|
||||
{:credo, "~> 0.6", only: [:dev, :test], runtime: false},
|
||||
{:ex_doc, "~> 0.14", only: :dev, runtime: false},
|
||||
|
|
1
mix.lock
1
mix.lock
|
@ -8,7 +8,6 @@
|
|||
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
|
||||
"fs": {:hex, :fs, "2.12.0", "ad631efacc9a5683c8eaa1b274e24fa64a1b8eb30747e9595b93bec7e492e25e", [:rebar3], []},
|
||||
"hackney": {:hex, :hackney, "1.9.0", "51c506afc0a365868469dcfc79a9d0b94d896ec741cfd5bd338f49a5ec515bfe", [:rebar3], [{:certifi, "2.0.0", [hex: :certifi, optional: false]}, {:idna, "5.1.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
|
||||
"httpoison": {:hex, :httpoison, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, optional: false]}]},
|
||||
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []},
|
||||
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
|
||||
|
|
|
@ -9,6 +9,9 @@ defmodule JSON.LD.TestSuite.ErrorTest do
|
|||
|
||||
test_cases("error")
|
||||
|> Enum.each(fn %{"name" => name, "input" => input} = test_case ->
|
||||
if input in ~w[error-0002-in.jsonld error-0003-in.jsonld error-0004-in.jsonld error-0005-in.jsonld] do
|
||||
@tag skip: "TODO: remote contexts not implemented yet"
|
||||
end
|
||||
@tag :test_suite
|
||||
@tag :flatten_test_suite
|
||||
@tag :error_test
|
||||
|
|
Loading…
Reference in a new issue