docbase

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeEveryone specifies that a post is published for everybody in the team.
	ScopeEveryone = Scope("everyone")
	// ScopeGroup specifies that a post is published for members in specified groups.
	ScopeGroup = Scope("group")
	// ScopePrivate specifies that a post is just for me.
	ScopePrivate = Scope("private")
)
View Source
const (
	PostQuerySortNameScore     = PostQuerySortName("score")
	PostQuerySortNameChangedAt = PostQuerySortName("changed_at")
	PostQuerySortNameCreatedAt = PostQuerySortName("created_at")
	PostQuerySortNameStars     = PostQuerySortName("stars")
	PostQuerySortNameComments  = PostQuerySortName("comments")
	PostQuerySortNameLikes     = PostQuerySortName("likes")
)

Concrete properties to sort posts.

View Source
const (
	PostQueryPropertyNameTitle       = PostQueryPropertyName("title")
	PostQueryPropertyNameBody        = PostQueryPropertyName("body")
	PostQueryPropertyNameComments    = PostQueryPropertyName("comments")
	PostQueryPropertyNameAttachments = PostQueryPropertyName("attachments")
	PostQueryPropertyNameAuthor      = PostQueryPropertyName("author")
	PostQueryPropertyNameCommentedBy = PostQueryPropertyName("commented_by")
	PostQueryPropertyNameLikedBy     = PostQueryPropertyName("liked_by")
	PostQueryPropertyNameTag         = PostQueryPropertyName("tag")
	PostQueryPropertyNameGroup       = PostQueryPropertyName("group")
)

Concrete properties to search the keyword from posts

View Source
const (
	PostQueryDateNameCreatedAt = PostQueryDateName("created_at")
	PostQueryDateNameChangedAt = PostQueryDateName("changed_at")
)

Concrete properties to search the keyword from posts

View Source
const (
	PostQueryMissingNameTag = PostQueryMissingName("tag")
)

Concrete properties to search the keyword from posts

Variables

This section is empty.

Functions

func PostQueryDate

func PostQueryDate(property PostQueryDateName, year, month, day int) string

PostQueryDate specifies the date with property name to search posts

func PostQueryDateFrom

func PostQueryDateFrom(property PostQueryDateName, year, month, day int) string

PostQueryDateFrom specifies the start date with property name to search posts

func PostQueryDateRange

func PostQueryDateRange(property PostQueryDateName, year1, month1, day1, year2, month2, day2 int) string

PostQueryDateRange specifies the date range with property name to search posts

func PostQueryDateTo

func PostQueryDateTo(property PostQueryDateName, year, month, day int) string

PostQueryDateTo specifies the end date with property name to search posts

func PostQueryHasStar

func PostQueryHasStar() string

PostQueryHasStar :

func PostQueryIsDraft

func PostQueryIsDraft() string

PostQueryIsDraft :

func PostQueryIsShared

func PostQueryIsShared() string

PostQueryIsShared :

func PostQueryIsUnread

func PostQueryIsUnread() string

PostQueryIsUnread :

func PostQueryMissing

func PostQueryMissing(property PostQueryMissingName) string

PostQueryMissing specifies a property to search posts which is not filled

func PostQueryOr

func PostQueryOr() string

PostQueryOr :

func PostQueryProperty

func PostQueryProperty(property PostQueryPropertyName, keyword string) string

PostQueryProperty specifies a property to search the keyword from posts

func PostQuerySort

func PostQuerySort(property PostQuerySortName, asc bool) string

PostQuerySort specifies sort order to get posts.

func Version

func Version() string

Version will get a version of the package go-docbase

Types

type AttachmentService

type AttachmentService service

AttachmentService provides access to the installation related functions in the Docbase API.

type Client

type Client struct {

	// User agent used when communicating with the Docbase API.
	UserAgent string

	// Services used for talking to different parts of the Docbase API.
	Team       *TeamService
	Tag        *TagService
	Group      *GroupService
	Post       *PostService
	Comment    *CommentService
	Attachment *AttachmentService
	// contains filtered or unexported fields
}

A Client manages communication with the Docbase API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Docbase API client. If a nil httpClient is provided, http.DefaultClient will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it. If rate limit is exceeded and reset time is in the future, Do returns *RateLimitError immediately without making a network API call.

The provided ctx must be non-nil. If it is canceled or times out, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) NewUploadRequest

func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, mediaType string) (*http.Request, error)

NewUploadRequest creates an upload request. A relative URL can be provided in urlStr, in which case it is resolved relative to the UploadURL of the Client. Relative URLs should always be specified without a preceding slash.

type Comment

type Comment struct {
	Body      string    `json:"body"`
	CreatedAt string    `json:"created_at"`
	ID        CommentID `json:"id"`
	User      User      `json:"user"`
}

Comment represents a Docbase Comment.

type CommentID

type CommentID int64

CommentID identifies a Comment.

type CommentListOptions

type CommentListOptions struct {
	ListOptions
}

CommentListOptions specifies the optional parameters to the CommentService.List methods.

type CommentService

type CommentService service

CommentService handles communication with the Comment related methods of the Docbase API.

func (*CommentService) Create

func (s *CommentService) Create(ctx context.Context, domain Domain, postID PostID, comment *Comment) (*Comment, *Response, error)

Create a comment for a post.

Docbase API docs: https://help.docbase.io/posts/216289

func (*CommentService) Delete

func (s *CommentService) Delete(ctx context.Context, domain Domain, id PostID) (*Response, error)

Delete a comment.

Docbase API docs: https://help.docbase.io/posts/216290

type CreatePostOptions

type CreatePostOptions struct {
	// Required.
	Title string `json:"title"`
	Body  string `json:"body"`

	// Option.
	Draft  bool      `json:"draft,omitempty"`
	Groups []GroupID `json:"groups,omitempty"`
	Scope  Scope     `json:"scope,omitempty"`
	Tags   []string  `json:"tags,omitempty"`
	Notice bool      `json:"notice,omitempty"`

	// Parameters that only owners can use.
	AuthorID    *UserID    `json:"author_id,omitempty"`
	PublishedAt *time.Time `json:"published_at,omitempty"`
}

CreatePostOptions represents a Docbase Post.

type Domain

type Domain string

Domain specifies a team domain for some API parameters.

type Error

type Error struct {
	Resource string `json:"resource"` // resource on which the error occurred
	Field    string `json:"field"`    // field on which the error occurred
	Code     string `json:"code"`     // validation error code
	Message  string `json:"message"`  // Message describing the error. Errors with Code == "custom" will always have this set.
}

An Error reports more details on an individual error in an ErrorResponse. These are the possible validation error codes:

missing:
    resource does not exist
missing_field:
    a required field on a resource has not been set
invalid:
    the formatting of a field is invalid
already_exists:
    another resource has the same valid as this field
custom:
    some resources return this (e.g. github.User.CreateKey()), additional
    information is set in the Message field of the Error

Docbase API docs: https://developer.github.com/v3/#client-errors

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Messages []string       `json:"messages"` // more detail on individual errors
	Value    string         `json:"error"`    // error message
}

An ErrorResponse reports one or more errors caused by an API request.

Docbase API docs: https://developer.github.com/v3/#client-errors

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Group

type Group struct {
	ID   GroupID `json:"id"`
	Name string  `json:"name"`
}

Group represents a Docbase Group.

type GroupID

type GroupID int64

GroupID identifies a Group.

type GroupListOptions

type GroupListOptions struct {
	ListOptions
}

GroupListOptions specifies the optional parameters to the GroupService.List methods.

type GroupService

type GroupService service

GroupService provides access to the installation related functions in the Docbase API.

func (*GroupService) List

func (s *GroupService) List(ctx context.Context, domain Domain, opt *GroupListOptions) ([]*Group, *Response, error)

List groups for a domain.

Docbase API docs: https://help.docbase.io/posts/92978

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PerPage int `url:"per_page,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type Meta

type Meta struct {
	NextPage     string `json:"next_page"`
	PreviousPage string `json:"previous_page"`
	Total        int64  `json:"total"`
}

Meta provides the page values for paginating through a set of results. Any or all of these may be set to the zero value for responses that are not part of a paginated set, or for which there are no additional pages.

func (Meta) Next

func (m Meta) Next() *ListOptions

Next will get a ListOptions for the next page. If there's no next page, it will be nil.

func (Meta) Previous

func (m Meta) Previous() *ListOptions

Previous will get a ListOptions for the previous page. If there's no previous page, it will be nil.

type Post

type Post struct {
	Body      string    `json:"body"`
	Comments  []Comment `json:"comments"`
	CreatedAt string    `json:"created_at"`
	Draft     bool      `json:"draft"`
	Groups    []Group   `json:"groups"`
	ID        PostID    `json:"id"`
	Scope     Scope     `json:"scope"`
	Tags      []Tag     `json:"tags"`
	Title     string    `json:"title"`
	URL       string    `json:"url"`
	User      User      `json:"user"`
}

Post represents a Docbase Post.

type PostEditRequest

type PostEditRequest struct {
	Body   *string   `json:"body,omitempty"`
	Draft  *bool     `json:"draft,omitempty"`
	Groups []GroupID `json:"groups,omitempty"`
	Scope  *Scope    `json:"scope,omitempty"`
	Tags   []string  `json:"tags,omitempty"`
	Title  *string   `json:"title,omitempty"`
}

PostEditRequest represents a request body for `Edit` function.

type PostID

type PostID int64

PostID specifies a post id for some API parameters.

type PostListOptions

PostListOptions specifies the optional parameters to the PostService.List method.

type PostQueryDateName

type PostQueryDateName string

PostQueryDateName specifies a property to search the keyword from posts

func (PostQueryDateName) String

func (s PostQueryDateName) String() string

type PostQueryMissingName

type PostQueryMissingName string

PostQueryMissingName specifies a property to search the keyword from posts

func (PostQueryMissingName) String

func (s PostQueryMissingName) String() string

type PostQueryPropertyName

type PostQueryPropertyName string

PostQueryPropertyName specifies a property to search the keyword from posts

func (PostQueryPropertyName) String

func (s PostQueryPropertyName) String() string

type PostQuerySortName

type PostQuerySortName string

PostQuerySortName specifies a property to sort posts.

func (PostQuerySortName) String

func (s PostQuerySortName) String() string

type PostService

type PostService service

PostService handles communication with the Post related methods of the Docbase API.

func (*PostService) Create

func (s *PostService) Create(ctx context.Context, domain Domain, post *CreatePostOptions) (*Post, *Response, error)

Create a post for a domain.

Docbase API docs: https://help.docbase.io/posts/92980

func (*PostService) Delete

func (s *PostService) Delete(ctx context.Context, domain Domain, id PostID) (*Response, error)

Delete a post.

Docbase API docs: https://help.docbase.io/posts/92982

func (*PostService) Edit

func (s *PostService) Edit(ctx context.Context, domain Domain, id PostID, post *PostEditRequest) (*Post, *Response, error)

Edit a post.

Docbase API docs: https://help.docbase.io/posts/92981

func (*PostService) Get

func (s *PostService) Get(ctx context.Context, domain Domain, id PostID) (*Post, *Response, error)

Get a single post.

Docbase API docs: https://help.docbase.io/posts/97204

func (*PostService) List

func (s *PostService) List(ctx context.Context, domain Domain, opt *PostListOptions) ([]Post, *Response, error)

List posts in a domain. To build query, use PostQueryXXX functions.

Docbase API docs: https://help.docbase.io/posts/92984 Docbase query docs: https://help.docbase.io/posts/59432

type Rate

type Rate struct {
	// The number of requests per hour the client is currently limited to.
	Limit int

	// The number of remaining requests the client can make this hour.
	Remaining int

	// The time at which the current rate limit will reset.
	Reset Timestamp
}

Rate represents the rate limit for the current client.

func (Rate) String

func (r Rate) String() string

type RateLimitError

type RateLimitError struct {
	Rate     Rate           // Rate specifies last known rate limit for the client
	Response *http.Response // HTTP response that caused this error
	Messages []string       `json:"messages"` // error message
}

RateLimitError occurs when Docbase returns 429 Too many requests response with a rate limit remaining value of 0.

func (*RateLimitError) Error

func (r *RateLimitError) Error() string

type Response

type Response struct {
	*http.Response

	Meta
	Rate
}

Response is a Docbase API response. This wraps the standard http.Response returned from Docbase and provides convenient access to things like pagination links.

type Scope

type Scope string

Scope specifies a scope of the post.

func (Scope) String

func (s Scope) String() string

type Tag

type Tag struct {
	Name string `json:"name"`
}

Tag represents a Docbase Tag.

type TagListOptions

type TagListOptions struct {
	ListOptions
}

TagListOptions specifies the optional parameters to the TagService.List methods.

type TagService

type TagService service

TagService provides access to the installation related functions in the Docbase API.

func (*TagService) List

func (s *TagService) List(ctx context.Context, domain Domain, opt *TagListOptions) ([]*Tag, *Response, error)

List tags for a domain.

Docbase API docs: https://help.docbase.io/posts/92979

type Team

type Team struct {
	Domain Domain `json:"domain"`
	Name   string `json:"name"`
}

Team represents a Docbase Team.

type TeamListOptions

type TeamListOptions struct {
	ListOptions
}

TeamListOptions specifies the optional parameters to the TeamService.List methods.

type TeamService

type TeamService service

TeamService provides access to the installation related functions in the Docbase API.

func (*TeamService) List

func (s *TeamService) List(ctx context.Context, opt *TeamListOptions) ([]*Team, *Response, error)

List teams.

Docbase API docs: https://help.docbase.io/posts/92977

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type TokenTransport

type TokenTransport struct {
	Token string

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

TokenTransport is an http.RoundTripper that authenticates all requests with the provided access token.

func (*TokenTransport) Client

func (t *TokenTransport) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated with the provided access token.

func (*TokenTransport) RoundTrip

func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface.

type UploadOptions

type UploadOptions struct {
	Name string `url:"name,omitempty"`
}

UploadOptions specifies the parameters to methods that support uploads.

type User

type User struct {
	ID              UserID `json:"id"`
	Name            string `json:"name"`
	ProfileImageURL string `json:"profile_image_url"`
}

User represents a Docbase User.

type UserID

type UserID int64

UserID identifies a User.

Jump to

Keyboard shortcuts

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