duoapi

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Endpoints is the list of endpoints
	EndpointBaseAPI = "https://api.intra.42.fr"
	EndpointVersion = "/v2"

	EndpointCampus    = EndpointBaseAPI + EndpointVersion + "/campus"
	EndpointLocations = EndpointBaseAPI + EndpointVersion + "/locations"
	EndpointUsers     = EndpointBaseAPI + EndpointVersion + "/users"
)
View Source
var ErrInvalidWebhookProcessor = errors.New("invalid webhook processor for current type")

ErrInvalidWebhookProcessor is returned when the processor is not valid for the requested model. To know which methods are valid for a model, please refer to the implementation of {Model}WebhookProcessor.

Example: for `Location` refers to `LocationWebhookProcessor“

Functions

func Client

func Client(ctx context.Context) *http.Client

Client is the http client with the token set in the header

Types

type Campus

type Campus struct {
	ID                 int         `json:"id"`
	Name               string      `json:"name"`
	TimeZone           string      `json:"time_zone"`
	Language           Language    `json:"language"`
	UsersCount         int         `json:"users_count"`
	VogsphereID        int         `json:"vogsphere_id"`
	Country            string      `json:"country"`
	Address            string      `json:"address"`
	Zip                string      `json:"zip"`
	City               string      `json:"city"`
	Website            string      `json:"website"`
	Facebook           string      `json:"facebook"`
	Twitter            string      `json:"twitter"`
	Active             bool        `json:"active"`
	EmailExtension     string      `json:"email_extension"`
	DefaultHiddenPhone bool        `json:"default_hidden_phone"`
	Endpoint           interface{} `json:"endpoint"`
}

func CampusAll

func CampusAll(ctx context.Context) ([]*Campus, error)

CampusAll returns the list of all campuses in the 42 ecosystem

func CampusGet

func CampusGet(ctx context.Context, campusID string) (*Campus, error)

CampusGet returns the campus with the given ID or nil if not found

type CampusUser

type CampusUser struct {
	ID        int  `json:"id"`
	UserID    int  `json:"user_id"`
	CampusUD  int  `json:"campus_id"`
	IsPrimary bool `json:"is_primary"`
}

func (*CampusUser) HasWebhooks

func (*CampusUser) HasWebhooks() bool

HasWebhooks returns true because the CampusUser model has webhooks.

func (*CampusUser) ProcessWebhook

func (cu *CampusUser) ProcessWebhook(ctx context.Context, metadata *WebhookMetadata, processor WebhookProcessor) error

ProcessWebhook processes a webhook for the CampusUser model.

type CampusUserWebhookProcessor

type CampusUserWebhookProcessor interface {
	WebhookProcessor

	// Create is called when a new campusUser is created.
	Create(campusUser *CampusUser, metadata *WebhookMetadata) error
	// Update is called when a campusUser is updated.
	Update(campusUser *CampusUser, metadata *WebhookMetadata) error
	// Destroy is called when a campusUser is destroyed.
	Destroy(campusUser *CampusUser, metadata *WebhookMetadata) error
}

CampusUserWebhookProcessor is the interface that must be implemented by a webhook processor for the CampusUser model.

type ComplexLocationUser

type ComplexLocationUser struct {
	ID              int     `json:"id"`
	Login           string  `json:"login"`
	URL             string  `json:"url"`
	Email           string  `json:"email"`
	FirstName       string  `json:"first_name"`
	LastName        string  `json:"last_name"`
	UsualFullName   string  `json:"usual_full_name"`
	UsualFirstName  string  `json:"usual_first_name"`
	Phone           string  `json:"phone"`
	Displayname     string  `json:"displayname"`
	Image           Image   `json:"image"`
	Staff           bool    `json:"staff?"`
	CorrectionPoint int     `json:"correction_point"`
	PoolMonth       string  `json:"pool_month"`
	PoolYear        string  `json:"pool_year"`
	Location        string  `json:"location"`
	Wallet          int     `json:"wallet"`
	AnonymizeDate   DuoTime `json:"anonymize_date"`
	CreatedAt       DuoTime `json:"created_at"`
	UpdatedAt       DuoTime `json:"updated_at"`
	Alumni          bool    `json:"alumni"`
	IsLaunched      bool    `json:"is_launched?"`
}

type DuoTime

type DuoTime time.Time

func (DuoTime) Format

func (dt DuoTime) Format(s string) string

func (DuoTime) MarshalJSON

func (dt DuoTime) MarshalJSON() ([]byte, error)

func (*DuoTime) NillableTime

func (dt *DuoTime) NillableTime() *time.Time

func (DuoTime) String

func (dt DuoTime) String() string

func (DuoTime) Time

func (dt DuoTime) Time() time.Time

func (*DuoTime) UnmarshalJSON

func (dt *DuoTime) UnmarshalJSON(b []byte) error
type HeaderLink map[string]string

type ILocationUser

type ILocationUser interface {
	LocationUser | ComplexLocationUser
}

type IWebhookPayload

type IWebhookPayload interface {
	ProcessWebhook(ctx context.Context, metadata *WebhookMetadata, processor WebhookProcessor) error
}

type Image

type Image struct {
	Link     string `json:"link"`
	Versions struct {
		Large  string `json:"large"`
		Medium string `json:"medium"`
		Small  string `json:"small"`
		Micro  string `json:"micro"`
	} `json:"versions"`
}

type Language

type Language struct {
	ID         int    `json:"id"`
	Name       string `json:"name"`
	Identifier string `json:"identifier"`
}

type Location

type Location[UserType ILocationUser] struct {
	ID       int      `json:"id"`
	BeginAt  DuoTime  `json:"begin_at"`
	EndAt    *DuoTime `json:"end_at"`
	Primary  bool     `json:"primary"`
	Host     string   `json:"host"`
	CampusID int      `json:"campus_id"`
	User     UserType `json:"user"`
}

func LocationsActive

func LocationsActive(ctx context.Context, campusID string) ([]*Location[ComplexLocationUser], error)

LocationsActive returns the list of active locations of a campus

func (*Location[LocationUser]) HasWebhooks

func (*Location[LocationUser]) HasWebhooks() bool

HasWebhooks returns true because the Location model has webhooks.

func (*Location[LocationUser]) ProcessWebhook

func (l *Location[LocationUser]) ProcessWebhook(ctx context.Context, metadata *WebhookMetadata, processor WebhookProcessor) error

ProcessWebhook processes a webhook for the Location model.

type LocationUser

type LocationUser struct {
	ID    int    `json:"id"`
	Login string `json:"login"`
	URL   string `json:"url"`
}

type LocationWebhookProcessor

type LocationWebhookProcessor[T ILocationUser] interface {
	WebhookProcessor

	// Create is called when a new location is created.
	Create(location *Location[T], metadata *WebhookMetadata) error
	// Close is called when a location is closed.
	// (When an user disconnects from a location)
	Close(location *Location[T], metadata *WebhookMetadata) error
	// Destroy is called when a location is destroyed.
	// (When a location is invalid and removed by the system)
	Destroy(location *Location[T], metadata *WebhookMetadata) error
}

LocationWebhookProcessor is the interface that must be implemented by a webhook processor for the Location model.

type User

type User struct {
	ID             int    `json:"id"`
	Email          string `json:"email"`
	Login          string `json:"login"`
	FirstName      string `json:"first_name"`
	LastName       string `json:"last_name"`
	UsualFullName  string `json:"usual_full_name"`
	UsualFirstName string `json:"usual_first_name"`
	Image          Image  `json:"image"`
	URL            string `json:"url"`
	Staff          bool   `json:"staff?"`
	Phone          string `json:"phone"`
	PoolMonth      string `json:"pool_month"`
	PoolYear       string `json:"pool_year"`
}

func UserGet

func UserGet(ctx context.Context, userID string) (*User, error)

func (*User) HasWebhooks

func (*User) HasWebhooks() bool

HasWebhooks returns true because the User model has webhooks.

func (*User) ProcessWebhook

func (l *User) ProcessWebhook(ctx context.Context, metadata *WebhookMetadata, processor WebhookProcessor) error

ProcessWebhook processes a webhook for the User model.

type UserWebhookProcessor

type UserWebhookProcessor interface {
	WebhookProcessor

	// Create is called when a new user is created.
	Create(location *User, metadata *WebhookMetadata) error
	// Update is called when an user is updated.
	Update(location *User, metadata *WebhookMetadata) error
	// Alumnize is called when an user is alumnized.
	Alumnize(location *User, metadata *WebhookMetadata) error
}

UserWebhookProcessor is the interface that must be implemented by a webhook processor for the User model.

type Webhook

type Webhook struct {
	Metadata *WebhookMetadata `json:"metadata"`
	Payload  IWebhookPayload  `json:"payload"`
}

Webhook is the JSON structure of a FORMATTED webhook payload. This is the format used acutally internally by the S42 project.

func (*Webhook) UnmarshalJSON

func (w *Webhook) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON FORMATTED payload into a Webhook struct. This is the format used acutally internally by the S42 project.

type WebhookMetadata

type WebhookMetadata struct {
	// Event is the event that triggered the webhook. (Header: X-Event)
	// Possible values are listed on the interface {Model}WebhookProcessor.
	Event string `json:"event"`
	// Model is the model that triggered the webhook. (Header: X-Model)
	// Possible values are all models with WebhookProcessor implemented.
	Model string `json:"model"`
	// DeliveryID is the ID of the webhook delivery. (Header: X-Delivery)
	DeliveryID string `json:"deliveryID"`
}

WebhookMetadata contains the metadata of a webhook. This informations is sended originally by the 42 API on the Header of the webhook.

type WebhookProcessor

type WebhookProcessor interface {
	HasWebhooks() bool
}

WebhookProcessor is the interface that must be implemented by all webhook processors and used to know which models have webhooks.

Source Files

  • campus.go
  • campus_user.go
  • client.go
  • endpoints.go
  • locations.go
  • structs.go
  • time.go
  • user.go
  • webhooks.go

Jump to

Keyboard shortcuts

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