private function _doParseError(ehough_shortstop_api_HttpResponse $response) { $entity = $response->getEntity(); $rawResponse = $entity->getContent(); $unserialized = @unserialize($rawResponse); return $unserialized->err->msg; }
/** * Determines if this response needs to be decoded. * * @param ehough_shortstop_api_HttpResponse $response The HTTP response. * * @return boolean True if this response should be decoded. False otherwise. */ public final function needsToBeDecoded(ehough_shortstop_api_HttpResponse $response) { $entity = $response->getEntity(); $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($entity === null) { if ($isDebugEnabled) { $this->_logger->debug('Response contains no entity'); } return false; } $content = $entity->getContent(); if ($content == '' || $content == null) { if ($isDebugEnabled) { $this->_logger->debug('Response entity contains no content'); } return false; } $expectedHeaderName = $this->getHeaderName(); $actualHeaderValue = $response->getHeaderValue($expectedHeaderName); if ($actualHeaderValue === null) { if ($isDebugEnabled) { $this->_logger->debug(sprintf('Response does not contain %s header. No need to decode.', $expectedHeaderName)); } return false; } if ($isDebugEnabled) { $this->_logger->debug(sprintf('Response contains %s header. Will attempt decode.', $expectedHeaderName)); } return true; }
public function testAfterCredentialsOrTokenRequest() { $request = new ehough_shortstop_api_HttpRequest('POST', 'http://abc.com'); $httpResponse = new ehough_shortstop_api_HttpResponse(); $httpResponse->setStatusCode(200); $this->_sut->onAfterCredentialsOrTokenRequest($request, $httpResponse); $this->assertTrue(true); }
public function setUp() { $this->_mockSigner = ehough_mockery_Mockery::mock('ehough_coauthor_spi_v1_SignerInterface'); $this->_mockClientCredentials = new ehough_coauthor_api_v1_Credentials('id', 'secret'); $this->_mockTemporaryCredentials = new ehough_coauthor_api_v1_Credentials('id2', 'secret2'); $this->_mockServer = ehough_mockery_Mockery::mock('ehough_coauthor_api_v1_AbstractServer'); $this->_mockHttpClient = ehough_mockery_Mockery::mock('ehough_shortstop_api_HttpClientInterface'); $this->_mockServer->shouldReceive('getTemporaryCredentialsEndpoint')->andReturn(new ehough_curly_Url('http://abc.com/a/f/2.php?x=z')); $this->_mockServer->shouldReceive('getTokensEndpoint')->andReturn(new ehough_curly_Url('http://xez.net/w2/d/z.php?a=b')); $this->_mockHttpResponse = new ehough_shortstop_api_HttpResponse(); $this->_mockHttpResponse->setStatusCode(200); $entity = new ehough_shortstop_api_HttpEntity(); $entity->setContent('oauth_token=token&oauth_token_secret=secrettt'); $this->_mockHttpResponse->setEntity($entity); $this->_sut = new ehough_coauthor_impl_v1_DefaultRemoteCredentialsFetcher($this->_mockHttpClient, $this->_mockSigner); }
private function _doParseError(ehough_shortstop_api_HttpResponse $response) { $entity = $response->getEntity(); $rawResponse = $entity->getContent(); $domDocument = new DOMDocument(); $domDocument->loadXML($rawResponse); $xpath = new DOMXPath($domDocument); $xpath->registerNamespace('google', 'http://schemas.google.com/g/2005'); return $xpath->query('//google:error[1]/google:internalReason')->item(0)->nodeValue; }
/** * @param ehough_shortstop_api_HttpResponse $response The HTTP response for the temporary credentials or token request that failed. * * @return string An error message based on the HTTP response. */ public function getErrorMessageFromBadHttpResponse(ehough_shortstop_api_HttpResponse $response) { //override point return $this->getFriendlyName() . ' responded with an HTTP ' . $response->getStatusCode(); }
private function _assignEntityToResponse($body, ehough_shortstop_api_HttpResponse $response, $debugging) { if ($debugging) { $this->getLogger()->debug('Assigning (possibly empty) entity to response'); } $entity = new ehough_shortstop_api_HttpEntity(); $entity->setContent($body); $entity->setContentLength(strlen($body)); $contentType = $response->getHeaderValue(ehough_shortstop_api_HttpResponse::HTTP_HEADER_CONTENT_TYPE); if ($contentType !== null) { $entity->setContentType($contentType); } $response->setEntity($entity); }