From 7e3590eb9eb01abed8265e7ec3c2b4bfe6250d79 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 29 Aug 2018 16:43:15 -0400 Subject: [PATCH] Add GET /activity endpoint; tidy up api --- inc/actors.php | 2 +- inc/api.php | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/inc/actors.php b/inc/actors.php index c597486..31482bc 100644 --- a/inc/actors.php +++ b/inc/actors.php @@ -1,7 +1,7 @@ get('ID')); $actor = array( "@context" => array( "https://www.w3.org/ns/activitystreams" ), diff --git a/inc/api.php b/inc/api.php index 3cc7405..2b59485 100644 --- a/inc/api.php +++ b/inc/api.php @@ -4,17 +4,18 @@ namespace api; require_once plugin_dir_path( __FILE__ ) . '/actors.php'; require_once plugin_dir_path( __FILE__ ) . '/outbox.php'; require_once plugin_dir_path( __FILE__ ) . '/objects.php'; +require_once plugin_dir_path( __FILE__ ) . '/activities.php'; -function get_user_actor( $request ) { - $handle = $request['handle']; - $id = get_user_by( 'slug', $handle ); - return \actors\user_to_actor( $id ); +function get_actor( $request ) { + $actor = $request['handle']; + $user = get_user_by( 'slug', $actor ); + return \actors\get_actor( $user ); } function post_to_outbox( $request ) { - $handle = $request['handle'] ; + $actor = $request['handle'] ; $activity = json_decode( $request->get_body() ); - return \outbox\persist_activity( $handle, $activity ); + return \outbox\handle_activity( $actor, $activity ); } function get_object( $request ) { @@ -22,10 +23,15 @@ function get_object( $request ) { return \objects\get_object( $id ); } +function get_activity( $request ) { + $id = $request['id']; + return \activities\get_activity( $id ); +} + function register_routes() { register_rest_route( 'activitypub/v1', '/actor/(?P[a-zA-Z0-9-]+)', array( 'methods' => 'GET', - 'callback' => __NAMESPACE__ . '\get_user_actor', + 'callback' => __NAMESPACE__ . '\get_actor', ) ); register_rest_route( 'activitypub/v1', '/actor/(?P[a-zA-Z0-9-]+)/outbox', array( 'methods' => 'POST', @@ -35,5 +41,9 @@ function register_routes() { 'methods' => 'GET', 'callback' => __NAMESPACE__ . '\get_object', ) ); + register_rest_route( 'activitypub/v1', '/activity/(?P[0-9]+)', array( + 'methods' => 'GET', + 'callback' => __NAMESPACE__ . '\get_activity', + ) ); } ?>