public function testHasEffectiveUrl() { $r = new Response(200); $this->assertNull($r->getEffectiveUrl()); $r->setEffectiveUrl('http://www.test.com'); $this->assertEquals('http://www.test.com', $r->getEffectiveUrl()); }
/** * Set up our test fixture. * * Expect a service URL something like this: * http://api.nfldata.apiphany.com/developer/xml/AreAnyGamesInProgress/?key=000aaaa0-a00a-0000-0a0a-aa0a00000000 */ public static function setUpBeforeClass() { static::$sClient = new MockClient($_SERVER['FANTASY_DATA_API_KEY'], Subscription::KEY_DEVELOPER); /** \GuzzleHttp\Command\Model */ static::$sClient->AreAnyGamesInProgress([]); static::$sResponse = static::$sClient->mHistory->getLastResponse(); static::$sEffectiveUrl = static::$sResponse->getEffectiveUrl(); static::$sUrlFragments = explode('/', static::$sEffectiveUrl); }
/** * Set up our test fixture. * * Expect a service URL something like this: * http://api.nfldata.apiphany.com/developer/json/ScoresByWeek/2013REG/17?key=000aaaa0-a00a-0000-0a0a-aa0a00000000 */ public static function setUpBeforeClass() { static::$sClient = new MockClient($_SERVER['FANTASY_DATA_API_KEY'], Subscription::KEY_DEVELOPER); /** \GuzzleHttp\Command\Model */ static::$sClient->ScoresByWeek(['Season' => '2013REG', 'Week' => 17]); static::$sResponse = static::$sClient->mHistory->getLastResponse(); static::$sEffectiveUrl = static::$sResponse->getEffectiveUrl(); static::$sUrlFragments = explode('/', static::$sEffectiveUrl); }
/** * Set up our test fixture. * * Expect a service URL something like this: * http://api.nfldata.apiphany.com/developer/json/SeasonLeagueLeaders/2013REG/NE?key=000aaaa0-a00a-0000-0a0a-aa0a00000000 */ public static function setUpBeforeClass() { static::$sClient = new MockClient($_SERVER['FANTASY_DATA_API_KEY'], Subscription::KEY_DEVELOPER); /** \GuzzleHttp\Command\Model */ static::$sClient->SeasonLeagueLeaders(['Season' => '2013REG', 'Position' => 'WR', 'Column' => 'FantasyPoints']); static::$sResponse = static::$sClient->mHistory->getLastResponse(); static::$sEffectiveUrl = static::$sResponse->getEffectiveUrl(); static::$sUrlFragments = explode('/', static::$sEffectiveUrl); }
/** * Constructor * * @param GuzzleResponse $response */ public function __construct(GuzzleResponse $response) { $headers = $response->getHeaders(); //-- this is a hack on my part and I'm terribly sorry it exists //-- but deal with it. foreach ($headers as $header => $value) { $this->headers[$header] = implode(',', array_values((array) $value)); } $this->url = $response->getEffectiveUrl(); $url_parts = explode('?', $this->url); if (isset($url_parts[1])) { $query = explode('&', $url_parts[1]); foreach ($query as $params) { $kv = explode('=', $params); $this->params[$kv[0]] = isset($kv[1]) ? $kv[1] : ''; } } // $this->params = $response->request_parameters; // $this->method = $response->request_method; $this->json = $response->json(); // $json = json_decode($this->json, TRUE); $this->data = isset($this->json['data']) ? $this->json['data'] : []; $this->meta = isset($this->json['meta']) ? $this->json['meta'] : []; if (isset($this->json['code']) && $this->json['code'] !== 200) { $this->meta = $this->json; } $this->pagination = isset($this->json['pagination']) ? $this->json['pagination'] : []; $this->user = isset($this->json['user']) ? $this->json['user'] : []; $this->access_token = isset($this->json['access_token']) ? $this->json['access_token'] : NULL; $this->limit = isset($this->headers[self::RATE_LIMIT_HEADER]) ? $this->headers[self::RATE_LIMIT_HEADER] : 0; $this->remaining = isset($this->headers[self::RATE_LIMIT_REMAINING_HEADER]) ? $this->headers[self::RATE_LIMIT_REMAINING_HEADER] : 0; }
function debug(\GuzzleHttp\Message\Response $response) { $this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody(); //un string encodeado utf-8 $this->dump_url = $response->getEffectiveUrl(); //un string encodeado utf-8 }
public function testDoesTheSameAsResponseWhenDereferenced() { $str = Stream::factory('foo'); $response = new Response(200, ['Foo' => 'bar'], $str); $future = MockTest::createFuture(function () use($response) { return $response; }); $this->assertFalse($this->readAttribute($future, 'isRealized')); $this->assertEquals(200, $future->getStatusCode()); $this->assertTrue($this->readAttribute($future, 'isRealized')); // Deref again does nothing. $future->wait(); $this->assertTrue($this->readAttribute($future, 'isRealized')); $this->assertEquals('bar', $future->getHeader('Foo')); $this->assertEquals(['bar'], $future->getHeaderAsarray('Foo')); $this->assertSame($response->getHeaders(), $future->getHeaders()); $this->assertSame($response->getBody(), $future->getBody()); $this->assertSame($response->getProtocolVersion(), $future->getProtocolVersion()); $this->assertSame($response->getEffectiveUrl(), $future->getEffectiveUrl()); $future->setEffectiveUrl('foo'); $this->assertEquals('foo', $response->getEffectiveUrl()); $this->assertSame($response->getReasonPhrase(), $future->getReasonPhrase()); $this->assertTrue($future->hasHeader('foo')); $future->removeHeader('Foo'); $this->assertFalse($future->hasHeader('foo')); $this->assertFalse($response->hasHeader('foo')); $future->setBody(Stream::factory('true')); $this->assertEquals('true', (string) $response->getBody()); $this->assertTrue($future->json()); $this->assertSame((string) $response, (string) $future); $future->setBody(Stream::factory('<a><b>c</b></a>')); $this->assertEquals('c', (string) $future->xml()->b); $future->addHeader('a', 'b'); $this->assertEquals('b', $future->getHeader('a')); $future->addHeaders(['a' => '2']); $this->assertEquals('b, 2', $future->getHeader('a')); $future->setHeader('a', '2'); $this->assertEquals('2', $future->getHeader('a')); $future->setHeaders(['a' => '3']); $this->assertEquals(['a' => ['3']], $future->getHeaders()); }
/** * @param \GuzzleHttp\Message\Response $response * * @throws DocumentBuilderException * @return \Morphodo\CrawlerBundle\Domain\Document */ public function fromResponse(\GuzzleHttp\Message\Response $response) { $this->response = $response; $document = new IndexerBundle\Domain\Document(); if ($this->detectEncoding() != 'UTF-8') { $convertedBody = @iconv($this->detectEncoding(), $this->defaultEncoding . "//TRANSLIT", (string) $this->response->getBody()); if ($convertedBody === FALSE) { throw new Domain\DocumentBuilderException('Document charset conversion from ' . $this->detectEncoding() . ' into ' . $this->defaultEncoding . ' failed for document: ' . $this->response->getEffectiveUrl(), 1420557940); } $convertedBody = $this->updateContentTypeStringWithinMetaTag($this->convertEntitiesIntoUtf8($convertedBody)); } $document->setContent($convertedBody); $document->setUrl($response->getEffectiveUrl()); return $document; }
/** * Announces HTTP request to Wildfire channel * * @param GuzzleHttp\Message\Request * @param GuzzleHttp\Message\Response when dealing with error events, response may not be populated * @param float $elapsed */ public function publishRequest(Request $request, Response $response = null, $elapsed = 0) { $request_body = $request->getBody(); $request_preview = ''; if ($request_body) { $request_body->seek(0); // rewind the cursor in case a read was already done $request_preview = $request_body->read($this->_preview_length); $request_body->seek(0); // rewind the cursor, so subsequent reads are not affected } // Ensure response is populated before extracting body from it $response_body = $response ? $response->getBody() : ''; $response_preview = ''; if ($response_body) { $response_body->seek(0); // rewind the cursor, in case a read was already done $response_preview = $response_body->read($this->_preview_length); $response_body->seek(0); // rewind the cursor, so subsequent reads are not affected } $phrase = $response ? $response->getReasonPhrase() : self::ERROR_NO_RESPONSE; $table = []; $table[] = ['Key', 'Value']; $table[] = ['Phrase', $phrase]; $table[] = ['Host', $request->getHost()]; $table[] = ['Protocol', $request->getScheme()]; $table[] = ['User Agent', $request->getHeader('User-Agent')]; $table[] = ['Request', $request_preview]; $table[] = ['Response', $response_preview]; if ($response && $response->getEffectiveUrl() != $request->getUrl()) { $table[] = ['Effective URL', $response->getEffectiveUrl()]; } $elapsed = number_format($elapsed, 4); $status = $response ? $response->getStatusCode() : 0; $message = sprintf("%s <%s> (%d) %s (%f)s", $this->_remote_prefix, $request->getMethod(), $status, $request->getUrl(), $elapsed); $this->_client->table($message, $table); }
/** * get request url * @return string */ public function getRequestedURL() { return $this->response->getEffectiveUrl(); }