Documentation ¶
Index ¶
- Variables
- func Client(ctx context.Context) *http.Client
- type Campus
- type CampusUser
- type CampusUserWebhookProcessor
- type ComplexLocationUser
- type DuoTime
- type HeaderLink
- type ILocationUser
- type IWebhookPayload
- type Image
- type Language
- type Location
- type LocationUser
- type LocationWebhookProcessor
- type User
- type UserWebhookProcessor
- type Webhook
- type WebhookMetadata
- type WebhookProcessor
Constants ¶
This section is empty.
Variables ¶
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" )
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 ¶
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 ¶
CampusAll returns the list of all campuses in the 42 ecosystem
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 ILocationUser ¶
type ILocationUser interface { LocationUser | ComplexLocationUser }
type IWebhookPayload ¶
type IWebhookPayload interface {
ProcessWebhook(ctx context.Context, metadata *WebhookMetadata, processor WebhookProcessor) error
}
type Image ¶
type Language ¶
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 ¶
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 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 (*User) HasWebhooks ¶
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.
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.