docbase

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: MIT Imports: 15 Imported by: 1

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")
)

Variables

This section is empty.

Functions

func Version

func Version() string

Version will get a version of the package go-docbase

Types

type Attachment

type Attachment struct {
	ID        AttachmentID `json:"id"`
	Name      string       `json:"name"`
	Size      int64        `json:"size"`
	URL       string       `json:"url"`
	Markdown  string       `json:"markdown"`
	CreatedAt time.Time    `json:"created_at"`
}

type AttachmentID

type AttachmentID int64

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.
	User       *userService
	Tag        *tagService
	Group      *groupService
	Post       *postService
	Comment    *commentService
	Attachment *attachmentService
	// contains filtered or unexported fields
}

A Client manages communication with the Docbase API.

func NewAuthClient

func NewAuthClient(domain, token string) *Client

func NewClient

func NewClient(domain string, httpClient *http.Client) *Client

NewClient returns a new Docbase API client. If a nil httpClient is provided, http.DefaultClient will be used. But it is not authenticated, using methods which requires authentication, raises error. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the docbase.TokenTransport).

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.

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 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"`
	Description    string    `json:"description"`
	PostsCount     int64     `json:"posts_count"`
	LastActivityAt time.Time `json:"last_activity_at"`
	CreatedAt      time.Time `json:"created_at"`
	Users          []User
}

Group represents a Docbase Group.

type GroupID

type GroupID int64

GroupID identifies a Group.

type ListOptions

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

	// For paginated result sets, the number of results to include per page.
	PerPage *int64 `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 {
	ID            PostID    `json:"id"`
	Title         string    `json:"title"`
	Body          string    `json:"body"`
	Draft         bool      `json:"draft"`
	Archived      bool      `json:"archived"`
	URL           string    `json:"url"`
	CreatedAt     string    `json:"created_at"`
	Scope         Scope     `json:"scope"`
	SharingURL    string    `json:"sharing_url"`
	Tags          []Tag     `json:"tags"`
	User          User      `json:"user"`
	StarsCount    int64     `json:"stars_count"`
	GoodJobsCount int64     `json:"good_jobs_count"`
	Comments      []Comment `json:"comments"`
	Groups        []Group   `json:"groups"`
}

Post represents a Docbase Post.

type PostID

type PostID int64

PostID specifies a post id for some API parameters.

type Rate

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

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

	// 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

	Body bytes.Buffer
	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 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 User

type User struct {
	ID                    UserID    `json:"id"`
	Name                  string    `json:"name"`
	Username              string    `json:"username"`
	ProfileImageURL       string    `json:"profile_image_url"`
	Role                  UserRole  `json:"role"`
	PostsCount            int64     `json:"posts_count"`
	LastAccessTime        time.Time `json:"last_access_time"`
	TwoStepAuthentication bool      `json:"two_step_authentication"`
	Groups                []Group   `json:"groups"`
}

User represents a Docbase User.

type UserID

type UserID int64

UserID identifies a User.

type UserRole

type UserRole int64
const (
	UserRoleUser UserRole = iota
	UserRoleAdmin
	UserRoleOwner
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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