Change methods to be top level with names

based on OP codes. classes changed to
extensions of `V1` class
This commit is contained in:
krawieck 2020-08-06 22:06:53 +02:00
parent 4ad3b8d6fc
commit 091070726e
4 changed files with 34 additions and 40 deletions

View File

@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
class CommentEndpoint {
String instanceUrl;
CommentEndpoint(this.instanceUrl);
import 'main.dart';
extension CommentEndpoint on V1 {
/// POST /comment
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-comment
String create({
String createComment({
@required String content,
int parentId,
@required int postId,
@ -18,7 +17,7 @@ class CommentEndpoint {
/// PUT /comment
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-comment
String edit({
String editComment({
@required String content,
@required int editId,
String formId,
@ -30,7 +29,7 @@ class CommentEndpoint {
/// POST /comment/delete
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-comment
/// Only the creator can delete the comment
String delete({
String deleteComment({
@required int editId,
@required bool deleted,
@required String auth,
@ -41,7 +40,7 @@ class CommentEndpoint {
/// POST /comment/remove
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#remove-comment
/// Only a mod or admin can remove the comment
String remove({
String removeComment({
@required int editId,
@required bool removed,
String reason,
@ -52,7 +51,7 @@ class CommentEndpoint {
/// POST /comment/mark_as_read
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-comment-as-read
String markAsRead({
String markCommentAsRead({
@required int editId,
@required bool read,
@required String auth,
@ -62,7 +61,7 @@ class CommentEndpoint {
/// POST /comment/save
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-comment
String save({
String saveComment({
@required int commentId,
@required bool save,
@required String auth,
@ -72,7 +71,7 @@ class CommentEndpoint {
/// POST /comment/like
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-comment-like
String vote({
String createCommentLike({
@required int commentId,
@required int score,
@required String auth,

View File

@ -1,16 +1,13 @@
import 'package:flutter/foundation.dart';
import 'post_endpoint.dart';
import 'user_endpoint.dart';
export 'comment_endpoint.dart';
export 'post_endpoint.dart';
export 'user_endpoint.dart';
class V1 {
String instanceUrl;
UserEndpoint user;
PostEndpoint post;
V1(this.instanceUrl)
: user = UserEndpoint(instanceUrl),
post = PostEndpoint(instanceUrl);
V1(this.instanceUrl);
/// GET /categories
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#list-categories

View File

@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
class PostEndpoint {
String instanceUrl;
PostEndpoint(this.instanceUrl);
import 'main.dart';
extension PostEndpoint on V1 {
/// POST /post
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#post
String create({
String createPost({
@required String name,
String url,
String body,
@ -19,7 +18,7 @@ class PostEndpoint {
/// GET /post
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-post
String get({
String getPost({
@required int id,
String auth,
}) {
@ -27,8 +26,8 @@ class PostEndpoint {
}
/// GET /post/list
///
String getList({
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-posts
String getPosts({
@required String type,
@required String sort,
int page,
@ -40,8 +39,8 @@ class PostEndpoint {
}
/// POST /post/like
///
String vote({
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#create-post-like
String createPostLike({
@required int postId,
@required int score,
@required String auth,
@ -51,7 +50,7 @@ class PostEndpoint {
/// PUT /post
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-post
String update({
String editPost({
@required int editId,
@required String name,
String url,
@ -65,7 +64,7 @@ class PostEndpoint {
/// POST /post/delete
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#delete-post
/// delete a post in a user deleting their own kind of way
String delete({
String deletePost({
@required int editId,
@required bool deleted,
@required String auth,
@ -76,7 +75,7 @@ class PostEndpoint {
/// POST /post/remove
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#remove-post
/// remove post in an admin kind of way
String remove({
String removePost({
@required int editId,
@required bool removed,
String reason,
@ -87,7 +86,7 @@ class PostEndpoint {
/// POST /post/save
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-post
String save({
String savePost({
@required int postId,
@required bool save,
@required String auth,

View File

@ -1,9 +1,8 @@
import 'package:flutter/foundation.dart';
class UserEndpoint {
String instanceUrl;
UserEndpoint(this.instanceUrl);
import 'main.dart';
extension UserEndpoint on V1 {
/// POST /user/login
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#login
String login({
@ -32,7 +31,7 @@ class UserEndpoint {
/// GET /user
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-details
String getDetails({
String getUserDetails({
int userId,
String username,
@required String sort,
@ -47,7 +46,7 @@ class UserEndpoint {
/// PUT /save_user_settings
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#save-user-settings
String updateSettings({
String saveUserSettings({
@required bool showNsfw,
@required String theme,
@required int defaultSortType,
@ -71,7 +70,7 @@ class UserEndpoint {
/// GET /user/mentions
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#get-user-mentions
String getMentions({
String getUserMentions({
String sort,
@required int page,
@required int limit,
@ -83,7 +82,7 @@ class UserEndpoint {
/// POST /user/mention/mark_as_read
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-user-mention-as-read
String markMentionsAsRead({
String markUserMentionAsRead({
@required int userMentionId,
@required bool read,
@required String auth,
@ -114,7 +113,7 @@ class UserEndpoint {
/// PUT /private_message
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#edit-private-message
String updatePrivateMessage({
String editPrivateMessage({
@required int editId,
@required String content,
@required String auth,
@ -144,7 +143,7 @@ class UserEndpoint {
/// POST /user/mark_all_as_read
/// https://dev.lemmy.ml/docs/contributing_websocket_http_api.html#mark-all-as-read
String markAllPrivateMessagesAsRead({
String markAllAsRead({
@required String auth,
}) {
throw UnimplementedError();