Source for file search.php

Documentation is available at search.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Twitter
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die();
  11.  
  12. /**
  13.  * Twitter API Search class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Twitter
  17.  * @since       12.3
  18.  */
  19. {
  20.     /**
  21.      * Method to get tweets that match a specified query.
  22.      *
  23.      * @param   string   $query        Search query. Should be URL encoded. Queries will be limited by complexity.
  24.      * @param   string   $callback     If supplied, the response will use the JSONP format with a callback of the given name
  25.      * @param   string   $geocode      Returns tweets by users located within a given radius of the given latitude/longitude. The parameter value is
  26.      *                                     specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers).
  27.      * @param   string   $lang         Restricts tweets to the given language, given by an ISO 639-1 code.
  28.      * @param   string   $locale       Specify the language of the query you are sending (only ja is currently effective). This is intended for
  29.      *                                     language-specific clients and the default should work in the majority of cases.
  30.      * @param   string   $result_type  Specifies what type of search results you would prefer to receive. The current default is "mixed."
  31.      * @param   integer  $count        The number of tweets to return per page, up to a maximum of 100. Defaults to 15.
  32.      * @param   string   $until        Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
  33.      * @param   integer  $since_id     Returns results with an ID greater than (that is, more recent than) the specified ID.
  34.      * @param   integer  $max_id       Returns results with an ID less than (that is, older than) or equal to the specified ID.
  35.      * @param   boolean  $entities     When set to either true, t or 1, each tweet will include a node called "entities,". This node offers a
  36.      *                                     variety of metadata about the tweet in a discrete structure, including: urls, media and hashtags.
  37.      *
  38.      * @return  array  The decoded JSON response
  39.      *
  40.      * @since   12.3
  41.      */
  42.     public function search($query$callback null$geocode null$lang null$locale null$result_type null$count 15,
  43.         $until null$since_id 0$max_id 0$entities null)
  44.     {
  45.         // Check the rate limit for remaining hits
  46.         $this->checkRateLimit('search''tweets');
  47.  
  48.         // Set the API path
  49.         $path '/search/tweets.json';
  50.  
  51.         // Set query parameter.
  52.         $data['q'rawurlencode($query);
  53.  
  54.         // Check if callback is specified.
  55.         if ($callback)
  56.         {
  57.             $data['callback'$callback;
  58.         }
  59.  
  60.         // Check if geocode is specified.
  61.         if ($geocode)
  62.         {
  63.             $data['geocode'$geocode;
  64.         }
  65.  
  66.         // Check if lang is specified.
  67.         if ($lang)
  68.         {
  69.             $data['lang'$lang;
  70.         }
  71.  
  72.         // Check if locale is specified.
  73.         if ($locale)
  74.         {
  75.             $data['locale'$locale;
  76.         }
  77.  
  78.         // Check if result_type is specified.
  79.         if ($result_type)
  80.         {
  81.             $data['result_type'$result_type;
  82.         }
  83.  
  84.         // Check if count is specified.
  85.         if ($count != 15)
  86.         {
  87.             $data['count'$count;
  88.         }
  89.  
  90.         // Check if until is specified.
  91.         if ($until)
  92.         {
  93.             $data['until'$until;
  94.         }
  95.  
  96.         // Check if since_id is specified.
  97.         if ($since_id 0)
  98.         {
  99.             $data['since_id'$since_id;
  100.         }
  101.  
  102.         // Check if max_id is specified.
  103.         if ($max_id 0)
  104.         {
  105.             $data['max_id'$max_id;
  106.         }
  107.  
  108.         // Check if entities is specified.
  109.         if (!is_null($entities))
  110.         {
  111.             $data['include_entities'$entities;
  112.         }
  113.  
  114.         // Send the request.
  115.         return $this->sendRequest($path'GET'$data);
  116.     }
  117.  
  118.     /**
  119.      * Method to get the authenticated user's saved search queries.
  120.      *
  121.      * @return  array  The decoded JSON response
  122.      *
  123.      * @since   12.3
  124.      */
  125.     public function getSavedSearches()
  126.     {
  127.         // Check the rate limit for remaining hits
  128.         $this->checkRateLimit('saved_searches''list');
  129.  
  130.         // Set the API path
  131.         $path '/saved_searches/list.json';
  132.  
  133.         // Send the request.
  134.         return $this->sendRequest($path);
  135.     }
  136.  
  137.     /**
  138.      * Method to get the information for the saved search represented by the given id.
  139.      *
  140.      * @param   integer  $id  The ID of the saved search.
  141.      *
  142.      * @return  array  The decoded JSON response
  143.      *
  144.      * @since   12.3
  145.      */
  146.     public function getSavedSearchesById($id)
  147.     {
  148.         // Check the rate limit for remaining hits
  149.         $this->checkRateLimit('saved_searches''show/:id');
  150.  
  151.         // Set the API path
  152.         $path '/saved_searches/show/' $id '.json';
  153.  
  154.         // Send the request.
  155.         return $this->sendRequest($path);
  156.     }
  157.  
  158.     /**
  159.      * Method to create a new saved search for the authenticated user.
  160.      *
  161.      * @param   string  $query  The query of the search the user would like to save.
  162.      *
  163.      * @return  array  The decoded JSON response
  164.      *
  165.      * @since   12.3
  166.      */
  167.     public function createSavedSearch($query)
  168.     {
  169.         // Set the API path
  170.         $path '/saved_searches/create.json';
  171.  
  172.         // Set POST request data
  173.         $data['query'rawurlencode($query);
  174.  
  175.         // Send the request.
  176.         return $this->sendRequest($path'POST'$data);
  177.     }
  178.  
  179.     /**
  180.      * Method to delete a saved search for the authenticating user.
  181.      *
  182.      * @param   integer  $id  The ID of the saved search.
  183.      *
  184.      * @return  array  The decoded JSON response
  185.      *
  186.      * @since   12.3
  187.      */
  188.     public function deleteSavedSearch($id)
  189.     {
  190.         // Check the rate limit for remaining hits
  191.         $this->checkRateLimit('saved_searches''destroy/:id');
  192.  
  193.         // Set the API path
  194.         $path '/saved_searches/destroy/' $id '.json';
  195.  
  196.         // Send the request.
  197.         return $this->sendRequest($path'POST');
  198.     }
  199. }

Documentation generated on Tue, 19 Nov 2013 15:12:39 +0100 by phpDocumentor 1.4.3