13.5. Zend_Service_Yahoo

13.5.1. Introdução

Zend_Service_Yahoo é uma simples API para fazer uso das muitas APIs baseadas em REST do "Yahoo!". Zend_Service_Yahoo permite a você fazer buscas no Yahoo! Web search, Yahoo! News, Yahoo! Local, e Yahoo! Images. Para fazer uso da Yahoo! REST API, vice deve possuir uma Yahoo! Application ID. Para obtê-la, preencha o Formulário de Requisição de Application ID e envie.

13.5.2. Pesquisando a Web com o Yahoo!

Zend_Service_Yahoo permite executar buscas na web com o Yahoo! usando o método webSearch(), que aceita uma string de busca como parâmetro principal e um um array de opções de busca como segundo parâmetro opcional. Para maiores detalhes e uma lista de opções, visite o site Yahoo! Web Search Documentation. O método webSearch() retorna um objeto Zend_Service_Yahoo_WebResultSet.

Exemplo 13.11. Pesquisando a Web com o Yahoo!

<?php
require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->webSearch('PHP');
foreach ($results as $result) {
    echo $result->Title .'<br />';
}
?>       

13.5.3. Localizando imagens com o Yahoo!

Você pode procurar por imagens com o Yahoo usando o método imageSearch() do Zend_Service_Yahoo. Este método aceita [This method aceita uma string de busca como parâmetro principal e um um array de opções de busca como segundo parâmetro opcional, da mesma forma que o método webSearch(). Para maiores detalhes e uma lista de opções, visite o site Yahoo! Image Search Documentation.

Exemplo 13.12. Localizando imagens com o Yahoo!

<?php
require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->imageSearch('PHP');
foreach ($results as $result) {
    echo $result->Title .'<br />';
}
?>       

13.5.4. Localizando atividades de Comércio e Serviços locais com o Yahoo!

Você pode pesquisar por atividades locais de comércio e serviços usando o método localSearch() do "Yahoo!". Para maiores informações consulte a documentação do Yahoo! Local Search .

Exemplo 13.13. Finding Local Businesses and Services with Yahoo!

<?php
require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->localSearch('Apple Computers', array('zip' => '95014'));
foreach ($results as $result) {
    echo $result->Title .'<br />';
}
?>       

13.5.5. Pesquisando o Yahoo! News

Pesquisar no Yahoo! News é simples; basta usar o método newsSearch(), como mostrado no exemplo seguinte. Para maiores informações consulte a documentação do Yahoo! News Search.

Exemplo 13.14. Searching Yahoo! News

<?php
require_once 'Zend/Service/Yahoo.php';
$yahoo = new Zend_Service_Yahoo("YAHOO_APPLICATION_ID");
$results = $yahoo->newsSearch('PHP');
foreach ($results as $result) {
    echo $result->Title .'<br />';
}
?>       

13.5.6. Zend_Service_Yahoo Classes

The following classes are all returned by the various Yahoo! searches. Each search type returns a type-specific result set which can be easily iterated, with each result being contained in a type result object. All result set classes implement the SeekableIterator interface, allowing for easy iteration and seeking to a specific result.

13.5.6.1. Zend_Service_Yahoo_ResultSet

Each of the search specific result sets is extended from this base class.

Each of the specific result sets returns a search specific Zend_Service_Yahoo_Result objects.

13.5.6.1.1. Zend_Service_Yahoo_ResultSet::totalResults()

int totalResults();

Returns the number of results returned for the search.

13.5.6.1.2. Properties

Tabela 13.13. Zend_Service_Yahoo_ResultSet

Name Type Description
totalResultsAvailable int Total number of results found.
totalResultsReturned int Number of results in the current result set
firstResultPosition int Position of the first result in this set relative to the total number of results.

Back to Class List

13.5.6.2. Zend_Service_Yahoo_WebResultSet

Zend_Service_Yahoo_WebResultSet represents a Yahoo! Web Search result set result set.

[Nota] Nota

Zend_Service_Yahoo_WebResultSet extends Zend_Service_Yahoo_ResultSet

Back to Class List

13.5.6.3. Zend_Service_Yahoo_ImageResultSet

Zend_Service_Yahoo_ImageResultSet represents a Yahoo! Image Search result set result set.

[Nota] Nota

Zend_Service_Yahoo_ImageResultSet extends Zend_Service_Yahoo_ResultSet

Back to Class List

13.5.6.4. Zend_Service_Yahoo_LocalResultSet

Zend_Service_Yahoo_LocalResultSet represents a Yahoo! Local Search result set result set.

Tabela 13.14. Zend_Service_Yahoo_LocalResultSet Properties

Name Type Description
resultSetMapURL string The URL of a webpage containing a map graphic with all returned results plotted on it.
[Nota] Nota

Zend_Service_Yahoo_LocalResultSet extends Zend_Service_Yahoo_ResultSet

Back to Class List

13.5.6.5. Zend_Service_Yahoo_NewsResultSet

Zend_Service_Yahoo_NewsResultSet represents a Yahoo! News Search result set result set.

[Nota] Nota

Zend_Service_Yahoo_NewsResultSet extends Zend_Service_Yahoo_ResultSet

Back to Class List

13.5.6.6. Zend_Service_Yahoo_Result

Each of the search specific results is extended from this base class.

13.5.6.6.1. Properties

Tabela 13.15. Zend_Service_Yahoo_Result Properties

Name Type Description
Title string Title of the Result item
Url string The URL of the result item
ClickUrl string The URL for linking to the result item

Back to Class List

13.5.6.7. Zend_Service_Yahoo_WebResult

Each Web Search result is returned as a Zend_Service_Yahoo_WebResult object.

13.5.6.7.1. Properties

Tabela 13.16. Zend_Service_Yahoo_WebResult Properties

Name Type Description
Summary string Result summary
MimeType string Result mimetype
ModificationDate string The last modification date of the result as a UNIX timestamp.
CacheUrl string Yahoo! web cache URL for the result, if it exists.
CacheSize int The size of the Cache entry

Back to Class List

13.5.6.8. Zend_Service_Yahoo_ImageResult

Each Image Search result is returned as a Zend_Service_Yahoo_ImageResult object.

13.5.6.8.1. Properties

Tabela 13.17. Zend_Service_Yahoo_ImageResult Properties

Name Type Description
Summary string Result summary
RefererUrl string The URL of the page which contains the image
FileSize int The size of the image file in bytes
FileFormat string The format of the image (bmp, gif, jpeg, png, etc.)
Height int The height of the image
Width int The width of the image
Thumbnail Zend_Service_Yahoo_Image Image thumbnail

Back to Class List

13.5.6.9. Zend_Service_Yahoo_LocalResult

Each Local Search result is returned as a Zend_Service_Yahoo_LocalResult object.

13.5.6.9.1. Properties

Tabela 13.18. Zend_Service_Yahoo_LocalResult Properties

Name Type Description
Address string Street Address of the result
City string City in which the result resides in
State string State in which the result resides in
Phone string Phone number for the result
Rating int User submitted rating for the result
Distance float The distance to the result from your specified location
MapUrl string A URL of a map for the result
BusinessUrl string The URL for the business website, if known
BusinessClickUrl string The URL for linking to the business website, if known

Back to Class List

13.5.6.10. Zend_Service_Yahoo_NewsResult

Each News Search result is returned as a Zend_Service_Yahoo_NewsResult object.

13.5.6.10.1. Properties

Tabela 13.19. Zend_Service_Yahoo_NewsResult Properties

Name Type Description
Summary string Result summary
NewsSource string The company who distributed the article
NewsSourceUrl string The URL for the company who distributed the article
Language string The language the article is in
PublishDate string The date the article was published as a UNIX timestamp
ModificationDate string The date the article was last modified as a UNIX timestamp
Thumbnail Zend_Service_Yahoo_Image Image Thumbnail for the article, if it exists

Back to Class List

13.5.6.11. Zend_Service_Yahoo_Image

All images returned either by the Yahoo! Image Search of the Yahoo! News Search are represented by Zend_Service_Yahoo_Image objects

13.5.6.11.1. Properties

Tabela 13.20. Zend_Service_Yahoo_Image Properties

Name Type Description
Url string Image URL
Width int Image Width
Height int Image Height

Back to Class List