Giter Club home page Giter Club logo

codecombat-api's Introduction

codecombat-api

PHP package for CodeCombat REST API

codecombat-api is a package for the CodeCombat REST API. It provides an abstracted interface to talk with the CodeCombat API. The Package contains a Laravel ServiceProvider to inject it into the Laravel Service Container, but other than that the package is framework-agnostic. Please look at the CodeCombat API Documentation for more details and do not be afraid to peruse the source code on this package.

Installation

composer require timutech/codecombat-api

Configuration

You will preferably need to have your own OAuth2 server. You will need to have a lookup URL where CodeCombat can query an AccessToken you give them and then you will return the User on your system linked to that AccessToken. eg https://yoursite.com/api/auth/{token} which returns a User with a required id field.

Normal

Make sure you keep your CodeCombat OAuth {CLIENT_ID}, {CLIENT_SECRET} and {OAUTH_PROVIDER_ID} in whatever config you have as you will need it to instantiate an instance.

Laravel

Add the line TimuTech\CodeCombat\CodeCombatserviceProvider::class, like below in your config/app.php file.

'providers' => [
	// Other

	TimuTech\CodeCombat\CodeCombatServiceProvider::class,
],

Add your CodeCombat OAuth credentials to your config/services.php file, as below.

// Other services

'codecombat' => [
    'id' => '{CLIENT_ID}',
    'secret' => '{CLIENT_SECRET}',
    'provider_id' => '{OAUTH_PROVIDER_ID}'
]

Usage

Refer to the source code for other functionality or create a pull request for addition of functionality. I will endeavour to keep adding features whenever I can.

Normal

Instantiate

$codecombat = new CodeCombat(
	{CLIENT_ID},
	{CLIENT_SECRET},
	{OAUTH_PROVIDER_ID});

Create a new user

$user = {A user from your system}
$combatUser = $codecombat->register([
    'name' => $user->name, // UNIQUE Nick Name
    'email' => $user->email, // NEW Email,
    'role' => 'student' //or 'teacher'
]);

Assign an OAuth Identity

$token = {YOUR OAuth2 token, generated for your user from your server}
$codecombat->setAuth($token)->createIdentity($combatUser);

Retrieve the user later

$handle = {UNIQUE Nick Name assigned earlier or the CodeCombat ID of the user, if you have it}
$combatUser = $codecombat->getUser($handle);

Get the url to redirect to CodeCombat

$token = {YOUR OAuth2 token, generated for your user from your server}
$url = $codecombat->setAuth($token)->redirect();

The TimuTech\CodeCombat\Resources\CombatUser class has some helpful methods and attributes, to name a few:

$combatUser->getEmail();
$combatUser->getId();
$combatUser->getProfile();

Once again, the source code is your friend.

codecombat-api's People

Contributors

xanmanza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.