anaconda

package module
v0.0.0-...-b2b32d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2013 License: MIT Imports: 7 Imported by: 0

README

Anaconda
====================


Anaconda is a simple, transparent Go package for accessing version 1.1 of the Twitter API. 

Successful API queries return native Go structs that can be used immediately, with no need for type assertions.



Examples
-------------

### Authentication

If you already have the access token (and secret) for your user (Twitter provides this for your own account on the developer portal), creating the client is simple:

````go
anaconda.SetConsumerKey("your-consumer-key")
anaconda.SetConsumerSecret("your-consumer-secret")
api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
````

### Queries

Queries are conducted using the authenticated `TwitterApi` struct. In v1.1 of Twitter's API, all requests should be authenticated.

````go
searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult {
    fmt.Println(tweet.Text)
}   
````
Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter. 

````go
//Perhaps we want 30 values instead of the default 15
v := url.Values{}
v.Set("count", "30")
result, err := api.GetSearch("golang", v)
````

(Remember that `url.Values` is equivalent to a `map[string][]string`, if you find that more convenient notation when specifying values). Otherwise, `nil` suffices.



Endpoints
------------

Anaconda implements most of the endpoints defined in the [Twitter API documentation](https://dev.twitter.com/docs/api/1.1). For clarity, in most cases, the function name is simply the name of the HTTP method and the endpoint (e.g., the endpoint `GET /friendships/incoming` is provided by the function `GetFriendshipsIncoming`).

In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function `Retweet`)



License
-----------
Anaconda is free software licensed under the MIT/X11 license. Details provided in the LICENSE file.

Documentation

Overview

Package anaconda provides structs and functions for accessing version 1.1 of the Twitter API.

Successful API queries return native Go structs that can be used immediately, with no need for type assertions.

Authentication

If you already have the access token (and secret) for your user (Twitter provides this for your own account on the developer portal), creating the client is simple:

anaconda.SetConsumerKey("your-consumer-key")
anaconda.SetConsumerSecret("your-consumer-secret")
api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")

Queries

Executing queries on an authenticated TwitterApi struct is simple.

searchResult, _ := api.GetSearch("golang", nil)
for _ , tweet := range searchResult {
    fmt.Print(tweet.Text)
}

Certain endpoints allow separate optional parameter; if desired, these can be passed as the final parameter.

v := url.Values{}
v.Set("count", "30")
result, err := api.GetSearch("golang", v)

Endpoints

Anaconda implements most of the endpoints defined in the Twitter API documentation: https://dev.twitter.com/docs/api/1.1. For clarity, in most cases, the function name is simply the name of the HTTP method and the endpoint (e.g., the endpoint `GET /friendships/incoming` is provided by the function `GetFriendshipsIncoming`).

In a few cases, a shortened form has been chosen to make life easier (for example, retweeting is simply the function `Retweet`)

More detailed information about the behavior of each particular endpoint can be found at the official Twitter API documentation.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizationURL

func AuthorizationURL(callback string) (string, error)

AuthorizationURL generates the authorization URL for the first part of the OAuth handshake. Redirect the user to this URL. This assumes that the consumer key has already been set (using SetConsumerKey).

func SetConsumerKey

func SetConsumerKey(consumer_key string)

SetConsumerKey will set the application-specific consumer_key used in the initial OAuth process This key is listed on https://dev.twitter.com/apps/YOUR_APP_ID/show

func SetConsumerSecret

func SetConsumerSecret(consumer_secret string)

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

Types

type Cursor

type Cursor struct {
	Previous_cursor     int64
	Previous_cursor_str string

	Ids []int64

	Next_cursor     int64
	Next_cursor_str string
}

type DirectMessage

type DirectMessage struct {
	Sender struct {
		Screen_name string
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

type Friendship

type Friendship struct {
	Name        string
	Id_str      string
	Id          int64
	Connections []string
	Screen_name string
}

type Retweet

type Retweet struct {
	Favorited     *bool
	User          TwitterUser
	Truncated     *bool
	Text          *string
	Retweet_count *float64
	Entities      struct {
		Urls          []interface{}
		Hashtags      []interface{}
		User_mentions []interface{}
	}
	Retweeted_status struct {
		Favorited     *bool
		User          TwitterUser
		Truncated     *bool
		Text          *string
		Retweet_count *float64
		Entities      struct {
			Hashtags      []interface{}
			User_mentions []interface{}
			Urls          []interface{}
		}
		Id_str     *string
		Created_at *string
		Source     *string
		Id         *float64
		Retweeted  *bool
	}
	Id_str     *string
	Created_at *string
	Source     *string
	Id         *float64
	Retweeted  *bool
}

type Tweet

type Tweet struct {
	Source        string
	Id            int64
	Retweeted     bool
	Favorited     bool
	User          TwitterUser
	Truncated     bool
	Text          string
	Retweet_count int64
	Id_str        string
	Created_at    string
	Entities      TwitterEntities
}

type TwitterApi

type TwitterApi struct {
	Credentials *oauth.Credentials
}

func NewTwitterApi

func NewTwitterApi(access_token string, access_token_secret string) TwitterApi

NewTwitterApi takes an user-specific access token and secret and returns a TwitterApi struct for that user. The TwitterApi struct can be used for accessing any of the endpoints available.

func (TwitterApi) DeleteTweet

func (a TwitterApi) DeleteTweet(id int64, trimUser bool) (tweet Tweet, err error)

DeleteTweet will destroy (delete) the status (tweet) with the specified ID, assuming that the authenticated user is the author of the status (tweet). If trimUser is set to true, only the user's Id will be provided in the user object returned.

func (TwitterApi) GetDirectMessages

func (a TwitterApi) GetDirectMessages(v url.Values) (messages []DirectMessage, err error)

func (TwitterApi) GetDirectMessagesSent

func (a TwitterApi) GetDirectMessagesSent(v url.Values) (messages []DirectMessage, err error)

func (TwitterApi) GetDirectMessagesShow

func (a TwitterApi) GetDirectMessagesShow(v url.Values) (messages []DirectMessage, err error)

func (TwitterApi) GetFollowersList

func (a TwitterApi) GetFollowersList(v url.Values) (c TwitterUserCursor, err error)

func (TwitterApi) GetFriendsIds

func (a TwitterApi) GetFriendsIds(v url.Values) (c Cursor, err error)

func (TwitterApi) GetFriendshipsIncoming

func (a TwitterApi) GetFriendshipsIncoming(v url.Values) (c Cursor, err error)

func (TwitterApi) GetFriendshipsLookup

func (a TwitterApi) GetFriendshipsLookup(v url.Values) (friendships []Friendship, err error)

func (TwitterApi) GetFriendshipsNoRetweets

func (a TwitterApi) GetFriendshipsNoRetweets() (ids []int64, err error)

GetFriendshipsNoRetweets returns a collection of user_ids that the currently authenticated user does not want to receive retweets from. It does not currently support the stringify_ids parameter

func (TwitterApi) GetFriendshipsOutgoing

func (a TwitterApi) GetFriendshipsOutgoing(v url.Values) (c Cursor, err error)

func (TwitterApi) GetHomeTimeline

func (a TwitterApi) GetHomeTimeline() (timeline []Tweet, err error)

func (TwitterApi) GetMentionsTimeline

func (a TwitterApi) GetMentionsTimeline(v url.Values) (timeline []Tweet, err error)

func (TwitterApi) GetRetweets

func (a TwitterApi) GetRetweets(id int64, v url.Values) (tweets []Tweet, err error)

func (TwitterApi) GetRetweetsOfMe

func (a TwitterApi) GetRetweetsOfMe(v url.Values) (tweets []Tweet, err error)

func (TwitterApi) GetSearch

func (a TwitterApi) GetSearch(query string, v url.Values) (timeline []Tweet, err error)
Example
package main

import (
	"fmt"
	"github.com/ChimeraCoder/anaconda"
)

func main() {

	anaconda.SetConsumerKey("your-consumer-key")
	anaconda.SetConsumerSecret("your-consumer-secret")
	api := anaconda.NewTwitterApi("your-access-token", "your-access-token-secret")
	search_result, err := api.GetSearch("golang", nil)
	if err != nil {
		panic(err)
	}
	for _, tweet := range search_result {
		fmt.Print(tweet.Text)
	}
}
Output:

func (TwitterApi) GetTweet

func (a TwitterApi) GetTweet(id int64, v url.Values) (tweet Tweet, err error)

func (TwitterApi) GetUserTimeline

func (a TwitterApi) GetUserTimeline(v url.Values) (timeline []Tweet, err error)

func (TwitterApi) GetUsersLookup

func (a TwitterApi) GetUsersLookup(usernames string, v url.Values) (u []TwitterUser, err error)

func (TwitterApi) PostTweet

func (a TwitterApi) PostTweet(status string, v url.Values) (tweet Tweet, err error)

PostTweet will create a tweet with the specified status message

func (TwitterApi) Retweet

func (a TwitterApi) Retweet(id int64, trimUser bool) (rt Retweet, err error)

Retweet will retweet the status (tweet) with the specified ID. trimUser functions as in DeleteTweet

type TwitterEntities

type TwitterEntities struct {
	Hashtags []struct {
		Indices []int
		Text    string
	}
	Urls []struct {
		Indices      []int
		Url          string
		Display_url  string
		Expanded_url string
	}
	User_mentions []struct {
		Name        string
		Indices     []int
		Screen_name string
		Id          int64
		Id_str      string
	}
}

type TwitterUser

type TwitterUser struct {
	Statuses_count                     *int64
	Contributors_enabled               *bool
	Friends_count                      *int64
	Geo_enabled                        *bool
	Description                        *string
	Profile_sidebar_border_color       *string
	Screen_name                        *string
	Listed_count                       *int64
	Followers_count                    *int64
	Location                           *string
	Profile_background_image_url       *string
	Name                               *string
	Default_profile_image              *bool
	Profile_image_url_https            *string
	Notifications                      *bool
	Protected                          *bool
	Id_str                             *string
	Profile_background_color           *string
	Created_at                         *string
	Default_profile                    *bool
	Url                                *string
	Id                                 *int64
	Verified                           *bool
	Profile_link_color                 *string
	Profile_image_url                  *string
	Profile_use_background_image       *bool
	Favourites_count                   *int64
	Profile_background_image_url_https *string
	Profile_sidebar_fill_color         *string
	Is_translator                      *bool
	Follow_request_sent                *bool
	Following                          *bool
	Profile_background_tile            *bool
	Show_all_inline_media              *bool
	Profile_text_color                 *string
	Lang                               *string
	Entities                           *TwitterEntities
}

type TwitterUserCursor

type TwitterUserCursor struct {
	Previous_cursor     int64
	Previous_cursor_str string
	Next_cursor         int64
	Next_cursor_str     string
	Users               []TwitterUser
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL