assembly-edu/assembly-client-php

1.2.368 2019-06-10 15:08 UTC

README

  • API version: 1.1.0
  • Package version: 1.2.368

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 variable are requied to be defined in your .env file.

ASSEMBLY_ENVIRONMENT=[sandbox / production]
ASSEMBLY_CLIENT_ID=[YOUR_CLIENT_ID]
ASSEMBLY_CLIENT_SECRET=[YOUR_CLIENT_SECRET]
<?php
require_once(__DIR__ . '/vendor/autoload.php');


$provider = new AssemblyAuth();

//GetTokenFromDatastore is a implementation placeholder which should be replace with your own data retrieval process.
$accessToken = new 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()->setAccessToken($accessToken->getToken());

$apiInstance = new Assembly\Client\Api\AssemblyApi(
  // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
  // This is optional, `GuzzleHttp\Client` will be used as default.
  new GuzzleHttp\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;
}

?>

Request School Authorization Token

There is more information available on our developer documentation site.

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

  $authorizationUrl = $provider->getAuthorizationUrl();

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

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

?>

Handling 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())
?>

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 findMedicalCondition GET /school/medical_conditions/{id} View a Medical Condition
AssemblyApi findRegistrationGroup GET /registration_groups/{id} View a Registration Group
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 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 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 getGroups GET /groups List Groups
AssemblyApi getLeftStaffMembers GET /staff_members/left List Left Staff Members
AssemblyApi getLeftStudents GET /students/left List Left Students
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 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 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