diff --git a/Readme.md b/Readme.md index 74b4a07..5539794 100644 --- a/Readme.md +++ b/Readme.md @@ -1,7 +1,8 @@ drivel ======== -drivel is a Twitter command line interface for status updates, media upload, your home timeline, your mention timeline and replies. +drivel is a Twitter command line interface for status updates, media upload, +your home timeline, your mention timeline, replies and likes. My personal opinion is that you shouldn't be on Twitter in the first place, but anyway... @@ -33,6 +34,12 @@ To get the last 200 tweets of your mention timeline: drivel mentions ``` +To like a tweet with a specific ID: + +``` +drivel like TWEET_ID +``` + To update your status with optional media upload... diff --git a/drivel.go b/drivel.go index 408d727..708e97d 100644 --- a/drivel.go +++ b/drivel.go @@ -22,6 +22,7 @@ const ( STATUS_ENDPOINT = "https://api.twitter.com/1.1/statuses/update.json" MENTIONS_ENDPOINT = "https://api.twitter.com/1.1/statuses/mentions_timeline.json?tweet_mode=extended&count=200" HOME_ENDPOINT = "https://api.twitter.com/1.1/statuses/home_timeline.json?tweet_mode=extended&count=200" + LIKE_ENDPOINT = "https://api.twitter.com/1.1/favorites/create.json" ) func optLogFatal(decorum string, err error) { @@ -416,12 +417,35 @@ func home(args []string) error { return nil } +func LikeRequest(id string) url.Values { + return map[string][]string{ + "id": {id}, + "tweet_mode": {"extended"}, + } +} + +func like(args []string) error { + log := func(err error) { optLogFatal("like", err) } + if len(args) != 1 { + fmt.Fprintln(os.Stderr, "USAGE: drivel like TWEET_ID") + os.Exit(-1) + } + client := getClient() + body := send(client, LIKE_ENDPOINT, LikeRequest(args[0])) + var tweet Status + err := json.Unmarshal(body, &tweet) + log(err) + fmt.Println("Liked", tweet) + return nil +} + func main() { commands := []goutil.Command{ goutil.NewCommand("status", status, "post a status with message and/or media"), goutil.NewCommand("home", home, "get your home timeline"), goutil.NewCommand("mentions", mentions, "get your mention timeline"), goutil.NewCommand("reply", reply, "reply to a tweet with a specific ID"), + goutil.NewCommand("like", like, "like a tweet with a specific ID"), } err := goutil.Execute(commands) if err != nil {