Class: Chomchom::SocialAnalytics
- Inherits:
-
Object
- Object
- Chomchom::SocialAnalytics
- Defined in:
- lib/chomchom/social_analytics.rb
Instance Method Summary collapse
-
#backtweets ⇒ Object
they need key, no commercial use www.backtype.com/developers.
-
#bitly ⇒ Object
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/clicks need the shorten url and a key (free signup).
- #delicious ⇒ Object
- #digg ⇒ Object
- #facebook ⇒ Object
-
#facebook_more ⇒ Object
this breaks down the counts and possibly allow multiple urls.
- #google_buzz ⇒ Object
- #initialize(url) ⇒ SocialAnalytics constructor
- #linkedin ⇒ Object
- #stumbleupon ⇒ Object
- #twitter ⇒ Object
Constructor Details
#initialize(url) ⇒ SocialAnalytics
10 11 12 13 14 |
# File 'lib/chomchom/social_analytics.rb', line 10 def initialize(url) @url = url @agent = Mechanize.new @agent.user_agent = "chomchom social analytics" end |
Instance Method Details
#backtweets ⇒ Object
they need key, no commercial use www.backtype.com/developers
102 103 104 |
# File 'lib/chomchom/social_analytics.rb', line 102 def backtweets "http://backtweets.com/search.json?q=http://news.ycombinator.com/&key=key" end |
#bitly ⇒ Object
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/clicks need the shorten url and a key (free signup)
96 97 98 |
# File 'lib/chomchom/social_analytics.rb', line 96 def bitly end |
#delicious ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/chomchom/social_analytics.rb', line 54 def delicious begin @agent.get("http://feeds.delicious.com/v2/json/urlinfo/#{Digest::MD5.hexdigest(@url)}") json = JSON.parse(@agent.page.body)[0] #puts tags = json['top_tags'] delicious = json['total_posts'] rescue 0 end end |
#digg ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/chomchom/social_analytics.rb', line 45 def digg begin @agent.get("http://widgets.digg.com/buttons/count?url=#{@url}") digg = JSON.parse(@agent.page.body.match(/\{.*?\}/)[0])['diggs'] rescue 0 end end |
#facebook ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/chomchom/social_analytics.rb', line 16 def facebook begin @agent.get("http://graph.facebook.com/#{@url}") facebook = JSON.parse(@agent.page.body)['shares'] rescue 0 end end |
#facebook_more ⇒ Object
this breaks down the counts and possibly allow multiple urls
26 27 28 29 30 31 32 33 34 |
# File 'lib/chomchom/social_analytics.rb', line 26 def facebook_more @agent.get("http://api.ak.facebook.com/restserver.php?v=1.0&method=links.getStats&urls=#{@url}&format=json") json = JSON.parse(@agent.page.body) share_count = json['share_count'] like_count = json['like_count'] comment_count = json['comment_count'] total_count = json['total_count'] #same as above click_count = json['click_count'] end |
#google_buzz ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chomchom/social_analytics.rb', line 74 def google_buzz begin @agent.get("http://www.googleapis.com/buzz/v1/activities/count?alt=json&url=#{@url}") google_buzz = JSON.parse(@agent.page.body)['data']['counts'][@url][0]['count'] #check multiple sites #"https://www.googleapis.com/buzz/v1/activities/count?alt=json&url=http://news.ycombinator.com&url=http://www.techcrunch.com&url=http://www.cnn.com" rescue 0 end end |
#linkedin ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/chomchom/social_analytics.rb', line 85 def linkedin begin @agent.get("http://www.linkedin.com/cws/share-count?url=#{@url}") linkedin = JSON.parse(@agent.page.body.match(/\{.*?\}/)[0])['count'] rescue 0 end end |
#stumbleupon ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/chomchom/social_analytics.rb', line 65 def stumbleupon begin @agent.get("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=#{@url}") stumbleupon = JSON.parse(@agent.page.body)['result']['views'] rescue 0 end end |
#twitter ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/chomchom/social_analytics.rb', line 36 def twitter begin @agent.get("http://urls.api.twitter.com/1/urls/count.json?url=#{@url}") twitter = JSON.parse(@agent.page.body)['count'].to_i rescue 0 end end |