Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439 Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2.0 KiB
2.0 KiB
Building an xAPI Client
The xAPI client library ships with a builder class which eases the process of
creating an instance of an XApiClient class:
use Xabbuh\XApi\Client\XApiClientBuilder;
$builder = new XApiClientBuilder();
$xApiClient = $builder->setBaseUrl('http://example.com/lrs/api')
->setVersion('1.0.0')
->build();
The builder creates a client for the 1.0.1 API version if you don't set a version.
HTTP Basic Authentication
Use the setAuth() method if access to the LRS resources is protected with
HTTP Basic authentication:
use Xabbuh\XApi\Client\XApiClientBuilder;
$builder = new XApiClientBuilder();
$xApiClient = $builder->setBaseUrl('http://example.com/lrs/api')
->setAuth('username', 'password')
->build();
OAuth1 Authentication
Using the setOAuthCredentials() method, you can configure the client to
access OAuth1 protected resources:
use Xabbuh\XApi\Client\XApiClientBuilder;
$builder = new XApiClientBuilder();
$xApiClient = $builder->setBaseUrl('http://example.com/lrs/api')
->setOAuthCredentials('consumer-key', 'consumer-secret', 'token', 'token-secret')
->build();
Using the APIs
The Experience API consists of four sub APIs: the statements API, the state API,
the activity profile API and the agent profile API. A client for each of these
APIs can be obtained from the global XApiClient instance:
$statementsApiClient = $xApiClient->getStatementsApiClient();
$stateApiClient = $xApiClient->getStateApiClient();
$activityProfileApiClient = $xApiClient->getActivityProfileApiClient();
$agentProfileApiClient = $xApiClient->getAgentProfileApiClient();
Read the dedicated chapters of the sub APIs to learn how to make use of them: