Download the PHP package sowiso/php-api-sdk without Composer

On this page you can find all versions of the php package sowiso/php-api-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-api-sdk

SOWISO API SDK for PHP

This PHP library contains the SDK to access the SOWISO API. It's not supposed to be used publicly.

Installation

Usage

The SDK is composed of some features that are explained in this section. The general usage can be seen in this (basic and not-working) example:

The SDK must be instantiated with a configuration, and can then be used to request the API.

Configuration

The SOWISO API requires these configuration settings:

PSR-17 and PSR-18

The SDK allows to specify to use your own HTTP Client (PSR-18) and your own HTTP Message Factories (PSR-17). If not provided, the SDK used this package to automatically discover applicable packages in your project.

Context

The context can be used to pass arbitrary data from the request into the callback and hook methods. Additionally, the context holds some data that is required by some endpoints:

Payload

The SDK supports passing additional payload from every request into the callbacks and hooks. This additional payload can be specified by a __additionalPayload field in the request JSON. When no or an empty field is provided, the SowisoApiPayload#getData() method returns null.

Exceptions

Note: It's not recommended catching every exception like it's done in the example.

Endpoints

The SDK is designed in a way that it takes JSON data as input and returns the API's response in that same format. The input JSON is required to be a JSON object that contains the endpoint name in a top-level field called __endpoint. That field determines the actual SOWISO API endpoint to call. All data in that JSON object is passed to the API endpoint, except all fields starting with __. The response can either be a JSON object or a JSON array.

The following example shows the basic use of the SDK and how to specify the API endpoint.

At the moment, the following endpoints are available in the SDK:

PlayExerciseSet

When the requested view is set to readonly, no "Try IDs" are returned for the exercises in that set. Hence, the corresponding hooks that handle "Try IDs" are not called.

_When a request contains a try_id instead of a set_id, the API continues the exercise set that belongs to that try_id. Providing both fields is not allowed and results in an InvalidDataException._

PlayExercise

This endpoint only supports getting an exercise for a "Try ID", for now. Requesting an exercise for an "Exercise ID" might be supported in a later version of the SDK.

ReplayExerciseTry

EvaluateAnswer

PlayHint

PlaySolution

StoreAnswer

Callbacks

The SDK allows specifying callback implementations for each endpoint. Every callback provides four methods to (optionally) implement:

When multiple callbacks for the same endpoint are used, they are executed in the order they were specified.

PlayExerciseSet

PlayExercise

ReplayExerciseTry

EvaluateAnswer

PlayHint

PlaySolution

StoreAnswer

RequestHandlers

The SDK allows specifying request handlers for each endpoint. Every request handler provides a handle method to (optionally) implement. Its data contains the request data and possibly the context data. When the handle method returns any array, the request is not passed to the API. If the handle method does return null, the request is passed to the API. The SDK still runs all callback methods for the endpoint.

When multiple request handlers for the same endpoint are used, only the latest is being used to handle the request.

PlayExerciseSet

PlayExercise

ReplayExerciseTry

EvaluateAnswer

PlayHint

PlaySolution

StoreAnswer

Hooks

The SDK provides so-called hooks, which hook into one or more callbacks. They are used for providing some SOWISO-specific functionality.

DataVerification

The DataVerificationHook simplifies the verification of data in requests before they are passed to the API. The main use cases for this hook is making sure that any request data tampering that might happen between the SOWISO Player and the SDK gets detected and blocked, before it's passed to the API.

The data verification can be done on a per-endpoint level. For example, all requests that are going to the "play/set" endpoint will be passed through the verifyPlayExerciseSetRequest() method before being sent to the API. Whenever the verification of data failed, the implementation can throw a SowisoApiException.DataVerificationFailed exception (or any other exception) which aborts the request stack (i.e., the request is not passed to the API) and exists the SowisoApi#request() method.

Along with the parsed, endpoint-specific request data, all request data objects contain the following properties:

Migrating from the TryIdVerification hook to the DataVerification hook

The new DataVerificationHook simplifies the whole verification process by a lot; however, it required a bit more logic in the hook's implementation.

First of all, we have removed the onRegisterTryId() method from the TryIdVerificationHook since it overlapped with the DataCaptureHook::onRegisterExerciseSet(). When you haven't used this method in the DataCaptureHook to register new exercise tries, please do this.

Secondly, we have removed the onCatchInvalidTryId() method. This was an additional and optional helper method that could be implemented for the cases when an invalid "Try ID" was caught. The same behavior could also be achieved by catching the InvalidTryIdException exception (which will be removed as well) and will be available by catching the DataVerificationFailedException exception instead.

And lastly, the isValidTryId() method. This was called on every request that contained a "Try ID". With the new DataVerificationHook, there will be new validate...Request() methods available for every endpoint where you can validate the given "Try ID".

The following example shows an implementation of the DataVerificationHook where the private verifyTryId() method resembles the old isValidTryId() method (an DataVerificationFailedException exception should be thrown instead of returning false). As you can see, only the "play/set" endpoint needs some special attention at the moment since that endpoint allows requesting a "Try ID" and a "Set ID" (but not at the same time). Additionally, this example shows where to verify other request data parameters.

DataCapture

The DataCapture hook simplifies receiving common, processed data. It can be extended in the future to provide other common data.

The OnRegisterExerciseSetData object contains the following properties:

ScoreCapture

The ScoreCapture hook wraps all endpoints that return some form of score for a user. The OnScoreData object contains the following properties:

TestMode

The TestMode hook simplifies everything related to playing and evaluating in "test" mode. By implementing and using this hook, you can decide if a certain "Exercise Set" or "Exercise Try" should use the "test" mode.

Note: When an "Exercise Set" was played in "test" mode, the returned "Exercise Tries" should also be evaluated in "test" mode.

All data objects contain the following properties:


All versions of php-api-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
php-http/discovery Version ^1.18
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sowiso/php-api-sdk contains the following files

Loading the files please wait ....