0.0
No commit activity in last 3 years
No release in over 3 years
Parse social media attributes from url or construct url from attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

 Project Readme

SocialParser

SocialParser

Parse social media attributes from url or construct url from attributes.

Supported provider

[:facebook, :github, :instagram, :github, :google, :linkedin, :medium, :pinterest, :qiita, :twitter, :vimeo, :youtube]

Installation

Add this line to your application's Gemfile:

gem 'social_parser'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install social_parser

Usage

The following code is an example of Twitter.

parser = SocialParser.parse 'https://www.twitter.com/hyde141421356'
=> #<SocialParser::Provider::Twitter:0x007fc57720a690 @url="https://www.twitter.com/hyde141421356">

parser.username
=> 'hyde141421356'

parser.provider
=> :twitter

parser.url
=> 'https://www.twitter.com/hyde141421356'

Facebook, Google+, LinkedIn, etc... as well.

parser = SocialParser.parse 'https://github.com/hyde2able'
=> #<SocialParser::Provider::Github:0x007fc5771e3c98 @url="https://github.com/hyde2able">

parser.username
=> 'hyde2able'

parser.provider
=> :github

parser.url
=> 'https://github.com/hyde2able'

An example of Youtube.

parser = SocialParser.parse 'https://www.youtube.com/watch?v=WOvdMz4yM9U'
=> #<SocialParser::Provider::Youtube:0x007faa5e26fd58 @url="https://www.youtube.com/watch?v=WOvdMz4yM9U", @type="video">

parser.id # alias parser.username
=> 'WOvdMz4yM9U'

parser.embed_url
=> 'https://www.youtube.com/embed/WOvdMz4yM9U'

When an embedded URL is not provided

parser = SocialParser.parse 'https://github.com/hyde2able'
=> #<SocialParser::Provider::Github:0x007faa5e06d7a8 @url="https://github.com/hyde2able">

parser.embed_url
# SocialParser::InvalidURIError: SocialParser::InvalidURIError

Test

Excute this code

bundle exec rspec

License

The gem is available as open source under the terms of the MIT License.