tent

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

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

Go to latest
Published: Sep 30, 2013 License: BSD-3-Clause Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostTypeApp         = "https://tent.io/types/app/v0#"
	PostTypeAppAuth     = "https://tent.io/types/app-auth/v0#"
	PostTypeCredentials = "https://tent.io/types/credentials/v0#"
)
View Source
const (
	MediaTypePost         = "application/vnd.tent.post.v0+json"
	MediaTypePostsFeed    = "application/vnd.tent.posts-feed.v0+json"
	MediaTypePostVersions = "application/vnd.tent.post-versions.v0+json"
	MediaTypePostMentions = "application/vnd.tent.post-mentions.v0+json"
	MediaTypePostChildren = "application/vnd.tent.post-children.v0+json"
)
View Source
const MediaTypeError = "application/vnd.tent.error.v0+json"
View Source
const RelCredentials = "https://tent.io/rels/credentials"
View Source
const RelMetaPost = "https://tent.io/rels/meta-post"
View Source
const TokenTypeHawk = "https://tent.io/oauth/hawk-token"

Variables

View Source
var ErrInvalidLink = errors.New("tent: invalid meta Link")
View Source
var ErrMissingCredentialsLink = errors.New("tent: missing credentials link")
View Source
var ErrNoPage = errors.New("tent: the requested page does not exist")
View Source
var ErrNotTentEntity = errors.New("tent: not a valid Tent entity")
View Source
var HTTP = newHTTPClient(timeout)
View Source
var UnixTimeUnmarshalError = errors.New("tent: invalid unix timestamp")
View Source
var UserAgent = "tent-go/1"

Functions

func NewRequest

func NewRequest(method, url string, header http.Header, body io.Reader) (*http.Request, error)

func ParseCredentials

func ParseCredentials(post *Post) (*hawk.Credentials, error)

func SetTimeout

func SetTimeout(t time.Duration)

func SplitType

func SplitType(typ string) (base string, fragment string)

func TypeBase

func TypeBase(typ string) string

Types

type AccessTokenRequest

type AccessTokenRequest struct {
	Code      string `json:"code"`
	TokenType string `json:"token_type"`
}

type AccessTokenResponse

type AccessTokenResponse struct {
	HawkID  string `json:"access_token"`
	HawkKey string `json:"hawk_key"`

	HawkAlgorithm string `json:"hawk_algorithm"`
	TokenType     string `json:"token_type"`
}

func (*AccessTokenResponse) HawkCredentials

func (res *AccessTokenResponse) HawkCredentials(app string) *hawk.Credentials

type App

type App struct {
	Name        string   `json:"name"`
	URL         string   `json:"url"`
	Description string   `json:"description,omitempty"`
	Scopes      []string `json:"scopes,omitempty"`

	Types AppTypes `json:"types,omitempty"`

	RedirectURI       string   `json:"redirect_uri"`
	NotificationURL   string   `json:"notification_url,omitempty"`
	NotificationTypes []string `json:"notification_types,omitempty"`

	Post *Post `json:"-"`
}

type AppAuth

type AppAuth struct {
	Active bool     `json:"active"`
	Scopes []string `json:"scopes,omitempty"`

	Types AppTypes `json:"types,omitempty"`

	Post *Post `json:"-"`
}

type AppTypes

type AppTypes struct {
	Read  []string `json:"read,omitempty"`
	Write []string `json:"write,omitempty"`
}

type Client

type Client struct {
	Credentials *hawk.Credentials

	Servers []MetaPostServer
}

func NewClient

func NewClient(credsPost *Post, metaContent []byte) (*Client, error)

func (*Client) CreatePost

func (client *Client) CreatePost(post *Post) error

func (*Client) GetAttachment

func (client *Client) GetAttachment(entity, digest string) (body io.ReadCloser, header http.Header, err error)

func (*Client) GetChildren

func (client *Client) GetChildren(entity, post, version string, r *PageRequest) (*PostListPage, error)

func (*Client) GetFeed

func (client *Client) GetFeed(q *PostsFeedQuery, r *PageRequest) (*PostListPage, error)

func (*Client) GetMentions

func (client *Client) GetMentions(entity, post string, r *PageRequest) (*PostListPage, error)

func (*Client) GetPost

func (client *Client) GetPost(entity, id, version string, r *PostRequest) (*PostEnvelope, error)

func (*Client) GetPostAttachment

func (client *Client) GetPostAttachment(entity, post, version, name, accept string) (body io.ReadCloser, header http.Header, err error)

func (*Client) GetVersions

func (client *Client) GetVersions(entity, post string, r *PageRequest) (*PostListPage, error)

func (*Client) NewRequest

func (client *Client) NewRequest(method, url string, header http.Header, body []byte) (*http.Request, error)

func (*Client) Request

func (client *Client) Request(req func(*MetaPostServer) error) error

func (*Client) RequestAccessToken

func (client *Client) RequestAccessToken(code string) (*hawk.Credentials, error)

func (*Client) SignRequest

func (client *Client) SignRequest(req *http.Request, body []byte)

type Credentials

type Credentials struct {
	HawkKey       string `json:"hawk_key"`
	HawkAlgorithm string `json:"hawk_algorithm"`

	Post *Post
}

type MetaPost

type MetaPost struct {
	Entity  string           `json:"entity"`
	Profile MetaProfile      `json:"profile"`
	Servers []MetaPostServer `json:"servers"`
	Post    *Post            `json:"-"`
}

func Discover

func Discover(entity string) (*MetaPost, error)

func GetMetaPost

func GetMetaPost(url string) (*MetaPost, error)

func ParseMeta

func ParseMeta(content []byte, attachments []*PostAttachment) (*MetaPost, error)

func (*MetaPost) HTTPSOnly

func (meta *MetaPost) HTTPSOnly() bool

type MetaPostServer

type MetaPostServer struct {
	Version    string `json:"version"`
	Preference int    `json:"preference"`

	URLs MetaPostServerURLs `json:"urls"`
}

type MetaPostServerURLs

type MetaPostServerURLs struct {
	OAuthAuth      string `json:"oauth_auth"`
	OAuthToken     string `json:"oauth_token"`
	PostsFeed      string `json:"posts_feed"`
	Post           string `json:"post"`
	NewPost        string `json:"new_post"`
	PostAttachment string `json:"post_attachment"`
	Attachment     string `json:"attachment"`
	Batch          string `json:"batch"`
	ServerInfo     string `json:"server_info"`
}

func (*MetaPostServerURLs) AttachmentURL

func (urls *MetaPostServerURLs) AttachmentURL(entity, digest string) string

func (*MetaPostServerURLs) OAuthURL

func (urls *MetaPostServerURLs) OAuthURL(appID string, state string) string

func (*MetaPostServerURLs) PostAttachmentURL

func (urls *MetaPostServerURLs) PostAttachmentURL(entity, post, version, name string) string

func (*MetaPostServerURLs) PostURL

func (urls *MetaPostServerURLs) PostURL(entity, post, version string) string

type MetaProfile

type MetaProfile struct {
	Name     string `json:"name,omitempty"`
	Bio      string `json:"bio,omitempty"`
	Website  string `json:"website,omitempty"`
	Location string `json:"location,omitempty"`

	AvatarDigest string `json:"avatar_digest,omitempty"`
}

type MultipartPostWriter

type MultipartPostWriter struct {
	// contains filtered or unexported fields
}

func NewMultipartPostWriter

func NewMultipartPostWriter(w io.Writer) *MultipartPostWriter

func (*MultipartPostWriter) Close

func (w *MultipartPostWriter) Close() error

func (*MultipartPostWriter) ContentType

func (w *MultipartPostWriter) ContentType() string

func (*MultipartPostWriter) WriteAttachment

func (w *MultipartPostWriter) WriteAttachment(att *PostAttachment) error

func (*MultipartPostWriter) WritePost

func (w *MultipartPostWriter) WritePost(post *Post) error
type PageHeader struct {
	ETag        string
	Count       int
	NotModified bool
}
type PageLinks struct {
	First string `json:"first,omitempty"`
	Prev  string `json:"prev,omitempty"`
	Next  string `json:"next,omitempty"`
	Last  string `json:"last,omitempty"`
	// contains filtered or unexported fields
}

type PageRequest

type PageRequest struct {
	ETag      string
	CountOnly bool
	Limit     int
}

type Post

type Post struct {
	ID string `json:"id,omitempty" sfilter:"version"`

	Entity         string `json:"entity,omitempty" sfilter:"version"`
	OriginalEntity string `json:"original_entity,omitempty"`

	Type    string          `json:"type" sfilter:"version"`
	Content json.RawMessage `json:"content,omitempty" sfilter:"version"`

	Version *PostVersion `json:"version,omitempty" sfilter:"version"`

	Refs        []PostRef         `json:"refs,omitempty" sfilter:"version"`
	Mentions    []PostMention     `json:"mentions,omitempty" sfilter:"version"`
	Licenses    []PostLicense     `json:"licenses,omitempty" sfilter:"version"`
	Attachments []*PostAttachment `json:"attachments,omitempty" sfilter:"version"`
	Permissions *PostPermissions  `json:"permissions,omitempty"`

	App *PostApp `json:"app,omitempty" sfilter:"version"`

	ReceivedAt  *UnixTime `json:"received_at,omitempty"`
	PublishedAt *UnixTime `json:"published_at,omitempty" sfilter:"version"`

	Links []link.Link `json:"-"`

	Notification bool `json:"-"`
}

func NewAppPost

func NewAppPost(app *App) *Post

func (*Post) CalculateVersion

func (post *Post) CalculateVersion() (string, []byte, error)

func (*Post) LinkedCredentials

func (post *Post) LinkedCredentials() (*hawk.Credentials, *Post, error)

type PostApp

type PostApp struct {
	Name string `json:"name,omitempty" sfilter:"version"`
	URL  string `json:"url,omitempty" sfilter:"version"`
	ID   string `json:"id,omitempty"`
}

type PostAttachment

type PostAttachment struct {
	Name        string `json:"name" sfilter:"version"`
	Category    string `json:"category" sfilter:"version"`
	ContentType string `json:"content_type" sfilter:"version"`
	Size        int64  `json:"size,omitempty" sfilter:"version"`
	Digest      string `json:"digest,omitempty" sfilter:"version"`

	// Include Data to upload a new attachment with the post
	Data ReadLenSeeker `json:"-"`
	// contains filtered or unexported fields
}

func (*PostAttachment) Close

func (att *PostAttachment) Close() error

func (*PostAttachment) Read

func (att *PostAttachment) Read(p []byte) (int, error)

Read downloads and reads from the attachment body. The attachment must have be initialized by downloading the containing post from the server in order to use Read.

type PostEnvelope

type PostEnvelope struct {
	Post *Post  `json:"post"`
	Refs []Post `json:"refs"`
}

func GetPost

func GetPost(url string) (*PostEnvelope, error)

type PostLicense

type PostLicense struct {
	URL string `json:"url" sfilter:"version"`
}

type PostListPage

type PostListPage struct {
	Mentions []*PostMention `json:"mentions,omitempty"`
	Versions []*PostVersion `json:"versions,omitempty"`
	Posts    []*Post        `json:"posts,omitempty"`
	Links    PageLinks      `json:"pages"`
	Header   PageHeader     `json:"-"`
}

func (*PostListPage) First

func (f *PostListPage) First() (*PostListPage, error)

func (*PostListPage) Last

func (f *PostListPage) Last() (*PostListPage, error)

func (*PostListPage) Next

func (f *PostListPage) Next() (*PostListPage, error)

func (*PostListPage) Prev

func (f *PostListPage) Prev() (*PostListPage, error)

type PostMention

type PostMention struct {
	Entity         string `json:"entity,omitempty" sfilter:"version"`
	OriginalEntity string `json:"original_entity,omitempty"`
	Post           string `json:"post,omitempty" sfilter:"version"`
	Version        string `json:"version,omitempty" sfilter:"version"`
	Type           string `json:"type,omitempty" sfilter:"version"`
	PublicFlag     *bool  `json:"public,omitempty"` // nil or true is public == true; false is public == false
}

func (*PostMention) Public

func (mention *PostMention) Public() bool

type PostPermissions

type PostPermissions struct {
	PublicFlag *bool    `json:"public,omitempty"` // nil or true is public == true; false is public == false
	Groups     []string `json:"groups,omitempty"`
	Entities   []string `json:"entities,omitempty"`
}

func (*PostPermissions) Public

func (perm *PostPermissions) Public() bool

type PostRef

type PostRef struct {
	Entity         string `json:"entity,omitempty" sfilter:"version"`
	OriginalEntity string `json:"original_entity,omitempty"`
	Post           string `json:"post,omitempty" sfilter:"version"`
	Version        string `json:"version,omitempty" sfilter:"version"`
	Type           string `json:"type,omitempty" sfilter:"version"`
}

type PostRequest

type PostRequest struct {
	MaxRefs int
}

type PostVersion

type PostVersion struct {
	ID          string              `json:"id,omitempty"`
	Parents     []PostVersionParent `json:"parents,omitempty" sfilter:"version"`
	Message     string              `json:"message,omitempty" sfilter:"version"`
	PublishedAt *UnixTime           `json:"published_at,omitempty" sfilter:"version"`
	ReceivedAt  *UnixTime           `json:"received_at,omitempty"`

	// Used in post version and children lists
	Type   string `json:"type,omitempty"`
	Entity string `json:"entity,omitempty"`
	Post   string `json:"post,omitempty"`
}

type PostVersionParent

type PostVersionParent struct {
	Entity         string `json:"entity,omitempty" sfilter:"version"`
	OriginalEntity string `json:"original_entity,omitempty"`
	Post           string `json:"post,omitempty" sfilter:"version"`
	Version        string `json:"version" sfilter:"version"`
}

type PostsFeedQuery

type PostsFeedQuery struct{ url.Values }

func NewPostsFeedQuery

func NewPostsFeedQuery() *PostsFeedQuery

func (*PostsFeedQuery) Before

func (q *PostsFeedQuery) Before(t time.Time, version string) *PostsFeedQuery

func (*PostsFeedQuery) Entities

func (q *PostsFeedQuery) Entities(entities ...string) *PostsFeedQuery

func (*PostsFeedQuery) Limit

func (q *PostsFeedQuery) Limit(n int) *PostsFeedQuery

func (*PostsFeedQuery) MaxRefs

func (q *PostsFeedQuery) MaxRefs(n int) *PostsFeedQuery

func (*PostsFeedQuery) Mentions

func (q *PostsFeedQuery) Mentions(mentions ...[]string) *PostsFeedQuery

func (*PostsFeedQuery) Since

func (q *PostsFeedQuery) Since(t time.Time, version string) *PostsFeedQuery

func (*PostsFeedQuery) Types

func (q *PostsFeedQuery) Types(types ...string) *PostsFeedQuery

func (*PostsFeedQuery) Until

func (q *PostsFeedQuery) Until(t time.Time, version string) *PostsFeedQuery

type ReadLenSeeker

type ReadLenSeeker interface {
	io.ReadSeeker
	Len() int64
}

type RequestError

type RequestError struct {
	Err     error
	Request *http.Request
}

func (*RequestError) Error

func (e *RequestError) Error() string

type ResponseError

type ResponseError struct {
	Type      ResponseErrorType
	Response  *http.Response
	TentError *TentError
}

func (*ResponseError) Error

func (e *ResponseError) Error() string

type ResponseErrorType

type ResponseErrorType int
const (
	ErrBadStatusCode ResponseErrorType = iota
	ErrBadContentType
	ErrBadData
	ErrReadTimeout
)

type TentError

type TentError struct {
	Error  string            `json:"error"`
	Fields map[string]string `json:"fields"`
}

type UnixTime

type UnixTime struct{ time.Time }

func (UnixTime) MarshalJSON

func (t UnixTime) MarshalJSON() ([]byte, error)

func (UnixTime) UnixMillis

func (t UnixTime) UnixMillis() int64

func (*UnixTime) UnmarshalJSON

func (t *UnixTime) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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