Skip to content

Instantly share code, notes, and snippets.

@diguinhorocks
Last active September 20, 2019 16:07
Show Gist options
  • Select an option

  • Save diguinhorocks/4237748 to your computer and use it in GitHub Desktop.

Select an option

Save diguinhorocks/4237748 to your computer and use it in GitHub Desktop.

Revisions

  1. diguinhorocks revised this gist Sep 20, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Request.php
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ protected function queryURL()
    {
    return <<<URL
    https://www.googleapis.com/customsearch/v1?key=AIzaSyCtYDYedySqc3VyEOsU2LyqC6l67MANF98&cx=012557125435830414214:wuek1hiu0n8&alt=atom
    https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={your_cx}&alt=atom
    URL;
    }
  2. diguinhorocks revised this gist Dec 8, 2012. 2 changed files with 3 additions and 8 deletions.
    9 changes: 2 additions & 7 deletions Request.php
    Original file line number Diff line number Diff line change
    @@ -8,10 +8,7 @@ class Request
    protected $response;
    protected $curl;

    public function __construct()
    {

    }
    public function __construct(){ }

    public function setQuery($query)
    {
    @@ -21,17 +18,15 @@ public function setQuery($query)

    public function go()
    {


    $this->curl = curl_init();
    curl_setopt( $this->curl , CURLOPT_URL , ltrim( $this->queryURL() . '&q=' . urlencode($this->query) ) );
    curl_setopt( $this->curl , CURLOPT_SSL_VERIFYPEER , false );
    curl_setopt( $this->curl , CURLOPT_RETURNTRANSFER , 1 );


    $this->response = curl_exec($this->curl);

    curl_close($this->curl);

    return $this->getResponse();
    }

    2 changes: 1 addition & 1 deletion search.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,6 @@

    include 'Request.php';

    $c = new Requestl();
    $c = new Request();

    echo $c->setQuery($_GET['q'])->go();
  3. diguinhorocks created this gist Dec 8, 2012.
    52 changes: 52 additions & 0 deletions Request.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    <?php


    class Request
    {
    protected $url;
    protected $request;
    protected $response;
    protected $curl;

    public function __construct()
    {

    }

    public function setQuery($query)
    {
    $this->query = $query;
    return $this;
    }

    public function go()
    {


    $this->curl = curl_init();
    curl_setopt( $this->curl , CURLOPT_URL , ltrim( $this->queryURL() . '&q=' . urlencode($this->query) ) );
    curl_setopt( $this->curl , CURLOPT_SSL_VERIFYPEER , false );
    curl_setopt( $this->curl , CURLOPT_RETURNTRANSFER , 1 );


    $this->response = curl_exec($this->curl);

    curl_close($this->curl);
    return $this->getResponse();
    }

    public function getResponse()
    {
    header('Content-Type: application/atom+xml');
    echo $this->response;
    }

    protected function queryURL()
    {
    return <<<URL
    https://www.googleapis.com/customsearch/v1?key=AIzaSyCtYDYedySqc3VyEOsU2LyqC6l67MANF98&cx=012557125435830414214:wuek1hiu0n8&alt=atom
    URL;
    }
    }
    12 changes: 12 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8">
    <title></title>
    </head>
    <body>
    <form action="search.php" method="GET">
    <label for="">Pesquisar: </label> <input type="text" name="q" />
    </form>
    </body>
    </html>
    7 changes: 7 additions & 0 deletions search.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <?php

    include 'Request.php';

    $c = new Requestl();

    echo $c->setQuery($_GET['q'])->go();