{"id":13427739,"url":"https://github.com/Timrael/social_shares","last_synced_at":"2025-03-16T00:32:00.966Z","repository":{"id":21388092,"uuid":"24705794","full_name":"Timrael/social_shares","owner":"Timrael","description":"Check how many times url was shared in social networks, e.g. share counts","archived":false,"fork":false,"pushed_at":"2018-05-11T11:00:05.000Z","size":65,"stargazers_count":327,"open_issues_count":4,"forks_count":40,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-02-15T05:04:57.724Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Timrael.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-02T03:59:55.000Z","updated_at":"2025-01-02T01:08:22.000Z","dependencies_parsed_at":"2022-07-30T04:17:59.877Z","dependency_job_id":null,"html_url":"https://github.com/Timrael/social_shares","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timrael%2Fsocial_shares","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timrael%2Fsocial_shares/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timrael%2Fsocial_shares/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timrael%2Fsocial_shares/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Timrael","download_url":"https://codeload.github.com/Timrael/social_shares/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809865,"owners_count":20351403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:00:39.648Z","updated_at":"2025-03-16T00:32:00.696Z","avatar_url":"https://github.com/Timrael.png","language":"Ruby","funding_links":[],"categories":["Active Record","Ruby","模型","Social Networking"],"sub_categories":["Omniauth"],"readme":"Social Shares\n=============\n\n[![Gem Version](https://badge.fury.io/rb/social_shares.svg)](http://badge.fury.io/rb/social_shares)\n\nSocial shares is intended to easily check social sharings of an url.\n\nYou can track how many times the url was shared in various social networks, such as facebook, twitter, etc. It can be useful for some kind landings with social mechanics or for tracking network activity of your content pages.\n\nSupported networks\n------\nInternational:\n* [facebook](http://www.facebook.com/)\n* [google plus](https://plus.google.com)\n* ~~[twitter](https://twitter.com/)~~ Looking for another way, because [API have been closed officially](https://blog.twitter.com/2015/hard-decisions-for-a-sustainable-platform)\n* [reddit](http://www.reddit.com/)\n* [linkedin](https://www.linkedin.com/)\n* [pinterest](http://www.pinterest.com/)\n* [stumbleupon](http://www.stumbleupon.com/)\n* [buffer](https://bufferapp.com/)\n\nRussian:\n* [vkontakte](http://vkontakte.ru/)\n* [mail.ru(aka moi mir)](http://my.mail.ru/)\n* [odnoklassniki](http://www.odnoklassniki.ru/)\n\nChinese:\n* [weibo](http://www.weibo.com)\n\nJapanese:\n* [hatebu](http://b.hatena.ne.jp/)\n\nBasic usage\n-----\n```ruby\n:000 \u003e require 'social_shares'\n =\u003e true\n\n:000 \u003e url = 'http://www.apple.com/'\n =\u003e \"http://www.apple.com/\"\n\n:000 \u003e SocialShares.facebook url\n =\u003e 394927\n\n:000 \u003e SocialShares.google url\n =\u003e 28289\n\n:000 \u003e SocialShares.twitter url\n =\u003e 1164675\n```\nIn case of exception:\n```ruby\n:000 \u003e SocialShares.twitter url\n =\u003e nil\n\n:000 \u003e SocialShares.twitter! url\n  =\u003e RestClient::RequestTimeout: Request Timeout\n```\n\nAdvanced usage\n-----\nList of all supported networks:\n```ruby\n:000 \u003e SocialShares.supported_networks\n =\u003e [:vkontakte, :facebook, :google, :twitter, :mail_ru, :odnoklassniki, :reddit, :linkedin, :pinterest, :stumbleupon, :buffer]\n```\n\nFetch all shares by one method (#all, #all!):\n```ruby\n# in case of exception it will return nil\n:000 \u003e SocialShares.all url\n =\u003e {:vkontakte=\u003enil, :facebook=\u003e399027, :google=\u003e28346, :twitter=\u003e1836, :mail_ru=\u003e37, :odnoklassniki=\u003e1, :reddit=\u003e2361, :linkedin=\u003e33, :pinterest=\u003e21011, :stumbleupon=\u003e43035, :weibo=\u003e12760, :buffer=\u003e1662}\n\n# and this will raise it\n:000 \u003e SocialShares.all! url\n =\u003e RestClient::RequestTimeout: Request Timeout\n```\n\nFetch shares by excluding networks(#omit, #omit!):\n```ruby\n:000 \u003e SocialShares.omit url, %w(facebook)\n =\u003e { :google=\u003e28289, :linkedin=\u003enil, ... }\n\n# same here\n:000 \u003e SocialShares.omit! url, %w(facebook)\n =\u003e RestClient::RequestTimeout: Request Timeout\n```\n\nFetch shares of selected networks(#selected, #selected!):\n```ruby\n:000 \u003e SocialShares.selected url, %w(facebook google linkedin)\n =\u003e {:facebook=\u003e394927, :google=\u003e28289, :linkedin=\u003enil}\n\n# same here\n:000 \u003e SocialShares.selected! url, %w(facebook google linkedin)\n =\u003e RestClient::RequestTimeout: Request Timeout\n```\nTotal sum of sharings in selected networks:\n```ruby\n:000 \u003e SocialShares.total url, %w(facebook google)\n =\u003e 423216\n\n# Second arg is optional, by default it takes all networks\n:000 \u003e SocialShares.total url\n =\u003e 1631102\n```\nDoes any network have at least one link?\n```ruby\n:000 \u003e SocialShares.has_any? url, %w(facebook google)\n =\u003e true\n# Second arg is optional, by default it takes all networks\n:000 \u003e SocialShares.has_any? url\n =\u003e true\n```\nNote that #has_any? is faster than (#total \u003e 0), because it stops on first network that has at least 1 sharing\n\nConfiguring\n-----\nYou can specify timeout and open_timeout for each social network\n```ruby\nSocialShares.config = {\n  twitter: {timeout: 4, open_timeout: 7},\n  facebook: {timeout: 10, open_timeout: 15}\n}\n```\n\n- `:open_timeout` is the timeout for opening the connection. This is useful if you are calling servers with slow or shaky response times. Default value is 3 seconds.\n- `:timeout` is the timeout for reading the answer. This is useful to make sure you will not get stuck half way in the reading process, or get stuck reading a 5 MB file when you're expecting 5 KB of JSON. Default value is 3 seconds.\n\nIf you use Rails, you can create file `config/initializers/social_shares.rb` and fill it with this config.\n\nTry it by yourself before installation\n-----\nSend request through shell to test numbers. Please do NOT use this url in your projects.\n```bash\ncurl -X POST -d '{\"url\": \"http://www.apple.com\", \"networks\": [\"facebook\", \"google\", \"reddit\"]}' https://social-shares-api-cedar-14.herokuapp.com/\n```\nYou will see:\n```bash\n{\"facebook\":312412,\"google\":46088,\"reddit\":114}\n```\n\nInstallation\n-----\nInclude the gem in your Gemfile:\n```\ngem 'social_shares'\n```\n\nContributing\n-----\n* Create provider class in lib/social_shares/foo.rb with method #shares!, that return Integer value. #checked_url is accessed attribute.\n```ruby\nmodule SocialShares\n  class Foo \u003c Base\n    def shares!\n      response = RestClient.get(url)\n      JSON.parse(response)[\"shares\"] || 0\n    end\n\n  private\n\n    def url\n      \"http://foo.com/?url=#{checked_url}\"\n    end\n  end\nend\n```\n* Add it to lib/social_shares.rb\n```\nrequire 'social_shares/foo'\nSUPPORTED_NETWORKS = [:foo, :vkontakte, :facebook]\n```\n* Update README: add link to list, possible answer in #all method, etc.\n\nAuthor\n----\n* [Timur Kozmenko](https://twitter.com/Timrael) - timraell@gmail.com\n\nContributors\n----\n* [Hamed Ramezanian](https://github.com/iCEAGE)\n* [Ciocanel Razvan](https://github.com/Chocksy)\n* [Mehdi FARSI](https://github.com/mehdi-farsi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimrael%2Fsocial_shares","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTimrael%2Fsocial_shares","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTimrael%2Fsocial_shares/lists"}