assembly-edu/assembly-client-php

1.2.424 2019-09-05 13:29 UTC

README

  • API version: 1.1.0
  • Package version: 1.2.424

For more information, please visit http://developers.assembly.education

Requirements

PHP 5.5 and later

Installation & Usage

Composer

To install the bindings via Composer:

Run composer require assembly-edu/assembly-client-php

Manual Installation

Download the files and include autoload.php:

  require_once('/path/to//vendor/autoload.php');

Tests

To run the unit tests:

composer install
./vendor/bin/phpunit

Getting Started

Please follow the installation procedure and then run the following:

The following variables can to be defined in your .env file.

ASSEMBLY_ENVIRONMENT=[sandbox / production]
ASSEMBLY_CLIENT_ID=[YOUR_CLIENT_ID]
ASSEMBLY_CLIENT_SECRET=[YOUR_CLIENT_SECRET]

or passed to the AssemblyAuth constructor as parameters

[
  'clientId' => [YOUR_CLIENT_ID],
  'clientSecret' => [YOUR_CLIENT_SECRET],
  'environment' => [sandbox / production]
]

Request School Authorization

There is more information available on our developer documentation site. Note: The redirectUri must match the uri defined in the application settings on the Assmebly Platform.

<?php
  $provider = new \Assembly\Client\Auth\AssemblyAuth([
    'redirectUri' => 'http://example.com/your-redirect-url/',
]);

  $state = ''; // Set a state value that will be link to s chool in your data store.
  $authorizationUrl = $provider->getAuthorizationUrl([
  'scope'      => ['school:required'], // Add additional scopes are required
	'state' => $state
  ]);

  //SaveSateToDataStore is a implementation placeholder which should be replace with your own data storage process.
  SaveSateToDataStore($state);

  // Redirect the user to the authorization URL.
  header('Location: ' . $authorizationUrl);
?>

Handle School Authorization Callback

<?php

  $provider = new \Assembly\Client\Auth\AssemblyAuth([
    'redirectUri' => 'http://example.com/your-redirect-url/',
  ]);

  //GetStateFromDataStore is a implementation placeholder which should be replace with your own data retrieval process.
  $state = GetStateFromDataStore();

  if (empty($_GET['state']) || (empty($state) && $_GET['state'] !== $state)) {
    exit('Invalid state');
  }

  // Try to get an access token using the authorization code grant.
  $accessToken = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code']
  ]);

  // We have an access token, which we may use in authenticated requests against the service provider's API.
  echo 'Access Token: ' . $accessToken->getToken() . "<br>";
  echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
  echo 'Expired in: ' . $accessToken->getExpires() . "<br>";
  echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";

  //SaveTokenToDatastore is a implementation placeholder which should be replace with your own data storage process.
  SaveTokenToDatastore($accessToken->jsonSerialize());

  $accessToken->jsonSerialize() will return the following
  /*
    {
      "access_token": "ABCDE",
      "refresh_token": "WXYZ",
      "token_type": "bearer",
      "level": "school",
      "expires_in": 108000,
      "school_id": 123,
      "scopes": ["school", "students"]
    }
  */
?>

Request School Data

<?php
require_once(__DIR__ . '/vendor/autoload.php');


$provider = new \Assembly\Client\Auth\AssemblyAuth();

//GetTokenFromDatastore is a implementation placeholder which should be replace with your own data retrieval process.
$accessToken = new \League\OAuth2\Client\Token\AccessToken(GetTokenFromDatastore());

if ($accessToken->hasExpired()) {
  $accessToken = $provider->getAccessToken('refresh_token', ['refresh_token' => $accessToken->getRefreshToken()]);

  //SaveTokenToDatastore is a implementation placeholder which should be replace with your own data storage process.
  SaveTokenToDatastore($accessToken->jsonSerialize())
}

// Configure OAuth2 access token for authorization: SchoolToken
$config = Assembly\Client\Configuration::getDefaultConfiguration($provider);
// $config = $config->setDebug(true);
// $config = $config->setDebugFile('LOCATION_OF_FILE');
$config->setAccessToken($accessToken->getToken());

$handler = new \GuzzleHttp\Handler\StreamHandler();
$client = new \GuzzleHttp\Client(['handler' => $handler]);

$apiInstance = new Assembly\Client\Api\AssemblyApi(
  $client,
  $config
);

try {
  $bulk_results_body = new \Assembly\Client\Model\BulkResultsBody(); // \Assembly\Client\Model\BulkResultsBody | 

  $result = $apiInstance->bulkUpdateResults($bulk_results_body);
  print_r($result);
} catch (Exception $e) {
  echo 'Exception when calling AssemblyApi->bulkUpdateResults: ', $e->getMessage(), PHP_EOL;
}

?>

Documentation for API Endpoints

All URIs are relative to https://api-sandbox.assembly.education

Class Method HTTP request Description
AssemblyApi bulkUpdateResults PATCH /results Update Multiple Results
AssemblyApi createResult POST /results Write Results
AssemblyApi findAcademicYear GET /academic_years/{id} View an Academic Year
AssemblyApi findAssessment GET /assessments/{id} View an Assessment
AssemblyApi findAssessmentGradeSet GET /assessments/{id}/grade_set View Grade Set for an Assessment
AssemblyApi findAssessmentPoint GET /assessment_points/{assessment_point_rank} View an Assessment Point
AssemblyApi findDietaryNeed GET /school/dietary_needs/{id} View a Dietary Need
AssemblyApi findFacet GET /facets/{id} View a Facet
AssemblyApi findGradeSet GET /grade_sets/{id} View a Grade Set
AssemblyApi findGroup GET /groups/{id} View a Group
AssemblyApi findLearningAim GET /school/learning_aims/{id} View a Post-16 Learning Aim
AssemblyApi findMedicalCondition GET /school/medical_conditions/{id} View a Medical Condition
AssemblyApi findRegistrationGroup GET /registration_groups/{id} View a Registration Group
AssemblyApi findRoom GET /rooms/{id} View a Room
AssemblyApi findSchool GET /school View School Details
AssemblyApi findStaffMember GET /staff_members/{id} View a Staff Member
AssemblyApi findStudent GET /students/{id} View a Student
AssemblyApi findTeachingGroup GET /teaching_groups/{id} View a Teaching Group
AssemblyApi findTimetable GET /timetables/{id} View a Timetable
AssemblyApi findYearGroup GET /year_groups/{id} View a Year Group
AssemblyApi getAcademicYears GET /academic_years List Academic Years
AssemblyApi getAssessmentPointResults GET /assessment_points/{assessment_point_rank}/results View Results for an Assessment Point
AssemblyApi getAssessmentPoints GET /assessment_points List Assessment Points
AssemblyApi getAssessmentResults GET /assessments/{id}/results View Results for an Assessment
AssemblyApi getAssessments GET /assessments List Assessments
AssemblyApi getAttendanceSummaries GET /attendances/summaries List Attendance Summaries
AssemblyApi getAttendances GET /attendances List Attendances
AssemblyApi getCalendarEvents GET /calendar_events List Calendar Events
AssemblyApi getClosures GET /rooms/{id}/closures List Closures For a Room
AssemblyApi getContacts GET /contacts List Contacts
AssemblyApi getDietaryNeeds GET /school/dietary_needs List Dietary Needs
AssemblyApi getExclusions GET /exclusions List Exclusions
AssemblyApi getFacets GET /facets List Facets
AssemblyApi getGradeSets GET /grade_sets List Grade Sets
AssemblyApi getGroupStudents GET /groups/{id}/students List Students for Group
AssemblyApi getGroups GET /groups List Groups
AssemblyApi getLearningAims GET /school/learning_aims List Post-16 Learning Aims
AssemblyApi getLeftStaffMembers GET /staff_members/left List Left Staff Members
AssemblyApi getLeftStudents GET /students/left List Left Students
AssemblyApi getLessons GET /rooms/{id}/lessons List Lessons For a Room
AssemblyApi getMedicalConditions GET /school/medical_conditions List Medical Conditions
AssemblyApi getRegistrationGroupStudents GET /registration_groups/{id}/students List Students for Registration Group
AssemblyApi getRegistrationGroups GET /registration_groups List Registration Groups
AssemblyApi getResults GET /results List Results
AssemblyApi getRooms GET /rooms List Rooms
AssemblyApi getStaffAbsences GET /staff_absences List Staff Absences
AssemblyApi getStaffContracts GET /staff_contracts List Staff Contracts
AssemblyApi getStaffMembers GET /staff_members List Staff Members
AssemblyApi getStudents GET /students List Students
AssemblyApi getSubjects GET /subjects List Subjects
AssemblyApi getTeachingGroupStudents GET /teaching_groups/{id}/students List Students for Teaching Group
AssemblyApi getTeachingGroups GET /teaching_groups List Teaching Groups
AssemblyApi getTimetables GET /timetables List Timetables
AssemblyApi getYearGroupStudents GET /year_groups/{id}/students List Students for Year Group
AssemblyApi getYearGroups GET /year_groups List Year Groups
AssemblyApi status GET /school/status View School Sync Status
AssemblyApi updateResults PATCH /results/{id} Update a Single Result

Documentation For Models

Author

help@assembly.education