Hatena::Star::Mobile - Perl extension for embedding Hatena Star into mobile sites.
use Hatena::Star::Mobile;
my $entries = [
{uri => 'http://d.hatena.ne.jp/jkondo/20080123/1201040123'},
{uri => 'http://d.hatena.ne.jp/jkondo/20080122/1200947996'},
{
uri => 'http://d.hatena.ne.jp/jkondo/20080121/1200906620',
location => 'http://d.hatena.ne.jp/jkondo/mobile', # return url to be used only for this entry
},
];
my $star_entries = Hatena::Star::Mobile->get_star_entries(
entries => $entries,
location => 'http://d.hatena.ne.jp/jkondo/mobile', # return url for add button to be used globally
color => 'gr', # color for add button
hatena_domain => 'hatena.ne.jp', # base domain name of Hatena
);
for my $se (@$star_entries) {
print $se->{star_html}; # html string for add button and stars
print $se->{uri}; # entry's uri
}The Hatena::Star::Mobile module adds Hatena Star's star ratings and "add star" buttons to your Web pages. While the HatenaStar.js, the JavaScript client implementation of Hatena Star, could be used to add Hatena Star functionality to your Web pages for modern Web browsers, most of Japanese legacy mobile Web browsers do not support or provide only limited support for JavaScript, and therefore some kind of server-side processing is preferred for better user experience. This module retrieves star rating data using Hatena Star API and returns HTML fragment representing them as sequences of HTML img elements.
The module provides the class method: get_star_entries. It receives named parameters and returns an array reference containing the result. Available input named parameters include:
add_img(Default: Auto)-
The URL of the image for the "add star" button.
color(Default:gr)-
Color variation for the "add star" button. Available values include:
bl(black),br(blue),dark(dark blue),dg(dark gray),gr(green),pr(purple),rd(red). This parameter is ignored if theadD_imgparameter is specified. entries(REQUIRED)-
The list of entries to retrieve HTMLized star rating data. Each item in the list must be hash references, which contain:
uri(REQUIRED)-
The canonical URL of the entry. It must be a normalized absolute URL reference with no non-ASCII characters.
location(Default: Same aslocationparameter for the method)-
The return URL for the "add star" button. After the user added stars to the URL, he is redirected to this URL. It must be an absolute URL reference.
get_entry_url(Default: Hatena Star entry page)-
Subroutine to obtain the URL of the anchor containing added star images. By default star images are linked to the entry page of Hatena Star Web site (for Japanese mobile phone browsers), which contains more detailed information on star added for the entry.
The value must be a
CODEreference that returns a URL. TheCODEreference would receive two arguments -$uriand$location, which are corresponding to theuriandlocationparameters specified in theentriesarray (but$locationalways has a value even whenlocationparameter was omitted). hatena_domain(Default:hatena.com)-
The domain of Hatena Web site. It must be either
hatena.comorhatena.ne.jp. For Japanese mobile phone usershatena.ne.jpdomain should be specified, as most of Japanese mobile phone users are usually accessing thehatena.ne.jpdomain. location(Default: Same as the entry URL)-
The default value for the return URL for the "add star" button. After the user added stars to the URL, he is redirected to this URL, unless it is explicitly specified for the entry in the
entriesparameter. It must be an absolute URL reference. use_http_post(Default: no)-
If a true value is specified, the HTTP
POSTmethod is used to access to Hatena Star API. This parameter is useful if you specify numbers of URLs inentriessuch that HTTPGETrequest would fail because of the length of the request-URI.
The returned array reference contains zero or more items corresponding input entries, which includes following values as hash references:
entries(If available)-
List of stars, as provided by Hatena Star API.
star_html(Always)-
The HTML fragment to embed star rating data and "add star" button into your Web page.
uri(Always)-
The URL of the entry.
- 0.05 (January 2010)
-
Added parameters
color,add_img,get_entry_url, anduse_http_postto the methodget_star_entries. Added parameterlocationto items in theentrieshashref. Added colored star support. - 0.03 (24 July 2008)
-
Added links to star entry.
- 0.02 (22 January 2008)
-
Added html of add button to empty entry.
0.01 Tue Jan 22 18:47:25 2008
- 0.01 (22 January 2008)
-
Original version; Created by h2xs 1.23 with options -X -A -n Hatena::Star::Mobile
Junya Kondo (id:jkondo), Naoya Ito (id:naoya), id:antipop, id:onishi, id:cho45, id:nanolia, id:chris4403, Wakaba (id:wakabatan) <wakabatan@hatena.ne.jp>.
Copyright (C) Hatena Inc. All Rights Reserved.
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.