Giter Club home page Giter Club logo

rgp-api's Introduction

Rock Gym Pro API

Rock Gym Pro has released a basic API as of December 2019. This PHP class aims to make it easy to access all available endpoints that have been provided. RGP has made it clear that future development will be dependent on community interest and usage, so get coding! If there is some functionality you'd like to see added to the API, let RGP support know, as this will help guide development.

API Documentation

You can view RGP's documentation of their API here: https://api.rockgympro.com

API Keys

You will need to generate an API key before being able to access the API. This Google Doc from RGP has instructions on how to generate your key for both cloud and locally hosted servers.

Version 1.0.0 of This Library

The scope of this library has been reduced to provide just the basic wrapper and some small tweaks on the response structure. Previously, there were separate methods for each endpoint of the API. There were multiple changes in the API that each broke the library, so endpoint specific methods were removed in favor of a more generlized approach using the new get() method.

Installation

There are two ways to use this library. You can install it as a dependency with Composer, or you can download RGP.php from this repository and include it in your code.

Composer

composer require reganface/rgp

Include composer's autoload file at the top of your project to load all of your dependencies.

require __DIR__ . '/vendor/autoload.php';

Download

Save RGP.php to your project folder and include it in your project.

require "/path/to/RGP.php";

cURL

This class requires curl to be installed and enabled on the version of PHP that you are using. PHP will throw errors if curl is not accessible.

Basic Usage

When instantiating the class, you just need to include your api username and api key. Exceptions will be thrown on any errors, so make sure to keep code inside a try/catch block.

$api_username = "apiname";	// add your api username here
$api_key = "apikey";		// add your api key here

try {
	$rgp = new reganface\RGP\RGP($api_username, $api_key);

	// do stuff

} catch (Exception $e) {
	// handle errors
}

The structure of the data returned by get() will differ slightly from what RGP returns if you were to access the API directly. This is done to keep the meta data of the response separate from the data you requested. The structure looks like this:

[
	"data"  => [],			// The requested data
	"response"  => [],		// response information
	"pages"  => []			// pagination information (if applicable)
]

If you would prefer to have the data exactly as the API returns, you can use get_raw() instead.

Example

// Get some data. In this case, a list of all your facilities.
$result = $rgp->get("/facilities");

// The data will always be found in the "data" key.
$facilities  =  $result["data"];

// Output a list of each facility's three character code and the facility name.
if (!empty($facilities)) {
	foreach($facilities as $facility) {
		echo  "{$facility["code"]} - {$facility["name"]}\n";
	}
}

Methods

get()

get (string $path [, array $params])

Returns data from the API with a slightly altered data structure as seen below:

[
	"data" => array,			// this is the data you are looking for
	"response" => array,		// meta data about the response
	"pages" => [				// this will be here for any endpoints that return paginated data
		"itemTotal" => int,		// total number of results
		"itemPage" => int,		// number of results per page
		"pageTotal" => int,		// total number of pages
		"pageCurrent" => int	// the current page that was just returned
	]
]

path
This is the path of the API endpoint. The list of all current endpoints is available at https://api.rockgympro.com. Note: do not include "/v1" in the path.

params
An associative array of any query paramaters you want to include with the call.


get_raw()

get_raw (string $path [, array $params])

This method is identical to get() except that it will return the data exactly how the API returns it.


test()

test ()

Tests the connection to the API. Returns true if a connections can be made successfully.

rgp-api's People

Contributors

reganface avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.