refactoring: rename 'send' to 'post'

This commit is contained in:
gutmet 2020-10-21 13:42:04 +02:00
parent 58246116b2
commit f4b0627bbc
2 changed files with 12 additions and 12 deletions

View File

@ -49,14 +49,14 @@ func checkUsage(args []string, argcMin int, argcMax int, help string) {
} }
func get(url string) []byte { func get(url string) []byte {
return _send(url, nil, false) return send(url, nil, false)
} }
func send(url string, vals url.Values) []byte { func post(url string, vals url.Values) []byte {
return _send(url, vals, true) return send(url, vals, true)
} }
func _send(url string, vals url.Values, usePost bool) []byte { func send(url string, vals url.Values, usePost bool) []byte {
log := func(err error) { log := func(err error) {
v, _ := json.Marshal(vals) v, _ := json.Marshal(vals)
optLogFatal("get/post "+url+" "+string(v), err) optLogFatal("get/post "+url+" "+string(v), err)
@ -144,7 +144,7 @@ func splitArguments(args []string) data {
func tweet(status string, mediaIDs []ObjectID, previousID ObjectID) Status { func tweet(status string, mediaIDs []ObjectID, previousID ObjectID) Status {
log := func(err error) { optLogFatal("tweet "+status, err) } log := func(err error) { optLogFatal("tweet "+status, err) }
request := UpdateStatusRequest(status, mediaIDs, previousID) request := UpdateStatusRequest(status, mediaIDs, previousID)
body := send(STATUS_ENDPOINT, request) body := post(STATUS_ENDPOINT, request)
var tweet Status var tweet Status
err := json.Unmarshal(body, &tweet) err := json.Unmarshal(body, &tweet)
log(err) log(err)
@ -396,7 +396,7 @@ func retweet(args []string) error {
if len(tweets) != 1 { if len(tweets) != 1 {
log(errors.New("Could not find tweet " + id)) log(errors.New("Could not find tweet " + id))
} }
body := send(RETWEET_ENDPOINT+RetweetParameters(id), nil) body := post(RETWEET_ENDPOINT+RetweetParameters(id), nil)
var retweet Status var retweet Status
err := json.Unmarshal(body, &retweet) err := json.Unmarshal(body, &retweet)
log(err) log(err)
@ -407,7 +407,7 @@ func retweet(args []string) error {
func like(args []string) error { func like(args []string) error {
checkUsage(args, 1, 1, "like TWEET_ID") checkUsage(args, 1, 1, "like TWEET_ID")
log := func(err error) { optLogFatal("like", err) } log := func(err error) { optLogFatal("like", err) }
body := send(LIKE_ENDPOINT, LikeRequest(args[0])) body := post(LIKE_ENDPOINT, LikeRequest(args[0]))
var tweet Status var tweet Status
err := json.Unmarshal(body, &tweet) err := json.Unmarshal(body, &tweet)
log(err) log(err)
@ -417,7 +417,7 @@ func like(args []string) error {
func unlike(id string) { func unlike(id string) {
log := func(err error) { optLogFatal("unlike", err) } log := func(err error) { optLogFatal("unlike", err) }
body := send(DESTROY_LIKE_ENDPOINT, UnlikeRequest(id)) body := post(DESTROY_LIKE_ENDPOINT, UnlikeRequest(id))
var tweet Status var tweet Status
err := json.Unmarshal(body, &tweet) err := json.Unmarshal(body, &tweet)
log(err) log(err)
@ -426,7 +426,7 @@ func unlike(id string) {
func destroyStatus(id string) { func destroyStatus(id string) {
log := func(err error) { optLogFatal("destroy", err) } log := func(err error) { optLogFatal("destroy", err) }
body := send(DESTROY_STATUS_ENDPOINT+DestroyParameters(id), nil) body := post(DESTROY_STATUS_ENDPOINT+DestroyParameters(id), nil)
var tweet Status var tweet Status
err := json.Unmarshal(body, &tweet) err := json.Unmarshal(body, &tweet)
log(err) log(err)

View File

@ -102,7 +102,7 @@ func getMimetype(file string) string {
func initFileUpload(file string, mediaData []byte) ObjectID { func initFileUpload(file string, mediaData []byte) ObjectID {
log := func(err error) { optLogFatal("initFileUpload "+file, err) } log := func(err error) { optLogFatal("initFileUpload "+file, err) }
initRequest := InitRequest(getMimetype(file), len(mediaData)) initRequest := InitRequest(getMimetype(file), len(mediaData))
body := send(UPLOAD_ENDPOINT, initRequest) body := post(UPLOAD_ENDPOINT, initRequest)
var initResponse InitResponse var initResponse InitResponse
err := json.Unmarshal(body, &initResponse) err := json.Unmarshal(body, &initResponse)
log(err) log(err)
@ -130,7 +130,7 @@ func appendFileChunks(file string, media string, mediaId ObjectID) {
var body []byte var body []byte
for try := 0; try < 3 && !appended; try++ { for try := 0; try < 3 && !appended; try++ {
appRequest := AppendRequest(mediaId, media[start:end], i) appRequest := AppendRequest(mediaId, media[start:end], i)
body = send(UPLOAD_ENDPOINT, appRequest) body = post(UPLOAD_ENDPOINT, appRequest)
if string(body) == "" { if string(body) == "" {
appended = true appended = true
} }
@ -143,7 +143,7 @@ func appendFileChunks(file string, media string, mediaId ObjectID) {
func finalizeFileUpload(file string, mediaId ObjectID) int64 { func finalizeFileUpload(file string, mediaId ObjectID) int64 {
log := func(err error) { optLogFatal("finalizeFileUpload", err) } log := func(err error) { optLogFatal("finalizeFileUpload", err) }
body := send(UPLOAD_ENDPOINT, FinalizeRequest(mediaId)) body := post(UPLOAD_ENDPOINT, FinalizeRequest(mediaId))
var finalizeResponse FinalizeResponse var finalizeResponse FinalizeResponse
err := json.Unmarshal(body, &finalizeResponse) err := json.Unmarshal(body, &finalizeResponse)
log(err) log(err)