Documentation
¶
Overview ¶
Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file. Original Copyright and Attribution: Copyright (c) 2012 Brian Hetro <[email protected]> Use of this source code is governed by the ISC license that can be found in the LICENSE file.
Index ¶
- Constants
- Variables
- func Do(req *Request, name string, args EpArgs, v interface{}) (err error)
- type APIError
- type Application
- func (c *Application) AccessToken(code string) (string, error)
- func (c *Application) AuthenticationURL(state string) (string, error)
- func (c *Application) GetPost(id string) (p Post, err error)
- func (c *Application) GetUser(idname string) (u User, err error)
- func (c *Application) PasswordFlowAuthenticator(userName, userPassword string, appScope Scopes) (aToken string, user User, err error)
- func (c *Application) PasswordToken(userName, userPassword string) (aToken string, err error)
- type Counts
- type Description
- type Entities
- type EpArgs
- type Filter
- type Hashtag
- type Image
- type Link
- type Mention
- type Post
- type Request
- type ResponseMeta
- type Scopes
- type Source
- type Stream
- func (s *Stream) GetNextPost() (post Post, nr int, err error)
- func (s *Stream) Init(app Application, streamName string)
- func (s *Stream) NextPost() (post Post, err error)
- func (s *Stream) Read() (n int, err error)
- func (s *Stream) SetArgs(args EpArgs)
- func (s *Stream) SetUrlValues(values url.Values, init bool) (err error)
- type StreamMarker
- type StreamPosts
- type StreamResponse
- type User
Constants ¶
const ( ScopeBasic = "basic" ScopeStream = "stream" ScopeEmail = "email" ScopeWritePost = "write_post" ScopeFollow = "follow" ScopeMessages = "messages" ScopeExport = "export" )
Variables ¶
var ApiEndpoints = map[string]endpoint{ "retrieve user": {httpGet, apiHost + "/stream/0/users/{{.User}}", nil}, "follow user": {httpPost, apiHost + "/stream/0/users/{{.User}}/follow", nil}, "unfollow user": {httpDelete, apiHost + "/stream/0/users/{{.User}}/follow", nil}, "list followed users": {httpGet, apiHost + "/stream/0/users/{{.User}}/following", nil}, "list following users": {httpGet, apiHost + "/stream/0/users/{{.User}}/followers", nil}, "mute user": {httpPost, apiHost + "/stream/0/users/{{.User}}/mute", nil}, "unmute user": {httpDelete, apiHost + "/stream/0/users/{{.User}}/mute", nil}, "list muted users": {httpGet, apiHost + "/stream/0/users/me/muted", nil}, "search for users": {httpGet, apiHost + "/stream/0/users/search", nil}, "list reposters": {httpGet, apiHost + "/stream/0/posts/{{.Post}}/reposters", nil}, "list starrers": {httpGet, apiHost + "/stream/0/posts/{{.Post}}/star", nil}, "check current token": {httpGet, apiHost + "/stream/0/token", nil}, "create post": {httpPost, apiHost + "/stream/0/posts", nil}, "retrieve post": {httpGet, apiHost + "/stream/0/posts/{{.Post}}", nil}, "delete post": {httpDelete, apiHost + "/stream/0/posts/{{.Post}}", nil}, "retrieve post replies": {httpGet, apiHost + "/stream/0/posts/{{.Post}}/replies", nil}, "retrieve user posts": {httpGet, apiHost + "/stream/0/users/{{.User}}/posts", nil}, "repost post": {httpPost, apiHost + "/stream/0/posts/{{.Post}}/repost", nil}, "unrepost post": {httpDelete, apiHost + "/stream/0/posts/{{.Post}}/repost", nil}, "star post": {httpPost, apiHost + "/stream/0/posts/{{.Post}}/star", nil}, "unstar post": {httpDelete, apiHost + "/stream/0/posts/{{.Post}}/star", nil}, "retrieve user starred posts": {httpGet, apiHost + "/stream/0/users/{{.User}}/stars", nil}, "retrieve tagged posts": {httpGet, apiHost + "/stream/0/posts/tag/{{.Hashtag}}", nil}, "retrieve global stream": {httpGet, apiHost + "/stream/0/posts/stream/global", nil}, "retrieve public stream": {httpGet, apiHost + "/stream/0/streams/public", nil}, "retrieve multiple user personalized stream": {httpGet, apiHost + "/stream/0/streams/app", nil}, "retrieve user personalized stream": {httpGet, apiHost + "/stream/0/posts/stream", nil}, "retrieve user posts stream": {httpGet, apiHost + "/stream/0/users/{{.User}}/posts", nil}, "retrieve user unified stream": {httpGet, apiHost + "/stream/0/posts/stream/unified", nil}, "retrieve user mentions stream": {httpGet, apiHost + "/stream/0/users/{{.User}}/mentions", nil}, "retrieve stream status": {httpGet, apiHost + "/stream/0/streams/{{.Stream}}", nil}, "control stream": {httpPost, apiHost + "/stream/0/streams/{{.Stream}}", nil}, "list subscriptions": {httpGet, apiHost + "/stream/0/subscriptions", nil}, "create subscription": {httpPost, apiHost + "/stream/0/subscriptions", nil}, "delete subscription": {httpDelete, apiHost + "/stream/0/subscriptions/{{.Subscription}}", nil}, "delete all subscriptions": {httpDelete, apiHost + "/stream/0/subscriptions", nil}, "retrieve current user filters": {httpGet, apiHost + "/stream/0/filters", nil}, "create filter": {httpPost, apiHost + "/stream/0/filters", nil}, "retrieve filter": {httpGet, apiHost + "/stream/0/filters/{{.Filter}}", nil}, "delete filter": {httpGet, apiHost + "/stream/0/filters/{{.Filter}}", nil}, "authentication url": {httpGet, apiAuthHost + "/oauth/authenticate?client_id={{urlquery .Id}}&response_type=code&redirect_uri={{urlquery .RedirectURI}}&scope={{urlquery .Scopes.Spaced}}{{if .State}}&state={{urlquery .State}}{{end}}", nil}, "get access token": {httpPost, apiAuthHost + "/oauth/access_token", &epOptions{ResponseEnvelope: false}}, }
var DefaultApplication = &Application{}
Functions ¶
func Do ¶
Do handles all API requests.
The Request contains the authentication token and optional body.
The name comes from ApiEndpoints, with template arguments
provided in args.
The response is unpacked into v.
In the future, you would not call this function directly, but
instead use this helper function for the specific action.
Types ¶
type APIError ¶
type APIError responseMeta
Represents errors returned by ADN as a result of an API call.
type Application ¶
type Application struct {
Id string
Name string
Date string
Version string
Windowed bool
Secret string
RedirectURI string
Scopes Scopes
PasswordSecret string
Token string // Access token, Added, DAW, 06-Nov-2013
UserName string // User name, Added, DAW, 06-Nov-2013
UserId string // User ID, Added, DAW, 06-Nov-2013
}
func (*Application) AccessToken ¶
func (c *Application) AccessToken(code string) (string, error)
During server-side flow, the user will be redirected back with a
code.
AccessToken() uses this code to request an access token for the
user, which is returned as a string.
func (*Application) AuthenticationURL ¶
func (c *Application) AuthenticationURL(state string) (string, error)
Generate the authentication URL for the server-side flow.
func (*Application) GetPost ¶
func (c *Application) GetPost(id string) (p Post, err error)
Retrieve the post specified by id using token as authentication.
func (*Application) GetUser ¶
func (c *Application) GetUser(idname string) (u User, err error)
Retrieve the user specified by idname.
** Works **
func (*Application) PasswordFlowAuthenticator ¶
func (c *Application) PasswordFlowAuthenticator(userName, userPassword string, appScope Scopes) (aToken string, user User, err error)
Authenticate a user via the Password Flow method
Returns: Access Token and User ID in app
func (*Application) PasswordToken ¶
func (c *Application) PasswordToken(userName, userPassword string) (aToken string, err error)
PasswordToken is used to carry out the password flow. The function
submits the username and password to get an access token. This token is returned as a string. ** Works **
type Counts ¶
type Counts struct {
Following int `json:"following"` // The number of users this user is following.
Followers int `json:"followers"` // The number of users following this user.
Posts int `json:"posts"` // The number of posts created by this user.
Stars int `json:"stars"` // The number of posts starred by this user.
}
type Description ¶
type EpArgs ¶
type EpArgs struct {
User, Post, Hashtag, Stream, Subscription, Filter string
}
These fields are used to fill the endpoint template.
type Filter ¶
type Filter struct {
Type string `json:"type"` // Either "show" or "block" for whether this filter should exclude everything except for what's shown or show everything except for what's blocked.
Name string `json:"name"` // A User assigned name for this filter.
UserIds []string `json:"user_ids"` // A slice of user ids a Post must or must not be created by.
LinkDomains []string `json:"link_domains"` // A slice of domains a Post must or must not have a link to.
MentionUserIds []string `json:"mention_user_ids"` // A slice of user ids a Post must or must not mention.
}
type Mention ¶
type Mention struct {
Name string `json:"name"` // The username being mentioned (not including '@').
Id string `json:"id"` // The user id of the mentioned user.
Pos int `json:"pos"` // The 0-based index where the entity includes Text (includes '@').
Len int `json:"len"` // The length of the substring in Text.
}
type Post ¶
type Post struct {
Id string `json:"id"`
User User `json:"user"` // Embedded version of the User object. May not exist if the account has since been deleted.
// CreatedAt string `json:"created_at"` // The time at which the post was created.
CreatedAt time.Time `json:"created_at"` // The time at which the post was created.
Text string `json:"text"` // User supplied text of the post.
HTML string `json:"html"` // Server-generated annotated HTML rendering of the post text.
Source Source `json:"source"`
ReplyTo string `json:"reply_to"` // Id of the post this post is replying to (or "" if not a reply).
ThreadId string `json:"thread_id"` // Id of the post at the root of the thread this post is a part of.
CanonicalURL string `json:"canonical_url"` // The URL of the post's detail page on Alpha.
NumReplies int `json:"num_replies"` // The number of posts created in reply to this post.
NumStars int `json:"num_stars"` // The number of users who have starred this post.
NumReposts int `json:"num_reposts"` // The number of users who have reposted this post.
Annotations []interface{} `json:"annotations"` // TODO implement
Entities Entities `json:"entities"`
IsDeleted bool `json:"is_deleted"` // Has this post been deleted?
MachineOnly bool `json:"machine_only"` // Is this post meant for machines or humans?
YouStarred bool `json:"you_starred"` // Has the current user starred this post?
StarredBy []string `json:"starred_by"` // A partial list of users who have starred this post. (TODO verify)
YouReposted bool `json:"you_reposted"` // Has the current user reposted this post?
Reposters []string `json:"reposters"` // A partial list of users who have reposted this post. (TODO verify)
RepostOf *Post `json:"repost_of"` // If this post is a repost, the original post. (TODO verify self-reference)
}
type ResponseMeta ¶
type Stream ¶
type Stream struct {
PostCount int
// contains filtered or unexported fields
}
func (*Stream) GetNextPost ¶
Get the next post from the current block of posts. If there are
no more posts, try to read in another block of posts.
func (*Stream) Init ¶
func (s *Stream) Init(app Application, streamName string)
type StreamMarker ¶
type StreamPosts ¶
type StreamPosts []Post
type StreamResponse ¶
type StreamResponse struct {
Data StreamPosts `json:"data"`
Meta ResponseMeta `json:"meta"`
Error string
}
Stream response information
type User ¶
type User struct {
Id string `json:"id"`
Username string `json:"username"`
Name string `json:"name"` // The user-supplied Name may be a pseudonym.
Description Description `json:"description"`
Timezone string `json:"timezone"` // The Timezone is in tzinfo format.
Locale string `json:"locale"` // The Locale is in ISO format.
AvatarImage Image `json:"avatar_image"` // The URL and original size of the user's avatar.
CoverImage Image `json:"cover_image"` // The URL and original size of the user's cover image.
Type string `json:"type"` // An account can be human, bot, corporate, or feed.
CreatedAt time.Time `json:"created_at"` // The time at which the User was created in ISO 8601 format.
Counts Counts `json:"counts"`
AppData interface{} `json:"app_data"` // TODO: Opaque information an application may store.
FollowsYou bool `json:"follows_you"` // Does this user follow the user making the request? May be omitted if this is not an authenticated request.
YouFollow bool `json:"you_follow"` // Does this user making the request follow this user? May be omitted if this is not an authenticated request.
YouMuted bool `json:"you_muted"` // Has the user making the request blocked this user? May be omitted if this is not an authenticated request.
}