Ejemplo n.º 1
0
 /**
  * mutator method for the XSRF token
  * it is initialized by rummaging through Guzzle's Cookie Jar
  **/
 public final function setXsrfToken()
 {
     if ($this->guzzle !== null) {
         $cookieJar = $this->guzzle->getConfig("cookies");
         foreach ($cookieJar as $cookie) {
             if ($cookie->getName() === "XSRF-TOKEN") {
                 $this->xsrfToken = $cookie->getValue();
                 break;
             }
         }
     }
 }
Ejemplo n.º 2
0
 static function __callStatic($name, $args)
 {
     if (!self::$client) {
         self::$client = new GuzzleHttp\Client();
     }
     return call_user_func_array([self::$client, $name], $args);
 }
Ejemplo n.º 3
0
 static function __callStatic($name, $args)
 {
     if (!self::$client) {
         self::$client = new GuzzleHttp\Client(['defaults' => ['timeout' => 10, 'headers' => ['User-Agent' => 'PHP']]]);
     }
     return call_user_func_array([self::$client, $name], $args);
 }
Ejemplo n.º 4
0
 /**
  * Sends request to the URL and acquires data from the response.
  *
  * @param $url
  * @return mixed
  * @throws \Exception
  */
 protected function get($url)
 {
     $response = \Guzzle::get($url);
     if ($response->getStatusCode() === 200) {
         return json_decode($response->getBody());
     }
     throw new \Exception('Request was not successful: ' . $response->getStatusCode());
 }
Ejemplo n.º 5
0
 protected static function get($segments)
 {
     //
     // Authenticate organization to retrieve full list of members.
     // FIXME: without authentication, only the public list is being retrieved.
     //
     $client_id = '';
     $client_secret = '';
     return \Guzzle::get(self::API_URL . "{$segments}?client_id={$client_id}&client_secret={$client_secret}")->json();
 }
Ejemplo n.º 6
0
 private function _getGithub()
 {
     Guzzle\Http\StaticClient::mount();
     try {
         $response = Guzzle::get('https://api.github.com/orgs/codezeus/repos');
         if ($response->getStatusCode() == 200) {
             return json_decode($response->getBody());
         }
     } catch (\Exception $e) {
     }
     return [];
 }
Ejemplo n.º 7
0
 function __construct($url, $body = null)
 {
     if ($body) {
         $this->url = $url;
         $this->body = $body;
     } else {
         $response = Guzzle::get($url);
         $this->url = $response->getEffectiveUrl();
         // important if redirected
         $this->body = $response->getBody();
     }
     $this->crawler = new Crawler($this->body);
 }
Ejemplo n.º 8
0
 public function fire($job, $data)
 {
     $content = Content::findOrFail($data['id']);
     $url = Config::get('app.iframely_host') . '/oembed';
     $response = Guzzle::get($url, ['query' => ['url' => $content->url]])->json();
     $content->type = $response['type'];
     $content->save();
     if ($data['thumbnail'] && array_key_exists('thumbnail_url', $response)) {
         $content->setThumbnail($response['thumbnail_url']);
     }
     $content->autoThumbnail();
     WS::send(json_encode(['topic' => 'content.' . $content->getKey() . '.thumbnail', 'url' => $content->getThumbnailPath(100, 75)]));
     $content->unset('thumbnail_loading');
     $job->delete();
 }
Ejemplo n.º 9
0
 function perform()
 {
     $ps = DB::prepare('INSERT INTO listings SET scraped=FALSE, code=:code, title=:title, link=:link, date=:date, price=:price, neighborhood=:neighborhood');
     array_map(function ($url) use($ps) {
         $code = substr($url, 30, 3);
         // SUPER brittle obvs
         $crawler = new Crawler(Guzzle::get($url)->getBody());
         $crawler->filter('.row > .txt')->each(function ($node) use($ps, $code) {
             try {
                 $a = $node->filter('.pl > a.hdrlnk');
                 $ps->execute([':code' => $code, ':title' => $a->text(), ':link' => $a->attr('href'), ':date' => strftime('%Y-%m-%d', strtotime($node->filter('.pl > .date')->text())), ':price' => ($n = $node->filter('.l2 > .price')) && $n->count() ? preg_replace('/\\D/', '', $n->text()) : null, ':neighborhood' => ($n = $node->filter('.l2 > .pnr > small')) && $n->count() ? $n->text() : null]);
             } catch (Exception $e) {
                 Logger::error($e->getMessage(), $ps->errorinfo());
             }
         });
     }, ['http://newyork.craigslist.org/nfa/', 'http://newyork.craigslist.org/roo/', 'http://newyork.craigslist.org/sub/']);
 }
Ejemplo n.º 10
0
 function perform()
 {
     $q = DB::query('SELECT link, neighborhood FROM listings WHERE scraped != TRUE', PDO::FETCH_ASSOC);
     $ps = DB::prepare('UPDATE listings SET scraped=TRUE, street=:street, description=:description, lat=:lat, lng=:lng WHERE link=:link');
     /*
     Guzzle::sendAll(array_map(function ($listing) {
       return Guzzle::createRequest('GET', 'http://newyork.craigslist.org' . $listing['link']);
     }, iterator_to_array($q)), ['complete' => function ($event) use($ps) {
       try {        
         $body = $event->getResponse()->getBody();
       
         $crawler = new Crawler($body);
         $readability = new Readability($body);
     
         $street = $crawler->filter('.mapAndAttrs > .mapbox > div.mapaddress');
       
         $ps->execute([
           ':link' => parse_url($event->getRequest()->getUrl())['path'],
           ':lat'  => null,
           ':lng'  => null,
           ':street' => $street->count() ? $street->text() : null,
           ':description' => $readability->init() ? trim(strip_tags(tidy_parse_string($readability->getContent()->innerHTML, [], 'UTF8'))) : null    
         ]);
       } catch (Exception $e) {
         Logger::error($e->getMessage(), $ps->errorinfo());
       }
     }]);
     */
     foreach ($q as $listing) {
         try {
             $body = Guzzle::get('http://newyork.craigslist.org' . $listing['link'])->getBody();
             $crawler = new Crawler($body);
             $readability = new Readability($body);
             $street = $crawler->filter('.mapAndAttrs > .mapbox > div.mapaddress');
             $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . ($street->count() ? $street->text() : $listing['neighborhood']);
             $json = json_decode(Guzzle::get($url)->getBody(), true);
             $loc = isset($json['results'][0]) ? $json['results'][0]['geometry']['location'] : null;
             $ps->execute([':link' => $listing['link'], ':lat' => isset($loc['lat']) ? $loc['lat'] : null, ':lng' => isset($loc['lng']) ? $loc['lng'] : null, ':street' => $street->count() ? $street->text() : null, ':description' => $readability->init() ? trim(strip_tags(tidy_parse_string($readability->getContent()->innerHTML, [], 'UTF8'))) : null]);
         } catch (Exception $e) {
             Logger::error($e->getMessage(), $ps->errorinfo());
         }
     }
 }
<?php

use Guzzle\Http\Client;
$oclcNumber = $_GET['oclcNumber'];
$url = "https://worldcat.org/circ/availability/sru/service?x-registryId=" . $config['institution'] . "&query=no:ocm" . $oclcNumber;
$client = new Client($guzzleOptions);
$headers = array('Authorization' => 'Bearer ' . $accessToken->getValue());
// Set the guzzle headers
$guzzleOptions['headers'] = $headers;
// And execute the request (in this case a simple GET with no request body)
try {
    $response = \Guzzle::get($url, $guzzleOptions);
    // Define the namespaces for parsing
    $availabilityResponse = simplexml_load_string($response->getBody(true));
    $holdings = $availabilityResponse->xpath('//holdings/holding');
    echo '<p>holding count' . count($holdings) . '</p>';
} catch (\Guzzle\Http\Exception\BadResponseException $error) {
    // Or display the error, if one occurs
    echo '<div class="error">';
    echo $error->getResponse()->getStatusCode();
    echo $error->getRequest();
    echo '</div>';
}
?>
<html>
<head>
    <title>Availability Detail Screen for <?php 
echo $oclcNumber;
?>
</title>
    <style type="text/css">
Ejemplo n.º 12
0
 /**
  * Acknowledges the message on Discord servers.
  *
  * @return boolean 
  */
 public function acknowledgeMessage()
 {
     Guzzle::post($this->replaceWithVars('channels/:channel_id/messages/:id/ack'));
     return true;
 }
Ejemplo n.º 13
0
Archivo: guzzle3.php Proyecto: yfix/yf
#!/usr/bin/php
<?php 
$config = ['require_services' => ['sf_event_dispatcher'], 'git_urls' => ['https://github.com/yfix/guzzle.git~v3.7.4' => 'guzzle3/'], 'autoload_config' => ['guzzle3/src/Guzzle/' => 'Guzzle'], 'example' => function () {
    Guzzle\Http\StaticClient::mount();
    $response = Guzzle::get('http://google.com');
    echo strlen($response);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Ejemplo n.º 14
0
 /**
  * If the tournament has not started, delete a participant, automatically filling in the abandoned seed number.
  *
  * @return boolean
  */
 public function delete()
 {
     $response = Guzzle::delete("tournaments/{$this->tournament_slug}/participants/{$this->id}");
     return true;
 }
Ejemplo n.º 15
0
 /**
  * Process answer
  *
  * @param \Guzzle $response
  *
  * @return array
  */
 protected function processAnswer($response)
 {
     if (!$response->getStatusCode() == 200) {
         throw new RuntimeException('Wrong status code answer: ' . var_export($response->getStatusCode(), true));
     }
     $response->getBody()->seek(0);
     $result = $response->getBody()->getContents();
     $data = @json_decode($result, true);
     if ($data === false || !is_array($data)) {
         throw new RuntimeException('Wrong json in answer: ' . var_export($result, true));
     }
     if ($data['error'] !== null) {
         throw new RuntimeException('Server return an error: ' . var_export($data['error']['message'], true));
     }
     return $data['result'];
 }
Ejemplo n.º 16
0
 function testFacade()
 {
     $this->assertEquals(preg_match('#^Guzzle/.+ curl/.+ PHP/.+$#', Guzzle::getDefaultUserAgent()), 1);
 }