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
%w{oembed pp}.each{|m|require m} | |
KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
EmbedlyPro = OEmbed::Provider.new("http://pro.embed.ly/v1/api/oembed") | |
response = EmbedlyPro.get("http://blog.embed.ly", {:key => KEY}) | |
pp response |
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
(embedly)15:44:55 [doki_pen@wilkenfeld ~/src/embedly-ruby][master]$ cucumber | |
Using the default profile... | |
Feature: OEmbed | |
As an embedly user | |
I want to call the the embedly api | |
Because I want and oembed for a specific url | |
Scenario Outline: Get the provider_url # features/oembed.feature:7 | |
Given an embedly endpoint # features/steps/api_steps.rb:4 |
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
$:.unshift(File.expand_path('../../../lib',__FILE__)) | |
require 'embedly' | |
Given /an embedly endpoint( [^\s]+)?( with ([^\s]+) key)?$/ do |endpoint, _, key| | |
opts = {} | |
opts[:endpoint] = endpoint | |
opts[:key] = key | |
@api = Embedly::API.new opts | |
end |
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
class Update < R '/update' | |
def get | |
articles = [] | |
doc = Hpricot(open('http://news.ycombinator.com/')) | |
(doc/'.subtext/..').each do |subtext| | |
article = subtext.previous_node | |
articles << { | |
:rank => | |
article.at('.title').inner_html.strip, |
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
class Preview < Base | |
def self._key url | |
Digest::SHA1.hexdigest(url) | |
end | |
def self.key_exists? url | |
find_redirect(url) or find_preview(url) | |
end |
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
class Index | |
def get | |
@articles = [] | |
Article::find(:all, :order => 'id').each do |a| | |
preview_row = Preview.find_preview( | |
Article.normalize_url(a.link)) | |
if preview_row | |
preview = OpenStruct.new( | |
JSON.parse(preview_row.value)) | |
end |
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
def _content article, preview | |
div.embedly_title do | |
a article.title, :target => '_blank', | |
:href => preview.original_url, | |
:title => preview.url | |
end | |
case preview.type | |
when 'image' | |
a.embedly_thumbnail(:href => preview.original_url) do |
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
def _content preview | |
case preview.type | |
when 'image' | |
a.embedly_thumbnail(:href => preview.original_url) do | |
img.thumbnail :src => preview.url, | |
:alt => 'goto article' | |
end | |
when 'video' | |
video.embedly_video :src => preview.url, | |
:controls => "controls", :preload => "preload" |
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
def _rss | |
if @last_update | |
self << @b.feed( | |
'xmlns' => 'http://www.w3.org/2005/Atom') do |f| | |
f.title 'Kalimba' | |
f.link :href => CONFIG[:canonical_url] | |
id = CONFIG[:canonical_url] | |
id = "#{id}/" unless id.end_with?'/' | |
f.id id | |
f.link :rel => 'self', :type => 'application/atom+xml', |