Documentation
¶
Index ¶
- Constants
- type APIResponse
- type APIResponseBase
- func (a APIResponseBase) AllFields() map[string]any
- func (a APIResponseBase) Code() string
- func (a APIResponseBase) FieldValue(field string) (any, error)
- func (a APIResponseBase) HTTPCode() int
- func (a APIResponseBase) HTTPHeaders() http.Header
- func (a APIResponseBase) IsError() bool
- func (a APIResponseBase) IsSuccess() bool
- func (a APIResponseBase) MarshalJSON() ([]byte, error)
- func (a APIResponseBase) Msg() string
- func (a APIResponseBase) Result() string
- func (a *APIResponseBase) SetHTTPCode(code int)
- func (a *APIResponseBase) SetHTTPHeaders(headers http.Header)
- func (a *APIResponseBase) UnmarshalJSON(b []byte) error
- func (a APIResponseBase) XRateLimitLimit() string
- func (a APIResponseBase) XRateLimitRemaining() string
- func (a APIResponseBase) XRateLimitReset() string
- type Client
- type ClientOption
- type CredentialsProvider
- type DoRequestOption
- type OrganizationRoleLevel
- type RESTClient
- type ReactionType
- type SectionData
- type Zuliprc
Constants ¶
const ( // X-RateLimit-Remaining: The number of additional requests of this type // that the client can send before exceeding its limit. XRateLimitRemaining string = "X-RateLimit-Remaining" // X-RateLimit-Limit: The limit that would be applicable to a client that // had not made any recent requests of this type. This is useful for // designing a client's burst behavior so as to avoid ever reaching a // rate limit. XRateLimitLimit string = "X-RateLimit-Limit" // X-RateLimit-Reset: The time at which the client will no longer have any // rate limits applied to it (and thus could do a burst of // X-RateLimit-Limit requests). XRateLimitReset string = "X-RateLimit-Reset" // ResultSuccess is the string returned in the result field when there is // a success operation ResultSuccess string = "success" // ResultError is the string returned in the result field when there is // an error ResultError string = "error" )
const ( RESTClientDefaultTimeout = 5 * time.Second RESTClientLongPollTimeout = 10 * time.Minute )
const ( DefaultUserAgentName = "go-zulip" Version = "v0.1.0-alpha" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
type APIResponse interface { SetHTTPCode(httpCode int) SetHTTPHeaders(headers http.Header) json.Unmarshaler json.Marshaler }
APIResponse is the interface that wraps the basic methods of an API response.
type APIResponseBase ¶
type APIResponseBase struct {
// contains filtered or unexported fields
}
APIResponseBase is the base struct for all API responses.
func (APIResponseBase) AllFields ¶
func (a APIResponseBase) AllFields() map[string]any
AllFields returns all the fields in the response.
func (APIResponseBase) Code ¶
func (a APIResponseBase) Code() string
Code returns a machine-readable error string.
func (APIResponseBase) FieldValue ¶
func (a APIResponseBase) FieldValue(field string) (any, error)
FieldValue returns the value of a field in the response.
func (APIResponseBase) HTTPCode ¶
func (a APIResponseBase) HTTPCode() int
HTTPCode returns the HTTP status code of the response.
func (APIResponseBase) HTTPHeaders ¶
func (a APIResponseBase) HTTPHeaders() http.Header
HTTPHeaders returns the HTTP headers of the response.
func (APIResponseBase) IsError ¶
func (a APIResponseBase) IsError() bool
IsError returns true if the result is an error.
func (APIResponseBase) IsSuccess ¶
func (a APIResponseBase) IsSuccess() bool
IsSuccess returns true if the result is a success.
func (APIResponseBase) MarshalJSON ¶
func (a APIResponseBase) MarshalJSON() ([]byte, error)
func (APIResponseBase) Msg ¶
func (a APIResponseBase) Msg() string
Msg returns the human-readable error message string.
func (APIResponseBase) Result ¶
func (a APIResponseBase) Result() string
Result returns either "error" or "success".
func (*APIResponseBase) SetHTTPCode ¶
func (a *APIResponseBase) SetHTTPCode(code int)
SetHTTPCode sets the HTTP status code of the response.
func (*APIResponseBase) SetHTTPHeaders ¶
func (a *APIResponseBase) SetHTTPHeaders(headers http.Header)
SetHTTPHeaders sets the HTTP headers of the response.
func (*APIResponseBase) UnmarshalJSON ¶
func (a *APIResponseBase) UnmarshalJSON(b []byte) error
func (APIResponseBase) XRateLimitLimit ¶
func (a APIResponseBase) XRateLimitLimit() string
func (APIResponseBase) XRateLimitRemaining ¶
func (a APIResponseBase) XRateLimitRemaining() string
func (APIResponseBase) XRateLimitReset ¶
func (a APIResponseBase) XRateLimitReset() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main HTTP Client to interact with Zulip's API
func NewClient ¶
func NewClient(credentials CredentialsProvider, options ...ClientOption) (*Client, error)
func (*Client) DoFileRequest ¶
func (c *Client) DoFileRequest(ctx context.Context, method, path string, fileName string, file io.Reader, response APIResponse, opts ...DoRequestOption) error
DoFileRequest is the main function to send requests to Zulip's API with a file. For file and emoji uploads.
type ClientOption ¶
type ClientOption func(*clientOptions) error
func WithCustomUserAgent ¶
func WithCustomUserAgent(userAgent string) ClientOption
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
func WithLogger ¶
func WithLogger(logger *slog.Logger) ClientOption
type CredentialsProvider ¶
type CredentialsProvider func() (*credentials, error)
func Credentials ¶
func Credentials(site, email, apiKey string) CredentialsProvider
func CredentialsFromZuliprc ¶
func CredentialsFromZuliprc(filePath string, section string) CredentialsProvider
type DoRequestOption ¶
type DoRequestOption func(*clientSendRequestOptions)
func WithTimeout ¶
func WithTimeout(duration time.Duration) DoRequestOption
type OrganizationRoleLevel ¶
type OrganizationRoleLevel int
const ( OwnerRole OrganizationRoleLevel = 100 AdministratorRole OrganizationRoleLevel = 200 ModeratorRole OrganizationRoleLevel = 300 MemberRole OrganizationRoleLevel = 400 GuestRole OrganizationRoleLevel = 600 )
type RESTClient ¶
type RESTClient interface { DoRequest(ctx context.Context, method, path string, data map[string]any, response APIResponse, opts ...DoRequestOption) error DoFileRequest(ctx context.Context, method, path string, fileName string, file io.Reader, response APIResponse, opts ...DoRequestOption) error }
type ReactionType ¶
type ReactionType string
const ( UnicodeEmojiType ReactionType = "unicode_emoji" RealmEmojiType ReactionType = "realm_emoji" ZulipExtraEmojiType ReactionType = "zulip_extra_emoji" )
type SectionData ¶
SectionData represents the key-value pairs of a section in a zuliprc file
type Zuliprc ¶
type Zuliprc map[string]SectionData
Zuliprc represents the content of a zuliprc file It is a map of sections, where each section is a map of key-value pairs