Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The design of Common API #3

Open
acid-chicken opened this issue Jun 21, 2018 · 19 comments
Open

The design of Common API #3

acid-chicken opened this issue Jun 21, 2018 · 19 comments
Labels
discussion Talking about this
Projects

Comments

@acid-chicken
Copy link
Owner

Overview

From #2.
In this issue, we have a discussion about designing Information.NET.Common.

@acid-chicken acid-chicken added the discussion Talking about this label Jun 21, 2018
@acid-chicken acid-chicken added this to To do in Tasks via automation Jun 21, 2018
@marihachi
Copy link
Collaborator

First of all, common point is posting messages.

@acid-chicken
Copy link
Owner Author

Yeah, and in general, these are listed on timelines.

@marihachi
Copy link
Collaborator

Also, It's necessary to decide the object-name of posted text message. (e.g. Status, Message, or Text etc.)

@acid-chicken
Copy link
Owner Author

I think "Message" sounds good! How do you like to call it? @mak0tia @siketyan

@marihachi
Copy link
Collaborator

marihachi commented Jun 23, 2018

But, when we want to define other messages, it will be probably a not good decision 🤔
If we doesn't call other objects "Message", it is ok.

@marihachi
Copy link
Collaborator

Or, How about "TextMessage"?

@acid-chicken
Copy link
Owner Author

The message contains text is not necessarily so. How about inheritance?

  • IMessage
    • ITextMessage

@marihachi
Copy link
Collaborator

sounds good!

@acid-chicken

This comment has been minimized.

@marihachi

This comment has been minimized.

@acid-chicken

This comment has been minimized.

@marihachi
Copy link
Collaborator

marihachi commented Jun 30, 2018

とりあえず、現状の構想でcommonプロジェクトを作成してみた
#5

I created a common project as based on the current idea at #5 for now.
— Translation added by @acid-chicken

@marihachi
Copy link
Collaborator

marihachi commented Jul 5, 2018

構想

using System.Threading.Tasks;

namespace Information
{
    public interface IService { }
    public interface IMessage { }
    public interface IMessagePostable<T> where T : IMessage
    {
        Task<T> PostMessageAsync(T message);
    }
}

namespace Information.Services
{
    public class Twitter :
        IService,
        IMessagePostable<Twitter.TextMessage>,
        IMessagePostable<Twitter.ReactionMessage>
    {
        public Task<TextMessage> PostMessageAsync(TextMessage message) => null;

        public Task<ReactionMessage> PostMessageAsync(ReactionMessage message) => null;

        public class TextMessage : IMessage
        {
            public string Content { get; set; }
        }

        public class ReactionMessage : IMessage
        {
            public ReactionType Type { get; set; }
        }

        public enum ReactionType { Like }
    }
}

public class Program
{
    public async void Main()
    {
        var tw = new Information.Services.Twitter();

        var text = new Information.Services.Twitter.TextMessage();
        text.Content = "hoge";
        await tw.PostMessageAsync(text);

        var reaction = new Information.Services.Twitter.ReactionMessage();
        reaction.Type = Information.Services.Twitter.ReactionType.Like;
        await tw.PostMessageAsync(reaction);
    }
}

どうだろう..

Conception:
some codes
Would you like this...?
— Translation added by @acid-chicken

@qpwakaba
Copy link
Collaborator

qpwakaba commented Jul 5, 2018

ReactionMessage のリアクション対象の指定ってどこでやる感じです?

Where do you want to let's specify the target for the reaction of ReactionMessage?
— Translation added by @acid-chicken

@acid-chicken
Copy link
Owner Author

var text = new Information.Services.Twitter.TextMessage();
text.Content = "hoge";
await tw.PostMessageAsync(text);

It looks a little bit complex.

@marihachi
Copy link
Collaborator

marihachi commented Jul 6, 2018

@acid-chicken

It looks a little bit complex.

それはそう。どのようにすれば最適だろう?

@qpwakaba

ReactionMessage のリアクション対象の指定ってどこでやる感じです?

ReactionMessageのコンストラクタもしくはプロパティから設定することになりそう

@marihachi
Copy link
Collaborator

リアクションをメッセージとして扱うのは抽象化し過ぎかなあ

@marihachi
Copy link
Collaborator

marihachi commented Jul 6, 2018

案2

  • パラメータとレスポンスを別の型で設定可能に
  • リアクションをメッセージとしてではなく、リアクションとして定義可能に

メソッド名がすべてのサービスで共通になるというメリットがあるが、結局パラメータとして与えるTextMessageやReactionのような「モデル」は全てのサービスで定義して使い分けないといけない。

using System.Threading.Tasks;
using static Information.Services.Twitter;

namespace Information
{
    public interface IService { }

    public interface IMessagePostable<T> { Task PostMessageAsync(T message); }
    public interface IMessagePostable<T, TRes> { Task<TRes> PostMessageAsync(T message); }

    public interface IReactionPostable<T> { Task PostReactionAsync(T reaction); }
    public interface IReactionPostable<T, TRes> { Task<TRes> PostReactionAsync(T reaction); }
}

namespace Information.Services
{
    public class Twitter :
        IService,
        IMessagePostable<TextMessage>,
        IReactionPostable<Reaction>
    {
        public Task PostMessageAsync(TextMessage message) => null;
        public Task PostReactionAsync(Reaction reaction) => null;

        public class TextMessage
        {
            public TextMessage(string text, string inReplyToStatusId = null)
            {
                Text = text;
                InReplyToStatusId = inReplyToStatusId;
            }

            public string Text { get; set; }
            public string InReplyToStatusId { get; set; }
        }

        public class Reaction
        {
            public Reaction(ReactionType type, string targetMessageId)
            {
                Type = type;
                TargetMessageId = targetMessageId;
            }

            public ReactionType Type { get; set; }
            public string TargetMessageId { get; set; }
        }

        public enum ReactionType { Like }
    }
}

public class Program
{
    public async void Main()
    {
        var tw = new Information.Services.Twitter();

        await tw.PostMessageAsync(new TextMessage("hoge"));
        await tw.PostReactionAsync(new Reaction(ReactionType.Like, "abc"));
    }
}

@acid-chicken acid-chicken moved this from To do to In progress in Tasks Jul 8, 2018
@acid-chicken

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Talking about this
Projects
Tasks
  
In progress
Development

No branches or pull requests

7 participants