Skip to content

Instantly share code, notes, and snippets.

@itsbalamurali
Created November 15, 2013 07:21
Show Gist options
  • Save itsbalamurali/7480462 to your computer and use it in GitHub Desktop.
Save itsbalamurali/7480462 to your computer and use it in GitHub Desktop.
My links (url) parsing api for facebook like link details fetching
#!/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