Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (26 sloc) 0.744 kb
require "rubygems"
require "bundler/setup"
Bundler.require(:default)
require "active_support/cache"
class Watme < Sinatra::Base
def wats
connection = Faraday.new(:url => 'http://knowyourmeme.com/memes/wat/photos?sort=score') do |conn|
conn.response :caching do
ActiveSupport::Cache::FileStore.new 'tmp/cache', :namespace => 'faraday', :expires_in => 3600
end
conn.adapter Faraday.default_adapter
end
response = connection.get
doc = Nokogiri::HTML(response.body)
doc.css("a.photo:not(.left) img").map{|img| {"wat" => img["src"].gsub("masonry", "newsfeed")}}
end
before do
content_type :json
end
get '/' do
wats.to_json
end
get '/random' do
wats.sample.to_json
end
end
Jump to Line
Something went wrong with that request. Please try again.