diff --git a/collection.go b/collection.go new file mode 100644 index 0000000..d82e2f5 --- /dev/null +++ b/collection.go @@ -0,0 +1,82 @@ +package anaconda + +type Collection struct { + Name string + UserId string `json:"user_id"` + CollectionUrl string `json:"collection_url"` + Description string + Url string + Visibility string + TimelineOrder string `json:"timeline_order"` + CollectionType string `json:"collection_type"` +} + +type CollectionListResult struct { + Objects struct { + Users map[string]User + Timelines map[string]Collection + } + Response struct { + Results []struct { + TimelineId string `json:"timeline_id"` + } + Cursors struct { + NextCursor string `json:"next_cursor"` + } + } +} + +// GET collections/show +// Also used by POST collections/create +// Also used by POST collections/update +type CollectionShowResult struct { + Objects struct { + Users map[string]User + Timelines map[string]Collection + } + Response struct { + TimelineId string `json:"timeline_id"` + } +} + +type CollectionEntriesResult struct { + Objects struct { + Timelines map[string]Collection + } + Tweets []Tweet + Response struct { + Position struct { + MaxPosition string `json:"max_position"` + MinPosition string `json:"min_position"` + WasTruncated bool `json:"was_truncated"` + } + Timeline []struct { + FeatureContext string `json:"feature_context"` + Tweet struct { + Id string + SortIndex string `json:"sort_index"` + } + } + TimelineId string `json:"timeline_id"` + } +} + +type CollectionDestroyResult struct { + Destroyed bool +} + +// POST collections/entries/add +// Also used by POST collections/entries/remove +// Also used by POST collections/entries/move +type CollectionEntryAddResult struct { + Objects struct{} + Response struct { + Errors []struct { + Change struct { + Op string + TweetId string `json:"tweet_id"` + } + Reason string + } + } +} diff --git a/collections.go b/collections.go new file mode 100644 index 0000000..47df6a9 --- /dev/null +++ b/collections.go @@ -0,0 +1,90 @@ +package anaconda + +import ( + "fmt" + "net/url" +) + +func (a TwitterApi) GetCollectionListByUserId(userId int64, v url.Values) (result CollectionListResult, err error) { + v = cleanValues(v) + v.Set("user_id", fmt.Sprintf("%d", userId)) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/list.json", v, &result, _GET, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) GetCollectionListByScreenName(screenName string, v url.Values) (result CollectionListResult, err error) { + v = cleanValues(v) + v.Set("screen_name", screenName) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/list.json", v, &result, _GET, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) GetCollectionShow(id string, v url.Values) (result CollectionShowResult, err error) { + v = cleanValues(v) + v.Set("id", id) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/show.json", v, &result, _GET, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) GetCollectionEntries(id string, v url.Values) (result CollectionEntriesResult, err error) { + v = cleanValues(v) + v.Set("id", id) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/entries.json", v, &result, _GET, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) CreateCollection(name string, v url.Values) (result CollectionShowResult, err error) { + v = cleanValues(v) + v.Set("name", name) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/create.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) UpdateCollection(id string, v url.Values) (result CollectionShowResult, err error) { + v = cleanValues(v) + v.Set("id", id) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/update.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) DestroyCollection(id string, v url.Values) (result CollectionDestroyResult, err error) { + v = cleanValues(v) + v.Set("id", id) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/destroy.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) AddEntryToCollection(id string, tweetId int64, v url.Values) (result CollectionEntryAddResult, err error) { + v = cleanValues(v) + v.Set("id", id) + v.Set("tweet_id", fmt.Sprintf("%d", tweetId)) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/entries/add.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) RemoveEntryFromCollection(id string, tweetId int64, v url.Values) (result CollectionEntryAddResult, err error) { + v = cleanValues(v) + v.Set("id", id) + v.Set("tweet_id", fmt.Sprintf("%d", tweetId)) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/entries/remove.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} + +func (a TwitterApi) MoveEntryFromCollection(id string, tweetId, relativeTo int64, v url.Values) (result CollectionEntryAddResult, err error) { + v = cleanValues(v) + v.Set("id", id) + v.Set("tweet_id", fmt.Sprintf("%d", tweetId)) + v.Set("relative_to", fmt.Sprintf("%d", relativeTo)) + response_ch := make(chan response) + a.queryQueue <- query{a.baseUrl + "/collections/entries/move.json", v, &result, _POST, response_ch} + return result, (<-response_ch).err +} diff --git a/twitter.go b/twitter.go index 069d581..535efef 100644 --- a/twitter.go +++ b/twitter.go @@ -147,12 +147,22 @@ func SetConsumerKey(consumer_key string) { oauthCredentials.Token = consumer_key } +//GetConsumerKey will return the consumer key set by SetConsumerSecret. +func GetConsumerKey() string { + return oauthClient.Credentials.Token +} + //SetConsumerSecret will set the application-specific secret used in the initial OAuth process //This secret is listed on https://dev.twitter.com/apps/YOUR_APP_ID/show func SetConsumerSecret(consumer_secret string) { oauthCredentials.Secret = consumer_secret } +//GetConsumerSecret will return the consumer secret set by SetConsumerKey. +func GetConsumerSecret() string { + return oauthClient.Credentials.Secret +} + // ReturnRateLimitError specifies behavior when the Twitter API returns a rate-limit error. // If set to true, the query will fail and return the error instead of automatically queuing and // retrying the query when the rate limit expires