{"id":20020999,"url":"https://github.com/sergeypedan/social-nets-db","last_synced_at":"2025-03-02T03:33:44.741Z","repository":{"id":56896375,"uuid":"434400884","full_name":"sergeypedan/social-nets-db","owner":"sergeypedan","description":"A non-comprehensive database of social nets packed in a Ruby gem","archived":false,"fork":false,"pushed_at":"2024-03-30T02:08:35.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-13T01:31:37.888Z","etag":null,"topics":["gem","ruby","social-network"],"latest_commit_sha":null,"homepage":"https://sergeypedan.ru/open_source_projects/social-nets-db","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/sergeypedan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-02T23:03:43.000Z","updated_at":"2022-06-18T10:17:45.000Z","dependencies_parsed_at":"2024-03-30T03:20:44.501Z","dependency_job_id":"c6de308c-3326-4ddd-846d-0264114a7030","html_url":"https://github.com/sergeypedan/social-nets-db","commit_stats":{"total_commits":128,"total_committers":1,"mean_commits":128.0,"dds":0.0,"last_synced_commit":"82d3000c7100bb0b8357f5db2041ac3563570410"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeypedan%2Fsocial-nets-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeypedan%2Fsocial-nets-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeypedan%2Fsocial-nets-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergeypedan%2Fsocial-nets-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergeypedan","download_url":"https://codeload.github.com/sergeypedan/social-nets-db/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241454606,"owners_count":19965411,"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":["gem","ruby","social-network"],"created_at":"2024-11-13T08:35:13.505Z","updated_at":"2025-03-02T03:33:44.722Z","avatar_url":"https://github.com/sergeypedan.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Social nets DB\n\n[![Gem Version](https://badge.fury.io/rb/social_nets_db.svg)](https://badge.fury.io/rb/social_nets_db)\n\n## Installation\n\n```ruby\ngem \"social_nets_db\"\n```\n\n\n## Internals\n\nIt stores data about popular social nets, video hostings etc. in a YAML file [`db.yml`](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_nets_db/db.yml):\n\n```yaml\nbehance:\n  name: Behance\n  icons:\n    font_awesome_4: behance\n  color: \"#1769ff\"\n  domain: behance.com\n  tags:\n    - art\n    - design\n    - recruiting\n  profile_url:\n    by_username: \"https://${domain}/${uid}\"\n    by_account_id: \"https://${domain}/${uid}\"\n```\n\nEverything else is just helpers around this simple DB: finders, accessors \u0026 view helpers.\n\n\n## Usage\n\nThere are 2 primary use cases for this gem:\n\n### 1. To help create lists of links to social net accounts\n\nLike in the footer of a website:\n\n```ruby\nruby:\n  accounts = [\n    { net_uid: \"instagram\", username: \"dhh\" },\n    { net_uid: \"facebook\",  username: \"d-h-h\" },\n    { net_uid: \"twitter\",   username: \"d_h_h\" },\n    { net_uid: \"upwork\",    account_id: \"401298374012374\" },\n    { net_uid: \"email\",     username: \"elon@musk.io\" },\n    { net_uid: \"website\",   username: \"musk.io\" }\n  ]\n\nul\n  - accounts.each do |account|\n    - net = SocialNetsDB::SocialNet.find account[:net_uid]\n    li\n      - fa_icon_uid = net.icons[\"font_awesome_4\"] || \"link\"\n      = fa_icon fa_icon_uid, class: \"fw\", style: \"color: #{net.color}\"\n      =\u003c link_to net.name, \\\n                 net.user_page(username: account[:username], account_id: account[:account_id]), \\\n                 target: \"_blank\", rel: \"noopener noreferrer\"\n```\n\nHere the gem:\n\n- builds the URL to user page\n\n\t```ruby\n\tnet.user_page(username: account[:username]) #=\u003e \"https://facebook.com/dhh\"\n\t```\n\n- gives you the correct name of the social net\n\n\t```ruby\n\tnet.name #=\u003e \"Facebook\"\n\t```\n\n### 2. To help building a `\u003cselect\u003e` with social nets when storing user's account link\n\n```ruby\n= form_for @user do |f|\n  = f.fields_for :social_net_accounts do |sna|\n    .form-group\n      = sna.label  :social_net_uid, class: \"control-label\"\n      = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: \"form-control\"\n```\n\nwhich produces\n\n```html\n\u003cform action=\"/users\" method=\"POST\"\u003e\n  \u003cdiv class=\"form-group\"\u003e\n    \u003clabel for=\"user_social_net_accounts_attributes_123_social_net_uid\"\u003eSocial net UID\u003c/label\u003e\n    \u003cselect required=\"required\" class=\"form-control\" name=\"user[social_net_accounts_attributes][123][social_net_uid]\"\u003e\n      \u003coption value=\"\"\u003eChoose a social net:\u003c/option\u003e\n      \u003coption value=\"behance\"\u003eBehance\u003c/option\u003e\n      \u003coption value=\"dribble\"\u003eDribble\u003c/option\u003e\n      \u003coption value=\"facebook\"\u003eFacebook\u003c/option\u003e\n      \u003c!-- ... --\u003e\n    \u003c/select\u003e\n  \u003c/div\u003e\n\u003c/form\u003e\n```\n\nSee section “[Using with Rails](#use-with-rails)” below for more details.\n\n\n## API\n\n### Find a social net record\n\nUse either one:\n\n```ruby\nsocial_net = SocialNetsDB::SocialNet.find(\"facebook\")\nsocial_net = SocialNetsDB::SocialNet.find_by(uid: \"facebook\")\nsocial_net = SocialNetsDB::SocialNet.find_by_uid(\"facebook\")\n# =\u003e #\u003cSocialNetsDB:0x00007fddc0041b40 @uid=\"facebook\"\u003e\n```\n\nWhich are supported UIDs?\n\n```ruby\nSocialNetsDB::SocialNet.uids\n#=\u003e [\n#    \"behance\",\n#    \"dribble\",\n#    \"facebook\",\n#    \"fl.ru\",\n#    \"freelansim\",\n#    \"habr\",\n#    \"github\",\n#    \"instagram\",\n#    ...\n#  ]\n```\n\n### Data\n\n```ruby\nsocial_net.to_h #=\u003e\n# {\n#   \"name\"   =\u003e \"Facebook\",\n#   \"icons\"  =\u003e { \"font_awesome_4\" =\u003e \"facebook\" },\n#   \"color\"  =\u003e \"#3C5A99\",\n#   \"domain\" =\u003e \"facebook.com\",\n#   \"tags\"   =\u003e [\"social net\"],\n#   \"profile_url\" =\u003e {\n#     \"by_username\"   =\u003e \"https://${domain}/${uid}\",\n#     \"by_account_id\" =\u003e \"https://${domain}/${uid}\"\n#   }\n# }\n```\n\n### Property accessors\n\n```ruby\nsocial_net.color  #=\u003e \"#3C5A99\"\nsocial_net.name   #=\u003e \"Facebook\"\nsocial_net.uid    #=\u003e \"facebook\"\nsocial_net.domain #=\u003e \"facebook.com\"\nsocial_net.url    #=\u003e \"https://facebook.com\"\nsocial_net.icons  #=\u003e { \"font_awesome_4\" =\u003e \"facebook\" }\n```\n\n### FontAwesome icon\n\n```ruby\nsocial_net.icons[\"font_awesome_4\"] #=\u003e \"facebook\"\n```\n\nCurrently, only FontAwesome v4 icons are store. I plan adding newer version of FA, maybe other icon providers, and also SVGs.\n\n### User's page URL\n\n```ruby\nsocial_net.user_page(username: \"dhh\")              #=\u003e \"https://facebook.com/dhh\"\nsocial_net.user_page(account_id: \"id1234566789\")   #=\u003e \"https://facebook.com/account/id1234566789\"\n```\n\nIf you pass a username, while the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.\n\nYou can check which is supported\n\n```ruby\nsocial_net.user_page_methods  #=\u003e [:account_id, :username]\n```\n\n\n## Use with Rails\n\nThis gem is Rails-agnostic, but you can use it in Rails like so:\n\n### Forms\n\n```ruby\n= form_for @user do |f|\n  = f.fields_for :social_net_accounts do |sna|\n    .form-group\n      = sna.label  :social_net_uid, class: \"control-label\"\n      = sna.select :social_net_uid, SocialNetsDB::SocialNet.values_for_select, {}, class: \"form-control\"\n```\n\nbecause\n\n```ruby\nSocialNetsDB::SocialNet.values_for_select\n#=\u003e [\n#     [\"Behance\",       \"behance\"],\n#     [\"Dribble\",       \"dribble\"],\n#     [\"Facebook\",      \"facebook\"],\n#     [\"GitHub\",        \"github\"],\n#     [\"Instagram\",     \"instagram\"],\n#     [\"LiveJournal\",   \"livejournal\"],\n#     [\"LinkedIn\",      \"linkedin\"],\n#     [\"Medium\",        \"medium\"],\n#     [\"Мой мир\",       \"my.mail.ru\"],\n#     [\"Одноклассники\", \"odnoklassniki\"],\n#     [\"StackOverflow\", \"stackoverflow\"],\n#     [\"Telegram\",      \"telegram\"],\n#     [\"Twitter\",       \"twitter\"],\n#     [\"Вконтакте\",     \"vkontakte\"],\n#     [\"YouTube\",       \"youtube\"]\n#  ]\n```\n\n### Models\n\n```ruby\nmodel User \u003c ApplicationRecord\n  has_many :social_net_accounts\nend\n```\n\nThis would be a standard approach:\n\n```ruby\n# model SocialNet \u003c ApplicationRecord\n#   has_many :social_net_accounts\n# end\n```\n\nbut instead we will use `SocialNetsDB::SocialNet` class instead of an ActiveRecord class:\n\n```ruby\nSocialNetsDB::SocialNet.find(\"facebook\")\nSocialNetsDB::SocialNet.find_by(uid: \"facebook\")\n```\n\n```ruby\nmodel SocialNetAccount \u003c ApplicationRecord\n  belongs_to :user\n\n  validates :account_id,     presence: true, if: Proc.new { |record| record.username.blank? }\n  validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB::SocialNet.uids }\n  validates :username,       presence: true, if: Proc.new { |record| record.account_id.blank? }\n\n  def social_net\n    @social_net ||= SocialNetsDB::SocialNet.find(self.social_net_uid)\n  end\n\n  def user_page\n    social_net.user_page(username: self.username, account_id: self.account_number)\n  end\n\n  #  id              :bigint  not null, primary key\n  #  user_id         :bigint  not null\n  #  account_id      :string            example: `id1230948712034871`\n  #  social_net_uid  :string  not null  example: `facebook`, `vkontakte`\n  #  username        :string            example, `tenderlove`\n  #  userpic_url     :string\nend\n```\n\nIt's probably better to move those 2 methods into a decorator — here they are in the model just for brevity.\n\n```ruby\nSocialNetAccount.create(user_id: User.first.id, social_net_uid: \"facebook\", username: \"tenderlobe\")\n```\n\n```ruby\n@user.social_net_accounts.first.user_page  #=\u003e \"https://facebook.com/tenderlove\"\n```\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeypedan%2Fsocial-nets-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergeypedan%2Fsocial-nets-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeypedan%2Fsocial-nets-db/lists"}