Add/update API transformers

This commit is contained in:
Daniel Supernault 2018-12-30 21:26:37 -07:00
parent 982aecb4cc
commit 547ac5c8f9
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
9 changed files with 148 additions and 60 deletions

View file

@ -7,27 +7,27 @@ use League\Fractal;
class AccountTransformer extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
return [
'id' => $profile->id,
'username' => $profile->username,
'acct' => $profile->username,
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
'created_at' => $profile->created_at->format('c'),
'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(),
'statuses_count' => $profile->statusCount(),
'note' => $profile->bio,
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => null,
'header_static' => null,
'moved' => null,
'fields' => null,
'bot' => null,
];
}
public function transform(Profile $profile)
{
return [
'id' => $profile->id,
'username' => $profile->username,
'acct' => $profile->username,
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
'created_at' => $profile->created_at->format('c'),
'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(),
'statuses_count' => $profile->statusCount(),
'note' => $profile->bio,
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => null,
'header_static' => null,
'moved' => null,
'fields' => null,
'bot' => null,
];
}
}

View file

@ -6,11 +6,11 @@ use League\Fractal;
class ApplicationTransformer extends Fractal\TransformerAbstract
{
public function transform()
{
return [
'name' => '',
'website' => null,
];
}
public function transform()
{
return [
'name' => '',
'website' => null,
];
}
}

View file

@ -0,0 +1,28 @@
<?php
namespace App\Transformer\Api;
use League\Fractal;
class AttachmentTransformer extends Fractal\TransformerAbstract
{
public function transform(Media $media)
{
return [
'id' => $media->id,
'type' => $media->activityVerb(),
'url' => $media->url(),
'remote_url' => null,
'preview_url' => $media->thumbnailUrl(),
'text_url' => null,
'meta' => null,
'description' => $media->caption,
'license' => $media->license,
'is_nsfw' => $media->is_nsfw,
'orientation' => $media->orientation,
'filter_name' => $media->filter_name,
'filter_class' => $media->filter_class,
'mime' => $media->mime,
];
}
}

View file

@ -0,0 +1,16 @@
<?php
namespace App\Transformer\Api;
use League\Fractal;
class ContextTransformer extends Fractal\TransformerAbstract
{
public function transform()
{
return [
'ancestors' => [],
'descendants' => []
];
}
}

View file

@ -6,13 +6,13 @@ use League\Fractal;
class EmojiTransformer extends Fractal\TransformerAbstract
{
public function transform($emoji)
{
return [
'shortcode' => '',
'static_url' => '',
'url' => '',
'visible_in_picker' => false
];
}
public function transform($emoji)
{
return [
'shortcode' => '',
'static_url' => '',
'url' => '',
'visible_in_picker' => false
];
}
}

View file

@ -0,0 +1,20 @@
<?php
namespace App\Transformer\Api;
use League\Fractal;
class FilterTransformer extends Fractal\TransformerAbstract
{
public function transform()
{
return [
'id' => (string) '',
'phrase' => (string) '',
'context' => [],
'expires_at' => null,
'irreversible' => (bool) false,
'whole_word' => (bool) false
];
}
}

View file

@ -7,11 +7,11 @@ use League\Fractal;
class HashtagTransformer extends Fractal\TransformerAbstract
{
public function transform(Hashtag $hashtag)
{
return [
'name' => $hashtag->name,
'url' => $hashtag->url(),
];
}
public function transform(Hashtag $hashtag)
{
return [
'name' => $hashtag->name,
'url' => $hashtag->url(),
];
}
}

View file

@ -10,20 +10,20 @@ class MediaTransformer extends Fractal\TransformerAbstract
public function transform(Media $media)
{
return [
'id' => $media->id,
'type' => $media->activityVerb(),
'url' => $media->url(),
'remote_url' => null,
'preview_url' => $media->thumbnailUrl(),
'text_url' => null,
'meta' => null,
'description' => $media->caption,
'license' => $media->license,
'is_nsfw' => $media->is_nsfw,
'orientation' => $media->orientation,
'filter_name' => $media->filter_name,
'filter_class' => $media->filter_class,
'mime' => $media->mime,
'id' => $media->id,
'type' => $media->activityVerb(),
'url' => $media->url(),
'remote_url' => null,
'preview_url' => $media->thumbnailUrl(),
'text_url' => null,
'meta' => null,
'description' => $media->caption,
'license' => $media->license,
'is_nsfw' => $media->is_nsfw,
'orientation' => $media->orientation,
'filter_name' => $media->filter_name,
'filter_class' => $media->filter_class,
'mime' => $media->mime,
];
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace App\Transformer\Api;
use League\Fractal;
class ResultsTransformer extends Fractal\TransformerAbstract
{
protected $defaultIncludes = [
'account',
'mentions',
'media_attachments',
'tags',
];
public function transform()
{
return [
'accounts' => [],
'statuses' => [],
'hashtags' => []
];
}
}