example

package
v0.92.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package example implements the example provider using jsonplaceholder.typicode.com for demonstration.

Package example implements the example provider using jsonplaceholder.typicode.com for demonstration.

Index

Constants

View Source
const (
	ID               = "example"
	EndpointKey      = "endpoint"
	TokenKey         = "token"
	WebhookSecretKey = "webhook_secret"
)
View Source
const MaxPageSize = 100

MaxPageSize is the maximum number of items per page.

Variables

This section is empty.

Functions

func GetWebhookSecret

func GetWebhookSecret() string

GetWebhookSecret reads the webhook HMAC secret from the example provider config.

Types

type Example

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

Example wraps the jsonplaceholder.typicode.com API client for demonstration purposes. It provides CRUD operations, OAuth stubs, and polling support.

func GetClient

func GetClient() *Example

GetClient reads provider config and returns a new Example client. It falls back to https://jsonplaceholder.typicode.com when no endpoint is configured.

func NewExample

func NewExample(endpoint, token string) *Example

NewExample creates an Example client with the given endpoint and optional auth token. If endpoint is empty, it defaults to https://jsonplaceholder.typicode.com.

func (*Example) Delete

func (e *Example) Delete(ctx context.Context, path string) (*Response, error)

Delete deletes a jsonplaceholder post via DELETE /posts/{path}. If path is empty it defaults to "1".

func (*Example) Get

func (e *Example) Get(ctx context.Context, path string) (*Response, error)

Get fetches a jsonplaceholder post by ID via GET /posts/{path}. If path is empty it defaults to "1".

func (*Example) GetAccessToken

func (*Example) GetAccessToken(_ fiber.Ctx) (*providers.OAuthToken, error)

GetAccessToken simulates an OAuth code exchange for demonstration.

func (*Example) GetAuthorizeURL

func (e *Example) GetAuthorizeURL(state string) string

GetAuthorizeURL returns a constructed OAuth authorize URL for demonstration.

func (*Example) GetStatus

func (e *Example) GetStatus(ctx context.Context, code int) (*Response, error)

GetStatus fetches a jsonplaceholder post by ID to demonstrate HTTP status handling. Non-existent IDs return 404 errors.

func (*Example) GetWithDelay

func (e *Example) GetWithDelay(ctx context.Context, seconds int) (*Response, error)

GetWithDelay fetches a jsonplaceholder post with a timeout context to demonstrate timeout handling patterns.

func (*Example) ListRawEvents

func (e *Example) ListRawEvents(ctx context.Context, cursor string) ([]map[string]any, string, error)

ListRawEvents fetches jsonplaceholder posts as a list for polling demonstration. The cursor is used as a page number for pagination.

func (*Example) Post

func (e *Example) Post(ctx context.Context, _ string, data any) (*Response, error)

Post creates a new jsonplaceholder post via POST /posts with the given data as JSON body.

func (*Example) Put

func (e *Example) Put(ctx context.Context, path string, data any) (*Response, error)

Put updates a jsonplaceholder post via PUT /posts/{path} with the given data as JSON body. If path is empty it defaults to "1".

type ItemsResponse

type ItemsResponse struct {
	Items      []map[string]any `json:"items"`
	NextCursor string           `json:"next_cursor"`
}

ItemsResponse carries a list of items with cursor for polling.

type Response

type Response struct {
	UserID int    `json:"userId"`
	ID     int    `json:"id"`
	Title  string `json:"title"`
	Body   string `json:"body"`
}

Response mirrors jsonplaceholder post response JSON structure.

type WebhookPayload

type WebhookPayload struct {
	EventType string `json:"event_type"`
	EntityID  string `json:"entity_id"`
	Timestamp string `json:"timestamp"`
	Data      any    `json:"data"`
}

WebhookPayload represents a webhook event payload from the example provider.

Jump to

Keyboard shortcuts

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