diff --git a/twitter/handler/twitter.go b/twitter/handler/twitter.go index 9d798e0..2459fa5 100644 --- a/twitter/handler/twitter.go +++ b/twitter/handler/twitter.go @@ -114,3 +114,40 @@ func (t *Twitter) Search(ctx context.Context, req *pb.SearchRequest, rsp *pb.Sea return nil } + +func (t *Twitter) User(ctx context.Context, req *pb.UserRequest, rsp *pb.UserResponse) error { + if len(req.Username) == 0 { + return errors.BadRequest("twitter.user", "missing username") + } + + user, _, err := t.Client.Users.Show(&twitter.UserShowParams{ + ScreenName: req.Username, + }) + if err != nil { + logger.Errorf("Failed to retrieve user profile for %v: %v", req.Username, err) + return errors.InternalServerError("twitter.user", "Failed to retrieve user profile for %v: %v", req.Username, err) + } + + rsp.Status = &pb.Tweet{ + Id: user.Status.ID, + Text: user.Status.Text, + CreatedAt: user.Status.CreatedAt, + FavouritedCount: int64(user.Status.FavoriteCount), + RetweetedCount: int64(user.Status.RetweetCount), + Username: req.Username, + } + + rsp.Profile = &pb.Profile{ + Id: user.ID, + Name: user.Name, + Username: user.ScreenName, + CreatedAt: user.CreatedAt, + Description: user.Description, + Followers: int64(user.FollowersCount), + Private: user.Protected, + Verified: user.Verified, + ImageUrl: user.ProfileImageURL, + } + + return nil +} diff --git a/twitter/proto/twitter.pb.go b/twitter/proto/twitter.pb.go index 3b2265b..03b7e51 100644 --- a/twitter/proto/twitter.pb.go +++ b/twitter/proto/twitter.pb.go @@ -113,6 +113,135 @@ func (x *Tweet) GetFavouritedCount() int64 { return 0 } +type Profile struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the user id + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + // display name of the user + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + // the username + Username string `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"` + // the user description + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` + // the account creation date + CreatedAt string `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` + // the user's location + Location string `protobuf:"bytes,6,opt,name=location,proto3" json:"location,omitempty"` + // the follower count + Followers int64 `protobuf:"varint,7,opt,name=followers,proto3" json:"followers,omitempty"` + // if the account is private + Private bool `protobuf:"varint,8,opt,name=private,proto3" json:"private,omitempty"` + // if the account is verified + Verified bool `protobuf:"varint,9,opt,name=verified,proto3" json:"verified,omitempty"` + // The user's profile picture + ImageUrl string `protobuf:"bytes,10,opt,name=image_url,json=imageUrl,proto3" json:"image_url,omitempty"` +} + +func (x *Profile) Reset() { + *x = Profile{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_twitter_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Profile) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Profile) ProtoMessage() {} + +func (x *Profile) ProtoReflect() protoreflect.Message { + mi := &file_proto_twitter_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Profile.ProtoReflect.Descriptor instead. +func (*Profile) Descriptor() ([]byte, []int) { + return file_proto_twitter_proto_rawDescGZIP(), []int{1} +} + +func (x *Profile) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *Profile) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Profile) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *Profile) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Profile) GetCreatedAt() string { + if x != nil { + return x.CreatedAt + } + return "" +} + +func (x *Profile) GetLocation() string { + if x != nil { + return x.Location + } + return "" +} + +func (x *Profile) GetFollowers() int64 { + if x != nil { + return x.Followers + } + return 0 +} + +func (x *Profile) GetPrivate() bool { + if x != nil { + return x.Private + } + return false +} + +func (x *Profile) GetVerified() bool { + if x != nil { + return x.Verified + } + return false +} + +func (x *Profile) GetImageUrl() string { + if x != nil { + return x.ImageUrl + } + return "" +} + // Get the timeline for a given user type TimelineRequest struct { state protoimpl.MessageState @@ -128,7 +257,7 @@ type TimelineRequest struct { func (x *TimelineRequest) Reset() { *x = TimelineRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_twitter_proto_msgTypes[1] + mi := &file_proto_twitter_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -141,7 +270,7 @@ func (x *TimelineRequest) String() string { func (*TimelineRequest) ProtoMessage() {} func (x *TimelineRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_twitter_proto_msgTypes[1] + mi := &file_proto_twitter_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -154,7 +283,7 @@ func (x *TimelineRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use TimelineRequest.ProtoReflect.Descriptor instead. func (*TimelineRequest) Descriptor() ([]byte, []int) { - return file_proto_twitter_proto_rawDescGZIP(), []int{1} + return file_proto_twitter_proto_rawDescGZIP(), []int{2} } func (x *TimelineRequest) GetUsername() string { @@ -183,7 +312,7 @@ type TimelineResponse struct { func (x *TimelineResponse) Reset() { *x = TimelineResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_twitter_proto_msgTypes[2] + mi := &file_proto_twitter_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -196,7 +325,7 @@ func (x *TimelineResponse) String() string { func (*TimelineResponse) ProtoMessage() {} func (x *TimelineResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_twitter_proto_msgTypes[2] + mi := &file_proto_twitter_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -209,7 +338,7 @@ func (x *TimelineResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use TimelineResponse.ProtoReflect.Descriptor instead. func (*TimelineResponse) Descriptor() ([]byte, []int) { - return file_proto_twitter_proto_rawDescGZIP(), []int{2} + return file_proto_twitter_proto_rawDescGZIP(), []int{3} } func (x *TimelineResponse) GetTweets() []*Tweet { @@ -234,7 +363,7 @@ type SearchRequest struct { func (x *SearchRequest) Reset() { *x = SearchRequest{} if protoimpl.UnsafeEnabled { - mi := &file_proto_twitter_proto_msgTypes[3] + mi := &file_proto_twitter_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -247,7 +376,7 @@ func (x *SearchRequest) String() string { func (*SearchRequest) ProtoMessage() {} func (x *SearchRequest) ProtoReflect() protoreflect.Message { - mi := &file_proto_twitter_proto_msgTypes[3] + mi := &file_proto_twitter_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -260,7 +389,7 @@ func (x *SearchRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SearchRequest.ProtoReflect.Descriptor instead. func (*SearchRequest) Descriptor() ([]byte, []int) { - return file_proto_twitter_proto_rawDescGZIP(), []int{3} + return file_proto_twitter_proto_rawDescGZIP(), []int{4} } func (x *SearchRequest) GetQuery() string { @@ -289,7 +418,7 @@ type SearchResponse struct { func (x *SearchResponse) Reset() { *x = SearchResponse{} if protoimpl.UnsafeEnabled { - mi := &file_proto_twitter_proto_msgTypes[4] + mi := &file_proto_twitter_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -302,7 +431,7 @@ func (x *SearchResponse) String() string { func (*SearchResponse) ProtoMessage() {} func (x *SearchResponse) ProtoReflect() protoreflect.Message { - mi := &file_proto_twitter_proto_msgTypes[4] + mi := &file_proto_twitter_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -315,7 +444,7 @@ func (x *SearchResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SearchResponse.ProtoReflect.Descriptor instead. func (*SearchResponse) Descriptor() ([]byte, []int) { - return file_proto_twitter_proto_rawDescGZIP(), []int{4} + return file_proto_twitter_proto_rawDescGZIP(), []int{5} } func (x *SearchResponse) GetTweets() []*Tweet { @@ -325,6 +454,112 @@ func (x *SearchResponse) GetTweets() []*Tweet { return nil } +// Get a user's twitter profile +type UserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the username to lookup + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` +} + +func (x *UserRequest) Reset() { + *x = UserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_twitter_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserRequest) ProtoMessage() {} + +func (x *UserRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_twitter_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserRequest.ProtoReflect.Descriptor instead. +func (*UserRequest) Descriptor() ([]byte, []int) { + return file_proto_twitter_proto_rawDescGZIP(), []int{6} +} + +func (x *UserRequest) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +type UserResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // the current user status + Status *Tweet `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` + // The requested user profile + Profile *Profile `protobuf:"bytes,2,opt,name=profile,proto3" json:"profile,omitempty"` +} + +func (x *UserResponse) Reset() { + *x = UserResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_twitter_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UserResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UserResponse) ProtoMessage() {} + +func (x *UserResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_twitter_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UserResponse.ProtoReflect.Descriptor instead. +func (*UserResponse) Descriptor() ([]byte, []int) { + return file_proto_twitter_proto_rawDescGZIP(), []int{7} +} + +func (x *UserResponse) GetStatus() *Tweet { + if x != nil { + return x.Status + } + return nil +} + +func (x *UserResponse) GetProfile() *Profile { + if x != nil { + return x.Profile + } + return nil +} + var File_proto_twitter_proto protoreflect.FileDescriptor var file_proto_twitter_proto_rawDesc = []byte{ @@ -341,31 +576,61 @@ var file_proto_twitter_proto_rawDesc = []byte{ 0x52, 0x0e, 0x72, 0x65, 0x74, 0x77, 0x65, 0x65, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x76, 0x6f, 0x75, 0x72, 0x69, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x66, 0x61, 0x76, 0x6f, - 0x75, 0x72, 0x69, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x43, 0x0a, 0x0f, 0x54, - 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, - 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, - 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, - 0x22, 0x3a, 0x0a, 0x10, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x18, 0x01, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, - 0x77, 0x65, 0x65, 0x74, 0x52, 0x06, 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x22, 0x3b, 0x0a, 0x0d, - 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, - 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, - 0x65, 0x72, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x38, 0x0a, 0x0e, 0x53, 0x65, 0x61, - 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x74, - 0x77, 0x65, 0x65, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x77, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, 0x77, 0x65, 0x65, 0x74, 0x52, 0x06, 0x74, 0x77, 0x65, - 0x65, 0x74, 0x73, 0x32, 0x89, 0x01, 0x0a, 0x07, 0x54, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x12, - 0x41, 0x0a, 0x08, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x2e, 0x74, 0x77, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, - 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x06, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x12, 0x16, 0x2e, 0x74, - 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x53, - 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x75, 0x72, 0x69, 0x74, 0x65, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x97, 0x02, 0x0a, 0x07, + 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x75, + 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, + 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, + 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x72, + 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x66, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x65, + 0x72, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, + 0x76, 0x65, 0x72, 0x69, 0x66, 0x69, 0x65, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6d, 0x61, 0x67, + 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x6d, 0x61, + 0x67, 0x65, 0x55, 0x72, 0x6c, 0x22, 0x43, 0x0a, 0x0f, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x22, 0x3a, 0x0a, 0x10, 0x54, 0x69, + 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, + 0x0a, 0x06, 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, + 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, 0x77, 0x65, 0x65, 0x74, 0x52, 0x06, + 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x22, 0x3b, 0x0a, 0x0d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x71, 0x75, 0x65, 0x72, 0x79, 0x12, 0x14, 0x0a, + 0x05, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6c, 0x69, + 0x6d, 0x69, 0x74, 0x22, 0x38, 0x0a, 0x0e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, + 0x54, 0x77, 0x65, 0x65, 0x74, 0x52, 0x06, 0x74, 0x77, 0x65, 0x65, 0x74, 0x73, 0x22, 0x29, 0x0a, + 0x0b, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, + 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x62, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x26, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, + 0x65, 0x72, 0x2e, 0x54, 0x77, 0x65, 0x65, 0x74, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x2a, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x10, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x50, 0x72, 0x6f, 0x66, + 0x69, 0x6c, 0x65, 0x52, 0x07, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x32, 0xc0, 0x01, 0x0a, + 0x07, 0x54, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x12, 0x41, 0x0a, 0x08, 0x54, 0x69, 0x6d, 0x65, + 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x18, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, + 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, + 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x06, 0x53, + 0x65, 0x61, 0x72, 0x63, 0x68, 0x12, 0x16, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, + 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, + 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, + 0x12, 0x14, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, + 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x74, 0x77, 0x69, 0x74, 0x74, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } @@ -382,26 +647,33 @@ func file_proto_twitter_proto_rawDescGZIP() []byte { return file_proto_twitter_proto_rawDescData } -var file_proto_twitter_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_proto_twitter_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_proto_twitter_proto_goTypes = []interface{}{ (*Tweet)(nil), // 0: twitter.Tweet - (*TimelineRequest)(nil), // 1: twitter.TimelineRequest - (*TimelineResponse)(nil), // 2: twitter.TimelineResponse - (*SearchRequest)(nil), // 3: twitter.SearchRequest - (*SearchResponse)(nil), // 4: twitter.SearchResponse + (*Profile)(nil), // 1: twitter.Profile + (*TimelineRequest)(nil), // 2: twitter.TimelineRequest + (*TimelineResponse)(nil), // 3: twitter.TimelineResponse + (*SearchRequest)(nil), // 4: twitter.SearchRequest + (*SearchResponse)(nil), // 5: twitter.SearchResponse + (*UserRequest)(nil), // 6: twitter.UserRequest + (*UserResponse)(nil), // 7: twitter.UserResponse } var file_proto_twitter_proto_depIdxs = []int32{ 0, // 0: twitter.TimelineResponse.tweets:type_name -> twitter.Tweet 0, // 1: twitter.SearchResponse.tweets:type_name -> twitter.Tweet - 1, // 2: twitter.Twitter.Timeline:input_type -> twitter.TimelineRequest - 3, // 3: twitter.Twitter.Search:input_type -> twitter.SearchRequest - 2, // 4: twitter.Twitter.Timeline:output_type -> twitter.TimelineResponse - 4, // 5: twitter.Twitter.Search:output_type -> twitter.SearchResponse - 4, // [4:6] is the sub-list for method output_type - 2, // [2:4] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 0, // 2: twitter.UserResponse.status:type_name -> twitter.Tweet + 1, // 3: twitter.UserResponse.profile:type_name -> twitter.Profile + 2, // 4: twitter.Twitter.Timeline:input_type -> twitter.TimelineRequest + 4, // 5: twitter.Twitter.Search:input_type -> twitter.SearchRequest + 6, // 6: twitter.Twitter.User:input_type -> twitter.UserRequest + 3, // 7: twitter.Twitter.Timeline:output_type -> twitter.TimelineResponse + 5, // 8: twitter.Twitter.Search:output_type -> twitter.SearchResponse + 7, // 9: twitter.Twitter.User:output_type -> twitter.UserResponse + 7, // [7:10] is the sub-list for method output_type + 4, // [4:7] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_proto_twitter_proto_init() } @@ -423,7 +695,7 @@ func file_proto_twitter_proto_init() { } } file_proto_twitter_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TimelineRequest); i { + switch v := v.(*Profile); i { case 0: return &v.state case 1: @@ -435,7 +707,7 @@ func file_proto_twitter_proto_init() { } } file_proto_twitter_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*TimelineResponse); i { + switch v := v.(*TimelineRequest); i { case 0: return &v.state case 1: @@ -447,7 +719,7 @@ func file_proto_twitter_proto_init() { } } file_proto_twitter_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SearchRequest); i { + switch v := v.(*TimelineResponse); i { case 0: return &v.state case 1: @@ -459,6 +731,18 @@ func file_proto_twitter_proto_init() { } } file_proto_twitter_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SearchRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_twitter_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SearchResponse); i { case 0: return &v.state @@ -470,6 +754,30 @@ func file_proto_twitter_proto_init() { return nil } } + file_proto_twitter_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_twitter_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -477,7 +785,7 @@ func file_proto_twitter_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_proto_twitter_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/twitter/proto/twitter.pb.micro.go b/twitter/proto/twitter.pb.micro.go index 2d9f7d9..202f64f 100644 --- a/twitter/proto/twitter.pb.micro.go +++ b/twitter/proto/twitter.pb.micro.go @@ -44,6 +44,7 @@ func NewTwitterEndpoints() []*api.Endpoint { type TwitterService interface { Timeline(ctx context.Context, in *TimelineRequest, opts ...client.CallOption) (*TimelineResponse, error) Search(ctx context.Context, in *SearchRequest, opts ...client.CallOption) (*SearchResponse, error) + User(ctx context.Context, in *UserRequest, opts ...client.CallOption) (*UserResponse, error) } type twitterService struct { @@ -78,17 +79,29 @@ func (c *twitterService) Search(ctx context.Context, in *SearchRequest, opts ... return out, nil } +func (c *twitterService) User(ctx context.Context, in *UserRequest, opts ...client.CallOption) (*UserResponse, error) { + req := c.c.NewRequest(c.name, "Twitter.User", in) + out := new(UserResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Twitter service type TwitterHandler interface { Timeline(context.Context, *TimelineRequest, *TimelineResponse) error Search(context.Context, *SearchRequest, *SearchResponse) error + User(context.Context, *UserRequest, *UserResponse) error } func RegisterTwitterHandler(s server.Server, hdlr TwitterHandler, opts ...server.HandlerOption) error { type twitter interface { Timeline(ctx context.Context, in *TimelineRequest, out *TimelineResponse) error Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error + User(ctx context.Context, in *UserRequest, out *UserResponse) error } type Twitter struct { twitter @@ -108,3 +121,7 @@ func (h *twitterHandler) Timeline(ctx context.Context, in *TimelineRequest, out func (h *twitterHandler) Search(ctx context.Context, in *SearchRequest, out *SearchResponse) error { return h.TwitterHandler.Search(ctx, in, out) } + +func (h *twitterHandler) User(ctx context.Context, in *UserRequest, out *UserResponse) error { + return h.TwitterHandler.User(ctx, in, out) +} diff --git a/twitter/proto/twitter.proto b/twitter/proto/twitter.proto index 29c7b4b..07a1f44 100644 --- a/twitter/proto/twitter.proto +++ b/twitter/proto/twitter.proto @@ -7,6 +7,7 @@ option go_package = "./proto;twitter"; service Twitter { rpc Timeline(TimelineRequest) returns (TimelineResponse) {} rpc Search(SearchRequest) returns (SearchResponse) {} + rpc User(UserRequest) returns (UserResponse) {} } message Tweet { @@ -24,6 +25,29 @@ message Tweet { int64 favourited_count = 8; } +message Profile { + // the user id + int64 id = 1; + // display name of the user + string name = 2; + // the username + string username = 3; + // the user description + string description = 4; + // the account creation date + string created_at = 5; + // the user's location + string location = 6; + // the follower count + int64 followers = 7; + // if the account is private + bool private = 8; + // if the account is verified + bool verified = 9; + // The user's profile picture + string image_url = 10; +} + // Get the timeline for a given user message TimelineRequest { // the username to request the timeline for @@ -49,3 +73,16 @@ message SearchResponse { // the related tweets for the search repeated Tweet tweets = 2; } + +// Get a user's twitter profile +message UserRequest { + // the username to lookup + string username = 1; +} + +message UserResponse { + // the current user status + Tweet status = 1; + // The requested user profile + Profile profile = 2; +}