Created
November 15, 2013 07:21
-
-
Save itsbalamurali/7480462 to your computer and use it in GitHub Desktop.
My links (url) parsing api for facebook like link details fetching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'grape' | |
require 'favico' | |
require 'metainspector' | |
require 'link_oracle' | |
module Edison | |
class API < Grape::API | |
#Response format | |
format :json | |
#errors in api format | |
rescue_from :all | |
#Default Error Format | |
default_error_formatter :json | |
#API Route | |
desc "Get brief url details." | |
#Parameters are required | |
params do | |
requires :url, type: String, desc: "Url." | |
end | |
get '/' do | |
pageurl = params[:url] | |
page = MetaInspector.new(params[:url],:allow_redirections => :all) | |
#fparser = Favico::Parser.new | |
link_data = LinkOracle.extract_from(params[:url]) | |
@url = page.url | |
@favicon = "http://g.etfv.co/#{params[:url]}" | |
@title = page.title | |
@description = page.description | |
@image = link_data.image_url | |
@thumbnail = "http://api.snapito.com/web/DOCS123/sc/#{params[:url]}" | |
{:url => @url, :favicon => @favicon , :title => @title , :description => @description , :image => @image, :thumbnail => @thumbnail} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment