diff --git a/modules/api.php b/modules/api.php new file mode 100644 index 0000000..ad9fe9e --- /dev/null +++ b/modules/api.php @@ -0,0 +1,19 @@ +uid) + { + $api_key = $this->redis->hget('user:' . $this->uid, 'api'); + } + + return array('api_key' => $api_key); + } +} + +?> diff --git a/modules/user/create.php b/modules/user/create.php index 99ad2f9..4d168f6 100644 --- a/modules/user/create.php +++ b/modules/user/create.php @@ -50,14 +50,6 @@ class user_create extends AnonymousModule // Generates the auth token $auth_token = sha1(microtime()); - // Writes the user data - $this->redis->hmset('user:' . $uid, array( - 'username' => $_POST['username'], - 'email' => $_POST['email'], - 'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'), - 'auth' => $auth_token, - )); - // Creates an API key for the user $api_key = false; @@ -73,6 +65,15 @@ class user_create extends AnonymousModule } } + // Writes the user data + $this->redis->hmset('user:' . $uid, array( + 'username' => $_POST['username'], + 'email' => $_POST['email'], + 'password' => crypt($_POST['password'], '$2y$11$' . String::random(22) . '$'), + 'auth' => $auth_token, + 'api' => $api_key, + )); + $mapping_fields[] = 'user:api:' . $api_key; // Sets the UID mappings diff --git a/templates/__shared/index.phtml b/templates/__shared/index.phtml index fd268d7..98946fe 100644 --- a/templates/__shared/index.phtml +++ b/templates/__shared/index.phtml @@ -57,7 +57,7 @@ { $links = array( '/' => 'Home', - '/about' => 'About', + '/api' => 'API Documentation', '/contact' => 'Contact Us', '/login' => 'Sign In', '/join' => 'Sign Up', diff --git a/templates/api.phtml b/templates/api.phtml index e69de29..d9579e5 100644 --- a/templates/api.phtml +++ b/templates/api.phtml @@ -0,0 +1,75 @@ +config->site['name']; +$url = 'http://' . $this->config->site['domain'] . '/api/'; +?> + +
The API is designed to allow you the easily interact with the leaderboards in your account. We provide all the tools required to push member data to your leaderboards and pull back your members scores and ranks.
+ +module['api_key']) +{ + ?> ++ Before we get started, here’s your API key: + module['api_key']; ?> +
+ + +All API calls start with {version} where {version} corresponds to the version of the API you would like to use.
+ +The current version of the API is v1.0
+ + + +You cannot reach the API without including an API key in your request. For the sake of consistency, the API key must be transmitted as part of the query string of URL regardless of the HTTP method being used with the call:
+ +{endpoint}?key={key} where {endpoint} is the call being made and {key} is your API key.
+ + +Returns a list of all of the leaderboards associated with the account. The API equivalent of the My Leaderboards page.
+ +Returns the members, scores and ranks sorted in descending order by score.
+ +{uid} corresponds with the UID found on the My Leaderboards page.
+ +The value of {member} is a unique indicator you are using in your system. It can be anything you want it to be as long as it’s unique within your system.
+ +We highly recommend using something that won’t change in the future like an auto incremented field from your database.
+ +Returns the score and rank for the {member} specified.
+ +The POST method allows you set the score of the {member} by passing the {score} parameter.
+ +The score must be an integer.
+ +The PUT method allows you to increment the score of the specified {member} by 1 point. If the {member} does not exist, the score will be be set to 1 point. If you would like to increase by more than one, or decrement the score, include the value parameter.
+ +The optional value must be an integer.