Skip to content

Commit

Permalink
add Feed member.
Browse files Browse the repository at this point in the history
new function for locationID search added
  • Loading branch information
ahmdrz committed Sep 12, 2018
1 parent 4eb2917 commit 1ec2c06
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 68 deletions.
5 changes: 4 additions & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
29 changes: 0 additions & 29 deletions examples/search/searchFeedTags.go

This file was deleted.

86 changes: 86 additions & 0 deletions feeds.go
Original file line number Diff line number Diff line change
@@ -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"`
}
3 changes: 3 additions & 0 deletions goinsta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down
38 changes: 0 additions & 38 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package goinsta

import (
"encoding/json"
"fmt"
"strconv"
"time"
)
Expand Down Expand Up @@ -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"`
}

0 comments on commit 1ec2c06

Please sign in to comment.