cnr-client v1.1.23
Codenrock gaming SDK
Installation
Run in console npm i --save cnr-client
or add the package
"cnr-client": "1.1.0"
in package.json file.
The stable version of the package is ^1.1.0
Init the game
Import the package
import CompetitionClient from 'cnr-client'
and create a game instance
The apiEndpoint
parameter is https://codenrock.com
by default, contestId
parameter will be given to you
by Codenrock.
Sign up with email
To register in the platform you have to use signUpWithEmail
method:
If there will be any errors during authorization, the SIGN_UP_FAILED
error will be thrown.
Sign in with email
To login in the platform you have to use signInWithEmail
method:
If there will be any errors during authorization, the SIGN_IN_FAILED
error will be thrown.
OAuth2
There are two properties in the game
instance: signInGoogleUrl
and signInFacebookUrl
.
To sign in using OAuth2, you have to redirect user to selected social.
<a :href="game.signInGoogleUrl">Sign in with Google</a>
or
<a :href="game.signInFacebookUrl">Sign in with Facebook</a>
After passing social authorization steps, you will be redirected on the main page of the game (window.location.origin
)
with token
parameter in query string.
Example:
You have to set this token to the game and clear query string.
Profile
Since user is authorized, you can always get its profile by user
property
If the user object is null
(for example, after OAuth2 authorization), you can ask it using the getProfile
method.
Init game
Starting the game, you have to make its initialization. Initialization process is required before getting any private data from the competition
Available methods
Method | Success | Error | Description |
---|---|---|---|
signUpWithEmail() | SignUpError | Sign up the system with email, returns validation errors if something wrong | |
signInWithEmail() | SignInError | Sign in the system with email, returns validation errors if something wrong | |
getProfile() | IUser | 403 | Get user profile |
getContest() | Contest | Get contest info | |
getForm() | IFormResponse | 403 | Get user form questions |
sendForm(data: IAnswerRequest) | IFormAnswerResponse | ValidationFailed | Answer the form |
getNominations() | Nomination[] | 403 | Get the list of the task categories |
getNomination(nominationId: number) | Nomination | 403 | Get category item by ID |
getRandomNomination() | Nomination | 403 | Get random category |
getTasks(nominationId: number) | Task[] | 403 | Get tasks from the category |
getRandomTask(nominationId: number) | Task | 403 | Get random task from the category |
getTask(nominationId: number, taskId: number) | Task | 403 | Get task from the category by ID |
answer(nominationId: number, taskId: number, data: any) | ISolutionResponse | 422 | Answer the task |
getLeaderboard(page: number = 1, search: string = "") | IRatingResponse | 403 | Get contest leaderboard (summary leaderboard) |
getMyGlobalScore() | IMyScoreResponse | 403 | Get the user score in contest |
getWheelTries() | IWheelSpins | 403 | only for wheel - get spins information |
setToken(token: string) | Set Auth token | ||
logout() | Logout the system |
Available properties
Property | Type | Description |
---|---|---|
signInGoogleUrl | string | The URL to sign in with Google |
signInFacebookUrl | string | The URL to sign in with Facebook |
authorized | boolean | Determines if the user is login |
user | User | Auth user instance |
Types
User
Contest
Form
IQuestion
AnswerRequest
Answer
Nomination
Task
SolutionResponse
Solution
IRatingResponse
IRatingPosition
IMyScoreResponse
IWheelSpins
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
8 months ago
8 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago