diff --git a/cmd/activity/activity.go b/cmd/activity/activity.go index 41e259e..9041b12 100644 --- a/cmd/activity/activity.go +++ b/cmd/activity/activity.go @@ -6,9 +6,15 @@ import ( ) var ( - channelId string - parts []string - output string + channelId string + home string + maxResults int64 + mine string + publishedAfter string + publishedBefore string + regionCode string + parts []string + output string ) var activityCmd = &cobra.Command{ diff --git a/cmd/activity/list.go b/cmd/activity/list.go index ea876e5..85361e0 100644 --- a/cmd/activity/list.go +++ b/cmd/activity/list.go @@ -12,6 +12,12 @@ var listCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { a := yutuber.NewActivity( yutuber.WithActivityChannelId(channelId), + yutuber.WithActivityHome(home), + yutuber.WithActivityMaxResults(maxResults), + yutuber.WithActivityMine(mine), + yutuber.WithActivityPublishedAfter(publishedAfter), + yutuber.WithActivityPublishedBefore(publishedBefore), + yutuber.WithActivityRegionCode(regionCode), ) a.List(parts, output) }, @@ -20,6 +26,21 @@ var listCmd = &cobra.Command{ func init() { activityCmd.AddCommand(listCmd) listCmd.Flags().StringVarP(&channelId, "channelId", "c", "", "ID of the channel") - listCmd.Flags().StringArrayVarP(&parts, "parts", "p", []string{"id", "snippet", "contentDetails"}, "Comma separated parts") + listCmd.Flags().StringVarP(&home, "home", "h", "", "true or false") + listCmd.Flags().Int64VarP( + &maxResults, "maxResults", "x", 5, "Specifies the maximum number of items that should be returned", + ) + listCmd.Flags().StringVarP(&mine, "mine", "m", "", "true or false") + listCmd.Flags().StringVarP( + &publishedAfter, "publishedAfter", "a", "", "Filter on activities published after this date", + ) + listCmd.Flags().StringVarP( + &publishedBefore, "publishedBefore", "b", "", "Filter on activities published before this date", + ) + listCmd.Flags().StringVarP(®ionCode, "regionCode", "r", "", "") + + listCmd.Flags().StringArrayVarP( + &parts, "parts", "p", []string{"id", "snippet", "contentDetails"}, "Comma separated parts", + ) listCmd.Flags().StringVarP(&output, "output", "o", "", "Output format: json or yaml") } diff --git a/pkg/yutuber/activity.go b/pkg/yutuber/activity.go index 02d380f..606390f 100644 --- a/pkg/yutuber/activity.go +++ b/pkg/yutuber/activity.go @@ -15,7 +15,13 @@ var ( ) type activity struct { - channelId string + channelId string + home string + maxResults int64 + mine string + publishedAfter string + publishedBefore string + regionCode string } type Activity interface { @@ -40,8 +46,26 @@ func (a *activity) get(parts []string) []*youtube.Activity { call := service.Activities.List(parts) if a.channelId != "" { call = call.ChannelId(a.channelId) - } else { - call = call.Mine(true) + } + + if a.home == "true" { + call = call.Home(true) + } else if a.home == "false" { + call = call.Home(false) + } + + call.MaxResults(a.maxResults) + + if a.publishedAfter != "" { + call.PublishedAfter(a.publishedAfter) + } + + if a.publishedBefore != "" { + call.PublishedBefore(a.publishedBefore) + } + + if a.regionCode != "" { + call.RegionCode(a.regionCode) } response, err := call.Do() @@ -72,3 +96,39 @@ func WithActivityChannelId(channelId string) ActivityOption { a.channelId = channelId } } + +func WithActivityHome(home string) ActivityOption { + return func(a *activity) { + a.home = home + } +} + +func WithActivityMaxResults(maxResults int64) ActivityOption { + return func(a *activity) { + a.maxResults = maxResults + } +} + +func WithActivityMine(mine string) ActivityOption { + return func(a *activity) { + a.mine = mine + } +} + +func WithActivityPublishedAfter(publishedAfter string) ActivityOption { + return func(a *activity) { + a.publishedAfter = publishedAfter + } +} + +func WithActivityPublishedBefore(publishedBefore string) ActivityOption { + return func(a *activity) { + a.publishedBefore = publishedBefore + } +} + +func WithActivityRegionCode(regionCode string) ActivityOption { + return func(a *activity) { + a.regionCode = regionCode + } +}