Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

Represent the url for each method and the encoding of the parameters and response.

Author: Yuliya Bozhko <yuliya.bozhko@totaralms.com>
Copyright: 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 404 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

backpack_api_mapping:: (12 methods):
  __construct()
  get_token_key()
  set_authentication_error()
  get_authentication_error()
  is_match()
  get_url()
  get_post_params()
  convert_email_response()
  get_auth_user_id()
  oauth_token_response()
  get_curl_options()
  request()


Class: backpack_api_mapping  - X-Ref

Represent a single method for the remote api.

__construct($action, $url, $postparams, $requestexporter, $responseexporter,$multiple, $method, $json, $authrequired, $isuserbackpack, $backpackapiversion)   X-Ref
Create a mapping.

param: string $action The action of this method.
param: string $url The base url of this backpack.
param: mixed $postparams List of parameters for this method.
param: string $requestexporter Name of a class to export parameters for this method.
param: string $responseexporter Name of a class to export response for this method.
param: boolean $multiple This method returns an array of responses.
param: string $method get or post methods.
param: boolean $json json decode the response.
param: boolean $authrequired Authentication is required for this request.
param: boolean $isuserbackpack user backpack or a site backpack.
param: integer $backpackapiversion OpenBadges version 1 or 2.

get_token_key($type)   X-Ref
Get the unique key for the token.

param: string $type The type of token.
return: string

set_authentication_error($msg)   X-Ref
Remember the error message in a static variable.

param: string $msg The message.

get_authentication_error()   X-Ref
Get the last authentication error in this request.

return: string

is_match($action)   X-Ref
Does the action match this mapping?

param: string $action The action.
return: boolean

get_url($apiurl, $param1, $param2)   X-Ref
Parse the method url and insert parameters.

param: string $apiurl The raw apiurl.
param: string $param1 The first parameter.
param: string $param2 The second parameter.
return: string

get_post_params($email, $password, $param)   X-Ref
Parse the post parameters and insert replacements.

param: string $email The api username.
param: string $password The api password.
param: string $param The parameter.
return: mixed

convert_email_response($response, $backpackid)   X-Ref
Read the response from a V1 user request and save the userID.

param: string $response The request response.
param: integer $backpackid The backpack id.
return: mixed

get_auth_user_id()   X-Ref
Get the user id from a previous user request.

return: integer

oauth_token_response($response, $backpackid)   X-Ref
Parse the response from an openbadges 2 login.

param: string $response The request response data.
param: integer $backpackid The id of the backpack.
return: mixed

get_curl_options()   X-Ref
Standard options used for all curl requests.

return: array

request($apiurl, $urlparam1, $urlparam2, $email, $password, $postparam, $backpackid)   X-Ref
Make an api request and parse the response.

param: string $apiurl Raw request url.
param: string $urlparam1 Parameter for the request.
param: string $urlparam2 Parameter for the request.
param: string $email User email for authentication.
param: string $password for authentication.
param: mixed $postparam Raw data for the post body.
param: string $backpackid the id of the backpack to use.
return: mixed