Ever wondered how you can get the shares made for your url? Here's a ruby library that might just save and put some color to your day!
require 'open-uri'
module SocialUtils
def self.get_facebook_shares(url)
f = open("http://graph.facebook.com/?id=#{url}")
response = f.read()
shares = JSON.parse(response)['shares']
return shares.nil? ? 0 : JSON.parse(response)['shares']
end
def self.get_twitter_shares(url)
f = open("http://cdn.api.twitter.com/1/urls/count.json?url=#{url}")
return JSON.parse(f.read())['count']
end
def self.get_pinterest_shares(url)
f = open("http://api.pinterest.com/v1/urls/count.json?url=#{url}")
return JSON.parse(f.read().gsub('receiveCount(','').gsub(')',''))['count']
end
def self.get_linkedin_shares(url)
f = open("http://www.linkedin.com/countserv/count/share?url=#{url}&format=json")
return JSON.parse(f.read())['count']
end
def self.get_stumbleupon_shares(url)
f = open("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=#{url}")
response = f.read()
views = JSON.parse(response)['result']['views']
return views.blank? ? 0 : JSON.parse(response)['result']['views']
end
def self.get_googleplus_shares(url)
f = open("https://plusone.google.com/_/+1/fastbutton?url=#{URI::encode(url)}")
response = f.read()
shares = response[/window.__SSR = {c\: \d+.\d+/]
return shares.nil? ? 0 : shares[/\d+.\d+/]
end
end
See original gist here: https://gist.github.com/maricris-sn/7082858
Author
Maricris Nonato
I turn tech ideas into websites using Ruby. I'm a budding Buddhist practitioner, passionate about health & fitness, a certified yoga teacher, and a cat fanatic!
Recent posts
Tags
- cats
- yoga
- blood pressure
- elecom
- scrum
- coderkitty
- RailsGirls
- workstation
- creativity
- live book signing
- healthy living
- lowering blood pressure
- crafting
- movies
- reviews
- new year
- blessings
- faith
- quotes to live by
- travelers notebook
- Bujo
- planners
- Monday Motivation
- himalayan salt lamp
- productivity
- life tips
- happiness
- success
- ruby
- digital ocean
- regex
- programming
- humor
- music
- pyromusical
- sphinx
- mac
- games
- musings
- yogi
- namaste
- photography
- hobby
- slimming
- sendmail
- lifestyle
- memes
- open letter
- sports
- shooting
- events
- meetups
- tech talks
- rails
- datatables
- sorting
- cycling
- COVID-19
- wishlist
- xmas
- tradition
- song lyrics
- life lessons
- poems
- short story
- food
- living life
- nginx
- technology
- youtube
- my Nyey
- meditation
- new normal
- jump rope
- two-wheel journey
- planner girl
- rubyist
- culture
- Filipino
- mental health
- counseling
- self-care
Advertise
Advertise here
Newsletter
Instagram Feed
Links
I'm sharing with you P150 gift from GoFutureFresh! Click here to accept my gift.