twitter

package
v0.0.0-...-576eb72 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_TWEET_LENGTH    = 140
	URL_CONSUMED_LENGTH = 23
)
View Source
const (
	REQUEST_TOKEN_URL  = "https://twitter.com/oauth/request_token"
	ACCESS_TOKEN_URL   = "https://twitter.com/oauth/access_token"
	AUTHORIZATION_URL  = "https://twitter.com/oauth/authorize"
	AUTHENTICATION_URL = "https://twitter.com/oauth/authenticate"
	API_BASE_URL       = "https://api.twitter.com/1.1/"
)

Variables

View Source
var (
	STATUS_URL = API_BASE_URL + "statuses/update.json"
)

Functions

func AuthHandler

func AuthHandler(twApp *App, handler Handler) app.Handler

AuthHandler takes a Handler a returns a app.Handler which can be added to a app. When users are directed to this handler, they're first asked to authenticate with Twitter. If the user accepts, Handler is called with a non-nil user and a non-nil token. Otherwise, Handler is called with both parameters set to nil.

Types

type App

type App struct {
	Key    string
	Secret string
	Client *httpclient.Client
	// contains filtered or unexported fields
}

App represents a Twitter application, with its consumer key and secret. To register an application go to https://dev.twitter.com

func (*App) Authenticate

func (app *App) Authenticate(callback string) (string, error)

func (*App) Authorize

func (app *App) Authorize(callback string) (string, error)

func (*App) Clone

func (a *App) Clone(ctx httpclient.Context) *App

func (*App) Exchange

func (app *App) Exchange(token string, verifier string) (*Token, error)

func (*App) Get

func (app *App) Get(token *Token, path string, data map[string]string, out interface{}) error

func (*App) Parse

func (a *App) Parse(s string) error

Parse parses the app credentials from its string representation. It must have the form key:secret. If key or secret contain the ':' character you must quote them (e.g. "k:ey":"sec:ret").

func (*App) Post

func (app *App) Post(token *Token, path string, data map[string]string, out interface{}) error

func (*App) Stats

func (a *App) Stats(urls []string) (map[string]*Stats, error)

func (*App) Update

func (app *App) Update(text string, token *Token, opts *TweetOptions) (*Tweet, error)

Update sends a tweet with the given text, using the provided app and token. Options are optional, you might pass nil.

func (*App) Verify

func (app *App) Verify(token *Token) (*User, error)

type Handler

type Handler func(*app.Context, *User, *Token)

Handler represents a function type which receives the result of authenticating a Twitter user.

type Stats

type Stats struct {
	Normalized string
	Count      int
}

type Token

type Token struct {
	Key    string
	Secret string
}

Token represents a key/secret pair for accessing Twitter services on behalf on another user.

func (*Token) Parse

func (t *Token) Parse(s string) error

Parse parses the token fields from its string representation. It must have the form key:secret. If key or secret contain the ':' character you must quote them (e.g. "k:ey":"sec:ret").

type Tweet

type Tweet struct {
	Id   string `json:"id_str"`
	Text string `json:"text"`
}

type TweetOptions

type TweetOptions struct {
	// If true, text will get truncated if it's longer than
	// the maximum tweet length (instead of returning an error).
	Truncate bool
	// Only has effect if Truncate is true. Rather than truncating
	// at 140 characters, it will truncate at the last whitespace.
	TruncateOnWhitespace bool
	// The ID of an existing status that the update is in reply to.
	// Note that Twitter ignores this unless the referenced id's
	// author is @mentioned in the tweet text.
	InReplyTo string
	// The latitude of the location this tweet refers to.
	Latitude float64
	// The longitude of the location this tweet refers to.
	Longitude float64
	// This parameter only has effect when Latitude and
	// Longitude are set. If this parameter is false, the
	// tweet will contain a pin with the exact location. Set
	// it to true to hide the pin.
	HideCoordinates bool
	// A place retrieved from geo/reverse_geocode
	PlaceId string
}

TweetOptions contains some optional settings which may be specified when sending a tweet.

type TwitterError

type TwitterError struct {
	Message    string
	Code       int
	StatusCode int
}

func (*TwitterError) Error

func (t *TwitterError) Error() string

type TwitterTime

type TwitterTime struct {
	time.Time
}

func (*TwitterTime) UnmarshalJSON

func (t *TwitterTime) UnmarshalJSON(b []byte) error

type User

type User struct {
	Id         string      `json:"id_str"`
	ScreenName string      `json:"screen_name"`
	Name       string      `json:"name"`
	Created    TwitterTime `json:"created_at"`
	Favorites  int         `json:"favourites_count"`
	Followers  int         `json:"followers_count"`
	Following  int         `json:"following_count"`
	Friends    int         `json:"friends_count"`
	ImageURL   string      `json:"profile_image_url"`
}

Jump to

Keyboard shortcuts

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