Add GET /activity endpoint; tidy up api
This commit is contained in:
parent
cfc1f87b71
commit
7e3590eb9e
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace actors;
|
||||
|
||||
function user_to_actor( $user ) {
|
||||
function get_actor( $user ) {
|
||||
$handle = get_the_author_meta( 'user_nicename', $user->get('ID'));
|
||||
$actor = array(
|
||||
"@context" => array( "https://www.w3.org/ns/activitystreams" ),
|
||||
|
24
inc/api.php
24
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<handle>[a-zA-Z0-9-]+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => __NAMESPACE__ . '\get_user_actor',
|
||||
'callback' => __NAMESPACE__ . '\get_actor',
|
||||
) );
|
||||
register_rest_route( 'activitypub/v1', '/actor/(?P<handle>[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<id>[0-9]+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => __NAMESPACE__ . '\get_activity',
|
||||
) );
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user