diff --git a/const.go b/const.go index 30de756c..5dd02ad5 100644 --- a/const.go +++ b/const.go @@ -74,7 +74,10 @@ const ( urlSearchTag = "tags/search/" urlSearchLocation = "location_search/" urlSearchFacebook = "fbsearch/topsearch/" - urlSearchFeedTag = "feed/tag/%s/" + + // feeds + urlFeedLocationID = "feed/location/%d/" + urlFeedTag = "feed/tag/%s/" // media urlMediaInfo = "media/%s/info/" diff --git a/examples/search/searchFeedTags.go b/examples/search/searchFeedTags.go deleted file mode 100644 index 836ddbe7..00000000 --- a/examples/search/searchFeedTags.go +++ /dev/null @@ -1,29 +0,0 @@ -// +build ignore - -package main - -import ( - "fmt" - "os" - - e "github.com/ahmdrz/goinsta/examples" -) - -func main() { - inst, err := e.InitGoinsta("") - e.CheckErr(err) - - fmt.Printf("Hello %s!\n", inst.Account.Username) - - tags, err := inst.Search.FeedTags(os.Args[0]) - e.CheckErr(err) - - for _, item := range tags.Images { - fmt.Printf(" Media found with ID: %s from User %s\n", item.ID, item.User.Username) - } - - if !e.UsingSession { - err = inst.Logout() - e.CheckErr(err) - } -} diff --git a/feeds.go b/feeds.go new file mode 100644 index 00000000..371afaad --- /dev/null +++ b/feeds.go @@ -0,0 +1,86 @@ +package goinsta + +import ( + "encoding/json" + "fmt" +) + +// Feed is the object for all feed endpoints. +type Feed struct { + inst *Instagram +} + +// newFeed creates new Feed structure +func newFeed(inst *Instagram) *Feed { + return &Feed{ + inst: inst, + } +} + +// Feed search by locationID +func (feed *Feed) LocationID(locationID int64) (*FeedLocation, error) { + insta := feed.inst + body, err := insta.sendRequest( + &reqOptions{ + Endpoint: fmt.Sprintf(urlFeedLocationID, locationID), + Query: map[string]string{ + "rank_token": insta.rankToken, + "ranked_content": "true", + }, + }, + ) + if err != nil { + return nil, err + } + + res := &FeedLocation{} + err = json.Unmarshal(body, res) + return res, err +} + +// FeedLocation is the struct that fits the structure returned by instagram on LocationID search. +type FeedLocation struct { + RankedItems []Item `json:"ranked_items"` + Items []Item `json:"items"` + NumResults int `json:"num_results"` + NextID string `json:"next_max_id"` + MoreAvailable bool `json:"more_available"` + AutoLoadMoreEnabled bool `json:"auto_load_more_enabled"` + MediaCount int `json:"media_count"` + Location Location `json:"location"` + Status string `json:"status"` +} + +// Tags search by Tag in user Feed +// +// (sorry for returning FeedTag. See #FeedTag) +func (feed *Feed) Tags(tag string) (*FeedTag, error) { + insta := feed.inst + body, err := insta.sendRequest( + &reqOptions{ + Endpoint: fmt.Sprintf(urlFeedTag, tag), + Query: map[string]string{ + "rank_token": insta.rankToken, + "ranked_content": "true", + }, + }, + ) + if err != nil { + return nil, err + } + res := &FeedTag{} + err = json.Unmarshal(body, res) + return res, err +} + +// FeedTag is the struct that fits the structure returned by instagram on TagSearch. +type FeedTag struct { + RankedItems []Item `json:"ranked_items"` + Images []Item `json:"items"` + NumResults int `json:"num_results"` + NextID string `json:"next_max_id"` + MoreAvailable bool `json:"more_available"` + AutoLoadMoreEnabled bool `json:"auto_load_more_enabled"` + Story StoryMedia `json:"story"` + Status string `json:"status"` +} diff --git a/goinsta.go b/goinsta.go index 8acdc4e5..a146aafa 100644 --- a/goinsta.go +++ b/goinsta.go @@ -59,6 +59,8 @@ type Instagram struct { Activity *Activity // Inbox are instagram message/chat system. Inbox *Inbox + // Feed for search over feeds + Feed *Feed c *http.Client } @@ -108,6 +110,7 @@ func (inst *Instagram) init() { inst.Timeline = newTimeline(inst) inst.Search = newSearch(inst) inst.Inbox = newInbox(inst) + inst.Feed = newFeed(inst) } // SetProxy sets proxy for connection. diff --git a/search.go b/search.go index 27faf12a..abef4c7d 100644 --- a/search.go +++ b/search.go @@ -2,7 +2,6 @@ package goinsta import ( "encoding/json" - "fmt" "strconv" "time" ) @@ -167,40 +166,3 @@ func (search *Search) Facebook(user string) (*SearchResult, error) { err = json.Unmarshal(body, res) return res, err } - -// FeedTags search by Tag in user Feed -// -// (sorry for returning FeedTag. See #FeedTag) -func (search *Search) FeedTags(tag string) (*FeedTag, error) { - insta := search.inst - body, err := insta.sendRequest( - &reqOptions{ - Endpoint: fmt.Sprintf(urlSearchFeedTag, tag), - Query: map[string]string{ - "rank_token": insta.rankToken, - "ranked_content": "true", - }, - }, - ) - if err != nil { - return nil, err - } - res := &FeedTag{} - err = json.Unmarshal(body, res) - return res, err -} - -// FeedTag is the struct that fits the structure returned by instagram on TagSearch. -// Instagram's database is f*cking shit. -// We all hate nodejs (seems that they use nodejs and mongoldb) -// I don't know why FeedTags returns this aberration structure. -type FeedTag struct { - RankedItems []Item `json:"ranked_items"` - Images []Item `json:"items"` - NumResults int `json:"num_results"` - NextID string `json:"next_max_id"` - MoreAvailable bool `json:"more_available"` - AutoLoadMoreEnabled bool `json:"auto_load_more_enabled"` - Story StoryMedia `json:"story"` - Status string `json:"status"` -}