root/platform/tdiary/plugin/pathtraq_counter.rb @ 37273

Revision 35980, 0.9 kB (checked in by hsbt, 3 years ago)

change logger.

Line 
1# pathtraq_counter.rb $Revision 1.0 $
2#
3# Copyright (c) 2008 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
4# You can redistribute it and/or modify it under GPL2.
5#
6
7require 'timeout'
8require 'open-uri'
9begin
10        require 'json'
11rescue
12        retry if require 'rubygems'
13end
14
15def call_pathtraq_json( url, mode )
16        json = nil
17        begin
18                timeout(10) do
19                        open( "http://api.pathtraq.com/page_counter?api=json&url=#{url}&m=#{mode}" ) do |f|
20                                json = JSON.parse( f.read )
21                        end
22                end
23        rescue => e
24                @logger.debug( e )
25        end
26        return json
27end
28
29def pathtraq_counter
30        url = @conf.base_url
31        mode = ['popular', 'hot', 'upcoming']
32
33        r = %Q|<ul>\n|
34        begin
35                mode.each do |m|
36                        json = call_pathtraq_json( url, m )
37                        r << %Q|<li>#{m}: #{json["count"]} hits</li>\n| unless json.nil?
38                end
39        rescue => e
40                @logger.debug( e )
41        end
42        r << %Q|</ul>\n|
43        r << %Q|<div class="iddy"><span class="iddy-powered">Powered by <a href="http://pathtraq.com/">Pathtraq</a></span></div>\n|
44
45        return r
46end
Note: See TracBrowser for help on using the browser.