Make the http request to the Mock Service to register the interaction.

@param ProviderResponse $response mock of response received

@return bool returns true on success
969557
public function willRespondWith(ProviderResponse $response): bool
    {
        $this->interaction->setResponse($response);

        return $this->mockServerHttpService->registerInteraction($this->interaction);
    }
112698
protected function verifyResponse(Response $response)
    {
        $content = json_decode($response->getContent(), true);
        $statusCode = $response->getStatusCode();

        if ($statusCode !== 204 && null === $content) {
            throw new LibraryException('Unable to parse response from server (status code: '.$response->getStatusCode().') '.$response->getContent());
        }

        if (isset($content['status']) && $content['status'] !== ExceptionFactory::STATUS_SUCCESS) {
            throw ExceptionFactory::createExceptionFromArray($content);
        }

        if ($statusCode !== 200 && $statusCode !== 204 && ($statusCode < 300 || $statusCode > 303)) {
            throw new LibraryException(sprintf('Invalid status code (expected 200, 204, or 300-303. Got %s). Response content: %s', $statusCode, $response->getContent()));
        }
    }
792638
protected static function handleResponse($response)
    {
        self::resolveContentType($response);

        $body = $response->getBody();
        $response = json_decode($body);

        self::resolveErrorResponse($response);

        return $response;
    }
1176258
protected function provideResponder(): ResponderInterface
    {
        $acceptHeader = $this->request->getServerParam('HTTP_ACCEPT', '');
        if (strpos($acceptHeader, 'application/json') !== false) {
            return new JsonResponder($this->config);
        }
        return new HtmlResponder($this->config);
    }
631523
public function inject(Response &$response)
    {
        $renderer = $this->debugBar->getJavascriptRenderer('/__debug__/');

        if (stripos($response->headers->get('Content-Type'), 'text/html') === 0) {
            $content = $response->getContent();
            $content = self::injectHtml($content, $renderer->renderHead(), '</head>');
            $content = self::injectHtml($content, $renderer->render(), '</body>');
            $response->setContent($content);
        }
    }
530325
public function bind(Request $request = null, AbstractResponse $response = null)
    {
        // Keep references
        $this->request  = $request  ?: $this->request;
        $this->response = $response ?: $this->response;

        return $this;
    }
285238
public function isBearer($response)
	{	
     	if (!isset($response->token_type)) {
    		return false;
    	}

    	if ($response->token_type == 'bearer') {
    		return $response->access_token;
    	}
	}
502320
private function performResponse($response)
    {
        $data = false;
        if ($response instanceof ResponseInterface) {
            $data = json_decode($response->getBody()->getContents());
            $this->getValidationResponse()->validateResponseData($data);
        }

        return $data;
    }
660177
public function addResponse($response)
    {
        if (!($response instanceof Response)) {
            if (!is_string($response)) {
                throw new InvalidArgumentException('Invalid response');
            }
            $response = self::getMockFile($response);
        }

        $this->queue[] = $response;

        return $this;
    }
1036922
public function verifyResponse($response, $clientIp = null)
    {
        if (empty($response)) {
            return false;
        }

        // Return true if response already verfied before.
        if (in_array($response, $this->verifiedResponses)) {
            return true;
        }

        $verifyResponse = $this->sendRequestVerify([
            'secret' => $this->secret,
            'response' => $response,
            'remoteip' => $clientIp,
        ]);

        if (isset($verifyResponse['success']) && $verifyResponse['success'] === true) {
            // A response can only be verified once from google, so we need to
            // cache it to make it work in case we want to verify it multiple times.
            $this->verifiedResponses[] = $response;
            return true;
        } else {
            return false;
        }
    }
779336
protected function respond($response)
    {
        if (Arr::get($response, 'object') === 'list') {
            if (!empty($response['data'])) {
                foreach ($response['data'] as $responseItem) {
                    $success = Arr::get($responseItem, 'object', 'error') !== 'error';

                    $responses[] = $this->mapResponse($success, $responseItem);
                }

                return $responses;
            } else {
                $response = $response['data'];
            }
        }

        $success = Arr::get($response, 'object', 'error') !== 'error';

        return $this->mapResponse($success, $response);
    }
39365
protected function processResponse($response)
    {
        // If the soap call failed then we need to throw an exception.
        $code = $this->soap->getResponseCode();
        if ($code != 200) {
            throw new \Exception(
                "SOAP client returned status of $code.",
                $code
            );
        }

        return $response;
    }
625803
public function register(
        ServerRequestInterface $request, ResponseInterface $response
    ) {
        $this->request = $request;
        $this->response = $response;
        return $this;
    }
93288
public function execute($response) {
        global $CFG, $DB;

        $params = $this->parse_template();
        $contextid = $params['context_id'];
        $itemid = $params['item_id'];

        // GET is disabled by the moment, but we have the code ready
        // for a future implementation.

        $isget = $response->get_request_method() === 'GET';
        if ($isget) {
            $contenttype = $response->get_accept();
        } else {
            $contenttype = $response->get_content_type();
        }
        $container = empty($contenttype) || ($contenttype === $this->formats[0]);
        // We will receive typeid when working with LTI 1.x, if not the we are in LTI 2.
        $typeid = optional_param('type_id', null, PARAM_ALPHANUM);
        if (is_null($typeid)) {
            if (!$this->check_tool_proxy(null, $response->get_request_data())) {
                $response->set_code(403);
                return;
            }
        } else {
            switch ($response->get_request_method()) {
                case 'GET':
                    $response->set_code(405);
                    $response->set_reason("GET requests are not allowed.");
                    return;
                case 'POST':
                    if (!$this->check_type($typeid, $contextid, 'Score.collection:post', $response->get_request_data())) {
                        $response->set_code(401);
                        $response->set_reason("This resource does not support POST requests.");
                        return;
                    }
                    break;
                default:  // Should not be possible.
                    $response->set_code(405);
                    return;
            }
        }
        if (empty($contextid) || !($container ^ ($response->get_request_method() === 'POST')) ||
                (!empty($contenttype) && !in_array($contenttype, $this->formats))) {
            $response->set_code(400);
            return;
        }
        if (!$DB->record_exists('course', array('id' => $contextid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Course $contextid doesn't exist.");
            return;
        }
        if (!$DB->record_exists('grade_items', array('id' => $itemid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Grade item $itemid doesn't exist.");
            return;
        }
        $item = $this->get_service()->get_lineitem($contextid, $itemid, $typeid);
        if ($item === false) {
            $response->set_code(403);
            $response->set_reason("Line item does not exist.");
            return;
        }
        $gbs = gradebookservices::find_ltiservice_gradebookservice_for_lineitem($itemid);
        $ltilinkid = null;
        if (isset($item->iteminstance)) {
            $ltilinkid = $item->iteminstance;
        } else if ($gbs && isset($gbs->ltilinkid)) {
            $ltilinkid = $gbs->ltilinkid;
        }
        if ($ltilinkid != null) {
            if (is_null($typeid)) {
                if (isset($item->iteminstance) && (!gradebookservices::check_lti_id($ltilinkid, $item->courseid,
                        $this->get_service()->get_tool_proxy()->id))) {
                    $response->set_code(403);
                    $response->set_reason("Invalid LTI id supplied.");
                    return;
                }
            } else {
                if (isset($item->iteminstance) && (!gradebookservices::check_lti_1x_id($ltilinkid, $item->courseid,
                        $typeid))) {
                    $response->set_code(403);
                    $response->set_reason("Invalid LTI id supplied.");
                    return;
                }
            }
        }
        $json = '[]';
        require_once($CFG->libdir.'/gradelib.php');
        switch ($response->get_request_method()) {
            case 'GET':
                $response->set_code(405);
                $response->set_reason("GET requests are not allowed.");
                break;
            case 'POST':
                try {
                    $json = $this->get_json_for_post_request($response, $response->get_request_data(), $item, $contextid, $typeid);
                    $response->set_content_type($this->formats[1]);
                } catch (\Exception $e) {
                    $response->set_code($e->getCode());
                    $response->set_reason($e->getMessage());
                }
                break;
            default:  // Should not be possible.
                $response->set_code(405);
                $response->set_reason("Invalid request method specified.");
                return;
        }
        $response->set_body($json);
    }
1075749
public function setResponse(Response $response)
    {
        $this->response = $response;
        $this->context->registerInstance($response);
    }
62456
protected function isValidResponse($response)
    {
        if (empty($this->acceptable)) {
            return true;
        }

        if ($this->acceptableIsClosure()) {
            return call_user_func($this->acceptable, $response);
        }

        return $this->isAcceptableResponse($response);
    }
724618
public function execute($response) {
        global $CFG, $DB;

        $params = $this->parse_template();
        $contextid = $params['context_id'];
        $itemid = $params['item_id'];
        if ($response->get_request_method() === 'GET') {
            $contenttype = $response->get_accept();
        } else {
            $contenttype = $response->get_content_type();
        }
        // We will receive typeid when working with LTI 1.x, if not then we are in LTI 2.
        $typeid = optional_param('type_id', null, PARAM_ALPHANUM);
        if (is_null($typeid)) {
            if (!$this->check_tool_proxy(null, $response->get_request_data())) {
                $response->set_code(403);
                $response->set_reason("Invalid tool proxy specified.");
                return;
            }
        } else {
            switch ($response->get_request_method()) {
                case self::HTTP_GET:
                    if (!$this->check_type($typeid, $contextid, 'LineItem.item:get', $response->get_request_data())) {
                        $response->set_code(403);
                        $response->set_reason("This resource does not support GET requests.");
                        return;
                    }
                    break;
                case self::HTTP_PUT:
                    if (!$this->check_type($typeid, $contextid, 'LineItem.item:put', $response->get_request_data())) {
                        $response->set_code(403);
                        $response->set_reason("This resource does not support PUT requests.");
                        return;
                    }
                    break;
                case self::HTTP_DELETE:
                    if (!$this->check_type($typeid, $contextid, 'LineItem.item:delete', $response->get_request_data())) {
                        $response->set_code(403);
                        $response->set_reason("This resource does not support DELETE requests.");
                        return;
                    }
                    break;
                default:  // Should not be possible.
                    $response->set_code(405);
                    return;
            }
        }
        if (empty($contextid) || (!empty($contenttype) && !in_array($contenttype, $this->formats))) {
            $response->set_code(400);
            $response->set_reason("Invalid request made.");
            return;
        }
        if (!$DB->record_exists('course', array('id' => $contextid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Course $contextid doesn't exist.");
            return;
        }
        if (!$DB->record_exists('grade_items', array('id' => $itemid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Grade item $itemid doesn't exist.");
            return;
        }
        $item = $this->get_service()->get_lineitem($contextid, $itemid, $typeid);
        if ($item === false) {
            $response->set_code(403);
            $response->set_reason("Line item does not exist.");
            return;
        }
        require_once($CFG->libdir.'/gradelib.php');
        switch ($response->get_request_method()) {
            case 'GET':
                $this->get_request($response, $item, $typeid);
                break;
            case 'PUT':
                $json = $this->process_put_request($response->get_request_data(), $item, $typeid);
                $response->set_body($json);
                $response->set_code(200);
                break;
            case 'DELETE':
                $this->process_delete_request($item);
                $response->set_code(204);
                break;
            default:  // Should not be possible.
                $response->set_code(405);
                $response->set_reason("Invalid request method specified.");
                return;
        }
    }