Documentation
¶
Index ¶
- func HandleWebhook(handler WebhookHandler, secret string) http.HandlerFunc
- type BearerTokenRoundTripper
- type Challenge
- type Client
- func (c *Client) EncryptPII(encodedPII string) (string, error)
- func (c *Client) EncryptUserPII(firstName, lastName, email string) (string, error)
- func (c *Client) GenerateOneTimePlayToken(trackId string) (token string, err error)
- func (c *Client) GetChallenge(id string) (ch Challenge, err error)
- func (c *Client) GetChallenges(trackId string) (ch []Challenge, err error)
- func (c *Client) GetInvite(inviteId string) (i TrackInvite, err error)
- func (c *Client) GetInvites() (i []TrackInvite, err error)
- func (c *Client) GetPlays(from time.Time, to time.Time, take int, skip int, opts ...Option) ([]PlayReport, int, error)
- func (c *Client) GetReview(id string, opts ...Option) (*Review, error)
- func (c *Client) GetReviews(trackId string, opts ...Option) (count int, reviews []Review, err error)
- func (c *Client) GetSandbox(id string) (s Sandbox, err error)
- func (c *Client) GetSandboxVariable(playID string, key string) (v string, err error)
- func (c *Client) GetSandboxes() (s []Sandbox, err error)
- func (c *Client) GetTPGPublicKey() (string, error)
- func (c *Client) GetTrackById(trackId string, opts ...Option) (t Track, err error)
- func (c *Client) GetTrackBySlug(trackSlug string, opts ...Option) (t Track, err error)
- func (c *Client) GetTrackUnlockedChallenge(userId string, trackId string) (challenge Challenge, err error)
- func (c *Client) GetTracks(opts ...Option) (tt []Track, err error)
- func (c *Client) GetUserChallenge(userId string, id string) (ch Challenge, err error)
- func (c *Client) GetUserInfo(userId string) (u UserInfo, err error)
- func (c *Client) GetUserTrackById(userId string, trackId string, opts ...Option) (t SandboxTrack, err error)
- func (c *Client) SkipToChallenge(userId string, trackId string, id string) (err error)
- func (c *Client) WithContext(ctx context.Context) *Client
- type Direction
- type GraphQLClient
- type Option
- func WithChallenges() Option
- func WithOrdering(orderBy OrderBy, direction Direction) Option
- func WithPlay() Option
- func WithPlayType(pt PlayType) Option
- func WithReviews() Option
- func WithTags(tags ...string) Option
- func WithTrackIDs(ids ...string) Option
- func WithTrackInviteIDs(ids ...string) Option
- func WithUserIDs(ids ...string) Option
- type OrderBy
- type Ordering
- type Play
- type PlayReport
- type PlayReports
- type PlayType
- type Review
- type Sandbox
- type SandboxTrack
- type SandboxVar
- type Track
- type TrackInvite
- type TrackInviteClaim
- type TrackTag
- type User
- type UserDetails
- type UserInfo
- type UserProfile
- type WebhookEvent
- type WebhookHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleWebhook ¶ added in v1.2.0
func HandleWebhook(handler WebhookHandler, secret string) http.HandlerFunc
HandleWebhook is an HTTP handler that validates and processes incoming webhooks It takes a WebhookHandler function and a secret for validating the webhook signature.
Types ¶
type BearerTokenRoundTripper ¶
type BearerTokenRoundTripper struct { Transport http.RoundTripper // The underlying transport to use for HTTP requests. Token string // The Bearer token for authorization. }
BearerTokenRoundTripper is a custom HTTP RoundTripper that adds a Bearer token for authorization in the HTTP request headers.
func (*BearerTokenRoundTripper) RoundTrip ¶
RoundTrip executes a single HTTP transaction, adding the Authorization header with the Bearer token to the request before forwarding it to the underlying transport.
Parameters:
- req: The HTTP request to be sent.
Returns:
- An HTTP response and any error encountered while making the request.
type Challenge ¶
type Challenge struct { Id string `json:"id"` // The unique identifier for the challenge. Slug string `json:"slug"` // The slug for the challenge, which is a human-readable identifier. Title string `json:"title"` // The title of the challenge. Index int `json:"index"` // The index of the challenge in the track. Status string `json:"status"` // The status of the challenge (e.g., "unlocked", "completed"). Track struct { Id string // The identifier for the track associated with the challenge. } `json:"-"` }
Challenge represents the data structure for an Instruqt challenge.
type Client ¶
type Client struct { GraphQLClient GraphQLClient // The GraphQL client used to execute queries and mutations. InfoLogger *log.Logger // Logger for informational messages. DebugLogger *log.Logger // Logger for debug messages. TeamSlug string // The slug identifier for the team within Instruqt. Context context.Context // Default context for API requests }
Client represents the Instruqt API client, which provides methods to interact with the Instruqt platform. It includes a GraphQL client, logging capabilities, and the team slug to identify which team's data to interact with.
func NewClient ¶
NewClient creates a new instance of the Instruqt API client. It initializes the GraphQL client with the provided API token and team slug.
Parameters:
- token: The API token used for authentication with the Instruqt GraphQL API.
- teamSlug: The slug identifier for the team.
Returns:
- A pointer to the newly created Client instance.
func (*Client) EncryptPII ¶
EncryptPII encrypts PII using the public key fetched from the GetTPGPublicKey function. It takes a string representing the PII data, encodes it, and then encrypts it using RSA.
func (*Client) EncryptUserPII ¶
EncryptUserPII creates PII data (first name, last name, and email) and encrypts it using the public key.
func (*Client) GenerateOneTimePlayToken ¶
GenerateOneTimePlayToken generates a one-time play token for a specific track.
Parameters:
- trackId: The unique identifier of the track.
Returns:
- string: The generated one-time play token.
- error: Any error encountered while generating the token.
func (*Client) GetChallenge ¶
GetChallenge retrieves a challenge from Instruqt using its unique challenge ID.
Parameters:
- id: The unique identifier of the challenge to retrieve.
Returns:
- Challenge: The challenge details if found.
- error: Any error encountered while retrieving the challenge.
func (*Client) GetChallenges ¶ added in v1.6.0
GetChallenges retrieves all challenges for a Track using its unique track ID.
Parameters:
- trackId: The unique identifier of the track to retrieve.
Returns:
- []Challenge: The list of challenges.
- error: Any error encountered while retrieving the challenge.
func (*Client) GetInvite ¶
func (c *Client) GetInvite(inviteId string) (i TrackInvite, err error)
GetInvite retrieves a track invite from Instruqt using its unique invite ID.
Parameters:
- inviteId: The unique identifier of the track invite to retrieve.
Returns:
- TrackInvite: The track invite details if found.
- error: Any error encountered while retrieving the invite.
func (*Client) GetInvites ¶
func (c *Client) GetInvites() (i []TrackInvite, err error)
GetInvites retrieves all track invites for the specified team slug from Instruqt.
Returns:
- []TrackInvite: A list of track invites for the team.
- error: Any error encountered while retrieving the invites.
func (*Client) GetPlays ¶
func (c *Client) GetPlays(from time.Time, to time.Time, take int, skip int, opts ...Option) ([]PlayReport, int, error)
GetPlays retrieves a list of play reports from Instruqt for the specified team, within a given date range, and using pagination parameters.
Parameters:
- from: The start date of the date range filter.
- to: The end date of the date range filter.
- take: The number of play reports to retrieve in one call.
- skip: The number of play reports to skip before starting to retrieve.
- opts: A variadic number of Option to configure the query.
Returns:
- []PlayReport: A list of play reports that match the given criteria.
- int: The total number of play reports available for the given criteria.
- error: Any error encountered while retrieving the play reports.
func (*Client) GetReview ¶ added in v1.1.0
GetReview retrieves a single review by its unique identifier. It accepts optional functional options to include additional fields like 'play'.
Parameters: - id (string): The unique identifier of the review. - opts (...Option): Variadic functional options to modify the query behavior.
Returns: - *Review: A pointer to the retrieved Review. Includes Play if specified. - error: An error object if the query fails or the review is not found.
func (*Client) GetReviews ¶ added in v1.6.0
func (c *Client) GetReviews(trackId string, opts ...Option) (count int, reviews []Review, err error)
GetReviews retrieves all reviews for a Track It accepts optional functional options to include additional fields like 'play'.
Parameters: - trackId (string): The unique identifier of the track. - opts (...Option): Variadic functional options to modify the query behavior.
Returns: - []Review: A list retrieved Reviews. Includes Play if specified. - error: An error object if the query fails or the review is not found.
func (*Client) GetSandbox ¶ added in v1.1.0
GetSandbox retrieves a sandbox by its ID.
Returns:
- Sandbox: The sandbox.
- error: Any error encountered while retrieving the sandbox.
func (*Client) GetSandboxVariable ¶
GetSandboxVariable retrieves a specific variable from a sandbox environment using the sandbox ID and the variable's key.
Parameters:
- playID: The unique identifier of the sandbox environment.
- key: The key of the sandbox variable to retrieve.
Returns:
- string: The value of the requested sandbox variable.
- error: Any error encountered while retrieving the variable.
func (*Client) GetSandboxes ¶
GetSandboxes retrieves all sandboxes associated with the team slug defined in the client.
Returns:
- []Sandbox: A list of sandboxes for the team.
- error: Any error encountered while retrieving the sandboxes.
func (*Client) GetTPGPublicKey ¶
GetTPGPublicKey retrieves the TPG public key for the team associated with the client.
Returns:
- string: The TPG public key of the team.
- error: Any error encountered while retrieving the TPG public key.
func (*Client) GetTrackById ¶
GetTrackById retrieves a track from Instruqt using its unique track ID.
Parameters: - trackId: The unique identifier of the track to retrieve. - opts (...Option): Variadic functional options to modify the query behavior.
Returns:
- Track: The track details if found.
- error: Any error encountered while retrieving the track.
func (*Client) GetTrackBySlug ¶
GetTrackBySlug retrieves a track from Instruqt using its slug and team slug.
Parameters: - trackSlug: The slug identifier of the track to retrieve. - opts (...Option): Variadic functional options to modify the query behavior.
Returns:
- Track: The track details if found.
- error: Any error encountered while retrieving the track.
func (*Client) GetTrackUnlockedChallenge ¶
func (c *Client) GetTrackUnlockedChallenge(userId string, trackId string) (challenge Challenge, err error)
GetTrackUnlockedChallenge retrieves the first unlocked challenge for a specific user's track.
Parameters:
- userId: The unique identifier of the user.
- trackId: The unique identifier of the track.
Returns:
- Challenge: The first unlocked challenge found.
- error: Any error encountered while retrieving the challenge.
func (*Client) GetTracks ¶
Parameters: - opts (...Option): Variadic functional options to modify the query behavior.
Returns: - []Track: A list of tracks for the team. - error: Any error encountered while retrieving the tracks.
func (*Client) GetUserChallenge ¶
GetUserChallenge retrieves a challenge associated with a specific user from Instruqt using the user's ID and the challenge's ID.
Parameters:
- userId: The unique identifier of the user.
- id: The unique identifier of the challenge.
Returns:
- Challenge: The challenge details if found.
- error: Any error encountered while retrieving the challenge.
func (*Client) GetUserInfo ¶
GetUserInfo retrieves the user information from Instruqt using the user's unique ID.
Parameters:
- userId: The unique identifier of the user.
Returns:
- UserInfo: The user's information including first name, last name, and email.
- error: Any error encountered while retrieving the user information.
func (*Client) GetUserTrackById ¶
func (c *Client) GetUserTrackById(userId string, trackId string, opts ...Option) (t SandboxTrack, err error)
GetUserTrackById retrieves a track for a specific user, including its challenges, using the user's ID and the track's ID.
Parameters: - userId: The unique identifier of the user. - trackId: The unique identifier of the track. - opts (...Option): Variadic functional options to modify the query behavior.
Returns:
- SandboxTrack: The track details with challenges if found.
- error: Any error encountered while retrieving the track.
func (*Client) SkipToChallenge ¶
SkipToChallenge allows a user to skip to a specific challenge in a track on Instruqt.
Parameters:
- userId: The unique identifier of the user.
- trackId: The unique identifier of the track.
- id: The unique identifier of the challenge to skip to.
Returns:
- error: Any error encountered while performing the skip operation.
type GraphQLClient ¶
type GraphQLClient interface { Query(context.Context, any, map[string]any, ...graphql.Option) error Mutate(context.Context, any, map[string]any, ...graphql.Option) error }
GraphQLClient is an interface that defines the methods for interacting with a GraphQL API, including querying and mutating data.
type Option ¶ added in v1.1.0
type Option func(*options)
Option defines a functional option for configuring methods. It allows modifying the behavior of query methods, such as including additional fields.
func WithChallenges ¶ added in v1.6.0
func WithChallenges() Option
WithChallenges is a functional option to include challenges. Example usage: GetTrackById("tracKID", WithChallenges())
func WithOrdering ¶ added in v1.1.0
WithOrdering sets the ordering parameters for methods that support it. Usage: GetPlays(from, to, take, skip, WithOrdering(OrderByCompletionPercent, DirectionDesc))
func WithPlay ¶ added in v1.1.0
func WithPlay() Option
WithPlay is a functional option that configures methods to include the 'play' field in the query. Example usage: GetReview("reviewID", WithPlay())
func WithPlayType ¶ added in v1.1.0
WithPlayType sets the PlayType filter for methods that support it. Usage: GetPlays(from, to, take, skip, WithPlayType(PlayTypeDeveloper))
func WithReviews ¶ added in v1.6.0
func WithReviews() Option
WithReviews is a functional option to include reviews. Example usage: GetTrackById("tracKID", WithReviews())
func WithTags ¶ added in v1.1.0
WithTags sets the Tags filter for methods that support it. Usage: GetPlays(from, to, take, skip, WithTags("tag1", "tag2"))
func WithTrackIDs ¶ added in v1.1.0
WithTrackIDs sets the TrackIDs filter for methods that support it. Usage: GetPlays(from, to, take, skip, WithTrackIDs("track1", "track2"))
func WithTrackInviteIDs ¶ added in v1.1.0
WithTrackInviteIDs sets the TrackInviteIDs filter for methods that support it. Usage: GetPlays(from, to, take, skip, WithTrackInviteIDs("invite1", "invite2"))
func WithUserIDs ¶ added in v1.1.0
WithUserIDs sets the UserIDs filter for methods that support it. Usage: GetPlays(from, to, take, skip, WithUserIDs("user1", "user2"))
type OrderBy ¶ added in v1.1.0
type OrderBy string
OrderBy represents the fields by which plays can be ordered.
type Ordering ¶ added in v1.1.0
type Ordering struct { OrderBy OrderBy // Must be "completion_percent" or "time_spent" Direction Direction // "Asc" or "Desc" }
Ordering represents the sorting parameters for plays.
type PlayReport ¶
type PlayReport struct { Id string // The unique identifier for the play report. Track SandboxTrack // The track played. TrackInvite TrackInvite // The optional Track invite associated to the play. User User // The user that played the play. CompletionPercent float64 // The percentage of the play that has been completed. TotalChallenges int // The total number of challenges in the play. CompletedChallenges int // The number of challenges completed by the user in the play. TimeSpent int // The total time spent on the play, in seconds. StoppedReason string // The reason why the play was stopped (if applicable). Mode string // The mode of the play (e.g., NORMAL, DEVELOPER). StartedAt time.Time // The time when the play started. Activity []struct { Time time.Time // The time when the activity occurred. Message string // A message describing the activity. } PlayReview struct { Id string // The unique identifier of the play review. Score int // The score given in the play review. Content string // The content of the play review. } CustomParameters []struct { Key string // The key of the custom parameter. Value string // The value of the custom parameter. } }
PlayReport represents the data structure for a single play report on Instruqt.
type PlayReports ¶
type PlayReports struct { Items []PlayReport // A list of play reports. TotalItems int // The total number of play reports available. }
PlayReports represents a collection of play reports retrieved from Instruqt.
type PlayType ¶ added in v1.1.0
type PlayType string
playType defines a custom type for play modes on Instruqt.
type Review ¶
type Review struct { Play *Play // contains filtered or unexported fields }
Review represents a review for an Instruqt track.
type Sandbox ¶
type Sandbox struct { Id string // The id of the sandbox. Last_Activity_At time.Time // The timestamp of the last activity in the sandbox. State string // The current state of the sandbox (e.g., "running", "stopped"). Track SandboxTrack // The track associated with the sandbox. Invite TrackInvite // The invite details associated with the sandbox. User User // The user running the sandbox. }
Sandbox represents a sandbox environment within Instruqt, including details about its state, associated track, and invite.
type SandboxTrack ¶
type SandboxTrack struct { Id string // The unique identifier for the sandbox track. Slug string // The slug identifier for the sandbox track. Icon string // The icon associated with the sandbox track. Title string // The title of the sandbox track. Description string // The description of the sandbox track. Level string // The difficulty level of the sandbox track. Embed_Token string // The token used for embedding the sandbox track. CreatedAt time.Time // Timestamp of when track was created. DeletedAt time.Time // Timestamp of when track was deleted. Last_Update time.Time // Timestamp of when track has been last updated. Statistics struct { Average_review_score float32 // The average review score of the sandbox track. } TrackTags []TrackTag // A list of tags associated with the track. TrackReviews struct { TotalCount int Nodes []Review } `graphql:"-"` /* Not queried */ Challenges []Challenge `graphql:"-"` // A list of challenges associated with the sandbox track, not queried. Status string // The current status of the sandbox track. Started time.Time // The timestamp when the sandbox track was started. Completed time.Time // The timestamp when the sandbox track was completed. Participant struct { Id string } }
SandboxTrack represents a track in a sandbox environment, including its details and associated challenges.
type SandboxVar ¶
type SandboxVar struct { Key string // The key of the sandbox variable. Value string // The value of the sandbox variable. }
SandboxVar represents a key-value pair for a variable within a sandbox environment.
type Track ¶
type Track struct { Slug string // The slug identifier for the track. Id string // The unique identifier for the track. Icon string // The icon associated with the track. Title string // The title of the track. Description string // The description of the track. Level string // The difficulty level of the track. Embed_Token string // The token used for embedding the track. CreatedAt time.Time // Timestamp of when track was created. DeletedAt time.Time // Timestamp of when track was deleted. Last_Update time.Time // Timestamp of when track has been last updated. Statistics struct { Average_review_score float32 // The average review score of the track. } TrackTags []TrackTag // A list of tags associated with the track. TrackReviews struct { TotalCount int Nodes []Review } `graphql:"-"` // Not queried Challenges []Challenge `graphql:"-"` // A list of challenges associated with the sandbox track, not queried. }
Track represents the data structure for an Instruqt track.
type TrackInvite ¶
type TrackInvite struct { Id string // The unique identifier for the invite. PublicTitle string // The public title of the track invite. RuntimeParameters struct { EnvironmentVariables []variable // Environment variables used during the invite session. } Claims []TrackInviteClaim // A list of claims associated with the track invite. }
TrackInvite represents the data structure for an Instruqt track invite.
type TrackInviteClaim ¶
type TrackInviteClaim struct { Id string // The unique identifier of the claim. User struct { Id string // The unique identifier of the user. } ClaimedAt time.Time // The timestamp when the claim was made. }
TrackInviteClaim represents a claim made by a user for a specific track invite.
type TrackTag ¶
type TrackTag struct {
Value string // The value of the tag.
}
TrackTag represents a tag associated with an Instruqt track.
type User ¶
type User struct { Id string Details *UserDetails `graphql:"details(teamSlug: $teamSlug)"` Profile *UserProfile }
User represents the data structure for an Instruqt user.
type UserDetails ¶ added in v1.2.0
type UserDetails struct { FirstName graphql.String // The first name of the user. LastName graphql.String // The last name of the user. Email graphql.String // The email of the user. }
Detailed user information associated with a specific team.
type UserInfo ¶
type UserInfo struct { FirstName string // The first name of the user. LastName string // The last name of the user. Email string // The email of the user. }
UserInfo represents a simplified user information structure.
type UserProfile ¶ added in v1.2.0
type UserProfile struct { Display_Name graphql.String // The display name of the user. Email graphql.String // The email of the user. }
Profile-level information for the user.
type WebhookEvent ¶ added in v1.2.0
type WebhookEvent struct { Type string `json:"type"` // Type of the event (e.g., challenge.completed) TrackId string `json:"track_id"` // ID of the track related to the event TrackSlug string `json:"track_slug"` // Slug identifier for the track ParticipantId string `json:"participant_id"` // ID of the participant IsDeveloperPlay bool `json:"is_developer_play"` // Whether it is a developer or normal play Pooled bool `json:"pooled"` // Whether the track was pooled UserId string `json:"user_id"` // ID of the user who triggered the event InviteId string `json:"invite_id"` // ID of the invite associated with the event ClaimId string `json:"claim_id"` // Claim ID associated with the event Timestamp time.Time `json:"timestamp"` // Timestamp when the event occurred Reason string `json:"reason"` // Reason for the event, if applicable Duration int `json:"duration"` // Duration of the activity, if applicable CustomParameters map[string]string `json:"custom_parameters"` // Custom parameters for the sandbox // Challenges ChallengeId string `json:"challenge_id"` // ID of the challenge ChallengeIndex int `json:"challenge_index"` // Index of the challenge in the track TotalChallenges int `json:"total_challenges"` // Total number of challenges in the track // Review Content string `json:"content"` // Content of the review, if the event is related to a review ReviewId string `json:"review_id"` // ID of the review Score int `json:"score"` // Score given in the review }
WebhookEvent represents the structure of an incoming webhook event from Instruqt This includes details about the type of event, participant, and other metadata related to challenges, reviews, and custom parameters.
type WebhookHandler ¶ added in v1.2.0
type WebhookHandler func(w http.ResponseWriter, r *http.Request, webhook WebhookEvent) error
WebhookHandler is a handler function for processing webhooks It takes an HTTP response writer, an HTTP request, and a WebhookEvent structure and returns an error if the processing fails.