Created
April 1, 2013 15:10
-
-
Save valachi/5285463 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module LikesCounter | |
| delegate :escape, to: URI | |
| delegate :get, to: RestClient | |
| def url | |
| Rails.application.routes.url_helpers.article_url(self, host: 'hungryshark.ru') | |
| end | |
| def total_likes | |
| tw_total + fb_total + vk_total | |
| end | |
| def tw_total | |
| JSON(tw_raw)['count'] | |
| end | |
| def fb_total | |
| puts url | |
| JSON(fb_raw).first['total_count'] | |
| end | |
| def vk_total | |
| vk_raw.force_encoding("windows-1251")[/var counter = (\d+)/, 1].to_i | |
| end | |
| private | |
| def tw_raw | |
| get escape "http://urls.api.twitter.com/1/urls/count.json?url=#{url}&callback=?" | |
| end | |
| def fb_raw | |
| get escape "https://api.facebook.com/method/fql.query?query=select | |
| total_count from link_stat where url=\"#{url}\"&format=json" | |
| end | |
| def vk_raw | |
| get escape "http://vk.com/widget_like.php?app=3123597&url=#{url}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment