From 688731cdb03d086cdadf46e97054539152cdc630 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sat, 10 Mar 2018 01:12:28 +0100 Subject: [PATCH] Revert "Add remote context processing (#2) [WIP]" This reverts commit aac4127aeb449cbbee84d36cfce9155f6f4d4bab. --- lib/json/ld/context.ex | 42 +------------------ lib/json/ld/document_loader.ex | 11 ----- lib/json/ld/document_loader/default.ex | 20 --------- .../ld/document_loader/remote_document.ex | 9 ---- mix.exs | 1 - mix.lock | 1 - test/suite/error_test.exs | 3 ++ 7 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 lib/json/ld/document_loader.ex delete mode 100644 lib/json/ld/document_loader/default.ex delete mode 100644 lib/json/ld/document_loader/remote_document.ex diff --git a/lib/json/ld/context.ex b/lib/json/ld/context.ex index e500d4b..c1e4c5e 100644 --- a/lib/json/ld/context.ex +++ b/lib/json/ld/context.ex @@ -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) diff --git a/lib/json/ld/document_loader.ex b/lib/json/ld/document_loader.ex deleted file mode 100644 index f6bde4a..0000000 --- a/lib/json/ld/document_loader.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule JSON.LD.DocumentLoader do - @moduledoc """ - Loader used to retrieve remote documents and contexts. - - as specified at - """ - - alias JSON.LD.DocumentLoader.RemoteDocument - - @callback load(String.t, JSON.LD.Options.t) :: {:ok, RemoteDocument.t} | {:error, any} -end diff --git a/lib/json/ld/document_loader/default.ex b/lib/json/ld/document_loader/default.ex deleted file mode 100644 index c8cbebb..0000000 --- a/lib/json/ld/document_loader/default.ex +++ /dev/null @@ -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 diff --git a/lib/json/ld/document_loader/remote_document.ex b/lib/json/ld/document_loader/remote_document.ex deleted file mode 100644 index cf06589..0000000 --- a/lib/json/ld/document_loader/remote_document.ex +++ /dev/null @@ -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 diff --git a/mix.exs b/mix.exs index 388bfc2..f948e46 100644 --- a/mix.exs +++ b/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}, diff --git a/mix.lock b/mix.lock index c6a3156..9f2e8f4 100644 --- a/mix.lock +++ b/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], []}, diff --git a/test/suite/error_test.exs b/test/suite/error_test.exs index 3715482..acd8579 100644 --- a/test/suite/error_test.exs +++ b/test/suite/error_test.exs @@ -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