Basic AP objects.
authorRoger Braun <roger@rogerbraun.net>
Tue, 21 Mar 2017 08:21:52 +0000 (09:21 +0100)
committerRoger Braun <roger@rogerbraun.net>
Tue, 21 Mar 2017 08:21:52 +0000 (09:21 +0100)
lib/pleroma/activity.ex [new file with mode: 0644]
lib/pleroma/object.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/activity_pub.ex [new file with mode: 0644]
priv/repo/migrations/20170321074828_create_activity.exs [new file with mode: 0644]
priv/repo/migrations/20170321074832_create_object.exs [new file with mode: 0644]
test/web/activity_pub/activity_pub_test.exs [new file with mode: 0644]

diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
new file mode 100644 (file)
index 0000000..c4efc62
--- /dev/null
@@ -0,0 +1,9 @@
+defmodule Pleroma.Activity do
+  use Ecto.Schema
+
+  schema "activities" do
+    field :data, :map
+
+    timestamps()
+  end
+end
diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex
new file mode 100644 (file)
index 0000000..a31f40d
--- /dev/null
@@ -0,0 +1,9 @@
+defmodule Pleroma.Object do
+  use Ecto.Schema
+
+  schema "objects" do
+    field :data, :map
+
+    timestamps()
+  end
+end
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
new file mode 100644 (file)
index 0000000..b70f4db
--- /dev/null
@@ -0,0 +1,8 @@
+defmodule Pleroma.Web.ActivityPub.ActivityPub do
+  alias Pleroma.Repo
+  alias Pleroma.Activity
+
+  def insert(map) when is_map(map) do
+    Repo.insert(%Activity{data: map})
+  end
+end
diff --git a/priv/repo/migrations/20170321074828_create_activity.exs b/priv/repo/migrations/20170321074828_create_activity.exs
new file mode 100644 (file)
index 0000000..6e875ae
--- /dev/null
@@ -0,0 +1,14 @@
+defmodule Pleroma.Repo.Migrations.CreatePleroma.Activity do
+  use Ecto.Migration
+
+  def change do
+    create table(:activities) do
+      add :data, :map
+
+      timestamps()
+    end
+
+    create index(:activities, [:data], using: :gin)
+
+  end
+end
diff --git a/priv/repo/migrations/20170321074832_create_object.exs b/priv/repo/migrations/20170321074832_create_object.exs
new file mode 100644 (file)
index 0000000..b8bd497
--- /dev/null
@@ -0,0 +1,12 @@
+defmodule Pleroma.Repo.Migrations.CreatePleroma.Object do
+  use Ecto.Migration
+
+  def change do
+    create table(:objects) do
+      add :data, :map
+
+      timestamps()
+    end
+
+  end
+end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
new file mode 100644 (file)
index 0000000..1b4b121
--- /dev/null
@@ -0,0 +1,17 @@
+defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
+  use Pleroma.DataCase
+  alias Pleroma.Web.ActivityPub.ActivityPub
+  alias Pleroma.Activity
+
+  describe "insertion" do
+    test "inserts a given map into the activity database" do
+      data = %{
+        ok: true
+      }
+
+      {:ok, %Activity{} = activity} = ActivityPub.insert(data)
+      assert activity.data == data
+    end
+  end
+
+end