From 9d285d43bdcd46c0f9f9926cbaf8f28e38fc8e96 Mon Sep 17 00:00:00 2001 From: Ahmadreza Zibaei Date: Tue, 26 Mar 2019 11:06:40 +0430 Subject: [PATCH] added GetPendingFollowRequests --- const.go | 27 ++++++++++++++------------- goinsta.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/const.go b/const.go index 188e123b..ce46d629 100644 --- a/const.go +++ b/const.go @@ -51,19 +51,20 @@ const ( urlFollowing = "friendships/%d/following/" // users - urlUserByName = "users/%s/usernameinfo/" - urlUserByID = "users/%d/info/" - urlUserBlock = "friendships/block/%d/" - urlUserUnblock = "friendships/unblock/%d/" - urlUserFollow = "friendships/create/%d/" - urlUserUnfollow = "friendships/destroy/%d/" - urlUserFeed = "feed/user/%d/" - urlFriendship = "friendships/show/%d/" - urlUserStories = "feed/user/%d/reel_media/" - urlUserTags = "usertags/%d/feed/" - urlBlockedList = "users/blocked_list/" - urlUserInfo = "users/%d/info/" - urlUserHighlights = "highlights/%d/highlights_tray/" + urlUserByName = "users/%s/usernameinfo/" + urlUserByID = "users/%d/info/" + urlUserBlock = "friendships/block/%d/" + urlUserUnblock = "friendships/unblock/%d/" + urlUserFollow = "friendships/create/%d/" + urlUserUnfollow = "friendships/destroy/%d/" + urlUserFeed = "feed/user/%d/" + urlFriendship = "friendships/show/%d/" + urlFriendshipPending = "friendships/pending/" + urlUserStories = "feed/user/%d/reel_media/" + urlUserTags = "usertags/%d/feed/" + urlBlockedList = "users/blocked_list/" + urlUserInfo = "users/%d/info/" + urlUserHighlights = "highlights/%d/highlights_tray/" // timeline urlTimeline = "feed/timeline/" diff --git a/goinsta.go b/goinsta.go index d4e89a5a..3064a199 100644 --- a/goinsta.go +++ b/goinsta.go @@ -3,6 +3,7 @@ package goinsta import ( "crypto/tls" "encoding/json" + "fmt" "io" "io/ioutil" "net/http" @@ -492,3 +493,31 @@ func (inst *Instagram) GetMedia(o interface{}) (*FeedMedia, error) { } return media, media.Sync() } + +// GetPendingFollowRequests returns pending follow requests. +func (inst *Instagram) GetPendingFollowRequests() ([]User, error) { + resp, err := inst.sendRequest( + &reqOptions{ + Endpoint: urlFriendshipPending, + }, + ) + if err != nil { + return nil, err + } + + var result struct { + Users []User `json:"users"` + // TODO: pagination + // TODO: SuggestedUsers + Status string `json:"status"` + } + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + if result.Status != "ok" { + return nil, fmt.Errorf("bad status: %s", result.Status) + } + + return result.Users, nil +}