assembly-edu/assembly-client-php

该软件包的规范存储库似乎已消失,因此软件包已被冻结。

1.2.477 2022-09-01 15:57 UTC

README

  • API版本:1.1.0
  • 软件包版本:1.2.477

更多信息,请访问 http://developers.assembly.education

需求

PHP 5.5 及以上版本

安装 & 使用

Composer

通过 Composer 安装绑定

运行 composer require assembly-edu/assembly-client-php

手动安装

下载文件并包含 autoload.php

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

测试

运行单元测试

composer install
./vendor/bin/phpunit

入门指南

请按照 安装过程 进行,然后运行以下操作

以下变量可以在您的 .env 文件中定义。

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

或作为参数传递给 AssemblyAuth 构造函数

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

请求学校授权

有关更多信息,请访问我们的 开发者文档 网站。 注意: redirectUri 必须与 Assembly 平台上应用程序设置中定义的 uri 匹配。

<?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);
?>

处理学校授权回调

<?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"]
    }
  */
?>

请求学校数据

<?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;
}

?>

API端点文档

所有 URI 都是相对于 https://api-sandbox.assembly.education

方法 HTTP 请求 描述
AssemblyApi bulkUpdateResults PATCH /results 更新多个结果
AssemblyApi createResult POST /results 写入结果
AssemblyApi deauthorize POST /school/deauthorize 取消授权学校
AssemblyApi findAcademicYear GET /academic_years/{id} 查看学年
AssemblyApi findAssessment GET /assessments/{id} 查看评估
AssemblyApi findAssessmentGradeSet GET /assessments/{id}/grade_set 查看评估的评分集
AssemblyApi findAssessmentPoint GET /assessment_points/{assessment_point_rank} 查看评估点
AssemblyApi findDietaryNeed GET /school/dietary_needs/{id} 查看饮食需求
AssemblyApi findFacet GET /facets/{id} 查看方面
AssemblyApi findGradeSet GET /grade_sets/{id} 查看成绩组
AssemblyApi findGroup GET /groups/{id} 查看组
AssemblyApi findLearningAim GET /school/learning_aims/{id} 查看16岁以上学习目标
AssemblyApi findMedicalCondition GET /school/medical_conditions/{id} 查看医疗状况
AssemblyApi findRegistrationGroup GET /registration_groups/{id} 查看登记组
AssemblyApi findRoom GET /rooms/{id} 查看房间
AssemblyApi findSchool GET /school 查看学校详情
AssemblyApi findStaffMember GET /staff_members/{id} 查看员工
AssemblyApi findStudent GET /students/{id} 查看学生
AssemblyApi findTeachingGroup GET /teaching_groups/{id} 查看教学组
AssemblyApi findTimetable GET /timetables/{id} 查看时间表
AssemblyApi findYearGroup GET /year_groups/{id} 查看年级组
AssemblyApi getAcademicYears GET /academic_years 列出学术年份
AssemblyApi getAssessmentPointResults GET /assessment_points/{assessment_point_rank}/results 查看评估点的结果
AssemblyApi getAssessmentPoints GET /assessment_points 列出评估点
AssemblyApi getAssessmentResults GET /assessments/{id}/results 查看评估结果
AssemblyApi getAssessments GET /assessments 列出评估
AssemblyApi getAttendanceSummaries GET /attendances/summaries 列出出勤摘要
AssemblyApi getAttendances GET /attendances 列出出勤
AssemblyApi getCalendarEvents GET /calendar_events 列出日历事件
AssemblyApi getClosures GET /rooms/{id}/closures 列出房间的关闭情况
AssemblyApi getContacts GET /contacts 列出联系人
AssemblyApi getDietaryNeeds GET /school/dietary_needs 列出饮食需求
AssemblyApi getExclusions GET /exclusions 列出排除项
AssemblyApi getFacets GET /facets 列出特性
AssemblyApi getGradeSets GET /grade_sets 列出成绩组
AssemblyApi getGroupEnrolments GET /groups/enrolments 列出组报名
AssemblyApi getGroupStudents GET /groups/{id}/students 列出组的学生
AssemblyApi getGroups GET /groups 列出组
AssemblyApi getLearningAims GET /school/learning_aims 列出16岁以上学习目标
AssemblyApi getLeftStaffMembers GET /staff_members/left 列出离职员工
AssemblyApi getLeftStudents GET /students/left 列出离职学生
AssemblyApi getLessons GET /rooms/{id}/lessons 列出房间的课程
AssemblyApi getMedicalConditions GET /school/medical_conditions 列出医疗状况
AssemblyApi getMisSubjects GET /mis_subjects 列出MIS科目
AssemblyApi getRegistrationGroupStudents GET /registration_groups/{id}/students 列出登记组的学生
AssemblyApi getRegistrationGroups GET /registration_groups 列出登记组
AssemblyApi getResults GET /results 列出结果
AssemblyApi getRooms GET /rooms 列出房间
AssemblyApi getStaffAbsences GET /staff_absences 列出员工缺席
AssemblyApi getStaffContracts GET /staff_contracts 列出员工合同
AssemblyApi getStaffMembers GET /staff_members 列出员工
AssemblyApi getStudents GET /students 列出学生
AssemblyApi getSubjects GET /subjects 列出科目
AssemblyApi getTeachingGroupStudents GET /teaching_groups/{id}/students 列出教学组的学生
AssemblyApi getTeachingGroups GET /teaching_groups 列出教学组
AssemblyApi getTimetables GET /timetables 列出时间表
AssemblyApi getYearGroupStudents GET /year_groups/{id}/students 列出年级组的学生
AssemblyApi getYearGroups GET /year_groups 列出年级组
AssemblyApi status GET /school/status 查看学校同步状态
AssemblyApi 同步 POST /school/sync 请求学校同步
AssemblyApi updateResults PATCH /results/{id} 更新单个结果

模型文档

作者

help@assembly.education