Giter Site home page Giter Site logo

vitalsource_api_class's Introduction

VitalSource API Class

A class I made to interact with the VitalSource API: https://developer.vitalsource.com/hc/en-us/categories/360001974433

It currently only makes 3 calls: Create Code, Check Code Status, and Cancel/Refund Code.

I did not include any API actions made on behalf of a specific user, as they were not necessary for my use-case -- they would require additional interaction to request an access token on behalf of the user, using their username and password.

Include and Construct API Class

// include api class
include_once('vitalsource_api.php');

// setup vars for creds
$api_key = "XXXXXXXXXXXXXXXX";

// construct a new vitalsource_api object with the API key
$vitalsource_api = new vitalsource_api($api_key);

Create Redemption Code

// set test sku
$test_sku = 'VCS-0074009900852';

// create a redemption code for the test sku
$vitalsource_api->createCode($test_sku);
// check for a response before continuing
if(!$vitalsource_api->getResponse()) {
  // no valid response found; check for errors
  var_dump($vitalsource_api->getErrors());
}
// pull the response (code status or error) off the api object
$response = $vitalsource_api->getResponse();
$code = $response['code'];

Check Status of Redemption Code

// get the status of the code we just created in above creation example ($code)
$vitalsource_api->checkCode($code);
// check for a response before continuing
if(!$vitalsource_api->getResponse()) {
  // no valid response found; check for errors
  var_dump($vitalsource_api->getErrors());
}
// pull the response (code status or error) off the api object
$response = $vitalsource_api->getResponse();

Cancel/Refund Redemption Code

// cancel/refund the code we just created in above creation example ($code)
$vitalsource_api->cancelCode($code);
// check for a response before continuing
if(!$vitalsource_api->getResponse()) {
  // no valid response found; check for errors
  var_dump($vitalsource_api->getErrors());
}
// pull the response (code status or error) off the api object
$response = $vitalsource_api->getResponse();

vitalsource_api_class's People

Contributors

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