pterotype/inc/api.php

88 lines
2.8 KiB
PHP
Raw Normal View History

2018-08-21 13:17:07 +00:00
<?php
2018-08-21 21:52:56 +00:00
namespace api;
require_once plugin_dir_path( __FILE__ ) . '/actors.php';
2018-08-23 02:39:59 +00:00
require_once plugin_dir_path( __FILE__ ) . '/outbox.php';
require_once plugin_dir_path( __FILE__ ) . '/objects.php';
require_once plugin_dir_path( __FILE__ ) . '/activities.php';
require_once plugin_dir_path( __FILE__ ) . '/following.php';
require_once plugin_dir_path( __FILE__ ) . '/likes.php';
require_once plugin_dir_path( __FILE__ ) . '/shares.php';
2018-08-21 13:17:07 +00:00
function get_actor( $request ) {
2018-08-29 20:47:56 +00:00
$actor = $request['actor'];
2018-09-04 01:33:14 +00:00
return \actors\get_actor_by_slug( $actor );
2018-08-21 13:17:07 +00:00
}
function post_to_outbox( $request ) {
$actor_slug = $request['actor'];
2018-08-29 21:04:24 +00:00
$activity = json_decode( $request->get_body(), true );
return \outbox\handle_activity( $actor_slug, $activity );
}
function get_outbox( $request ) {
$actor_slug = $request['actor'];
return \outbox\get_outbox( $actor_slug );
2018-08-23 02:39:59 +00:00
}
function get_object( $request ) {
$id = $request['id'];
return \objects\get_object( $id );
}
function get_activity( $request ) {
$id = $request['id'];
return \activities\get_activity( $id );
}
function get_following( $request ) {
$actor_slug = $request['actor'];
return \following\get_following_collection( $actor_slug );
}
function get_likes( $request ) {
$object_id = $request['object'];
return \likes\get_likes_collection( $object_id );
}
function get_shares( $request ) {
$object_id = $request['object'];
return \shares\get_shares_collection( $object_id );
}
2018-08-21 21:52:56 +00:00
function register_routes() {
2018-09-19 15:16:41 +00:00
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/outbox', array(
2018-08-29 21:18:45 +00:00
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\post_to_outbox',
) );
2018-09-19 15:16:41 +00:00
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+/outbox', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\get_outbox',
2018-08-29 21:18:45 +00:00
) );
2018-09-19 15:16:41 +00:00
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)', array(
2018-08-21 13:17:07 +00:00
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_actor',
2018-08-21 13:17:07 +00:00
) );
2018-09-19 15:16:41 +00:00
register_rest_route( 'pterotype/v1', '/object/(?P<id>[0-9]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_object',
) );
2018-09-19 15:16:41 +00:00
register_rest_route( 'pterotype/v1', '/activity/(?P<id>[0-9]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_activity',
) );
register_rest_route( 'pterotype/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/following', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_following',
) );
register_rest_route( 'pterotype/v1', '/object/(?P<object>[0-9]+)/likes', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_likes',
) );
register_rest_route( 'pterotype/v1', '/object/(?P<object>[0-9]+)/shares', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_shares',
) );
2018-08-21 21:52:56 +00:00
}
2018-08-21 13:17:07 +00:00
?>