Skip to content

Instantly share code, notes, and snippets.

View dokipen's full-sized avatar

Bob Corsaro dokipen

  • Medium.com
  • Newburyport, MA
View GitHub Profile
%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
(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
$:.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
@dokipen
dokipen / hn_parsing.rb
Created January 31, 2011 21:21
Parse Hacker News front page.
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,
@dokipen
dokipen / embedly-preview-store.rb
Created February 1, 2011 16:50
AR to store previews.
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
@dokipen
dokipen / kalimba-index.rb
Created February 1, 2011 17:01
Index Controller
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
@dokipen
dokipen / create_embed.rb
Created February 1, 2011 17:06
Create Embedly embed
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
@dokipen
dokipen / shareaholic-config.rb
Created February 1, 2011 17:16
Shareaholic 4 Publishers config
script do
self <<<<-"END"
jQuery(document).ready(function($) {
if (typeof(SHR4P) == 'undefined') {
SHR4P = {};
}
SHR4P.onready = function() {
SHR4P.jQuery('.shr').shareaholic_publishers({
mode: 'inject',
showShareCount: true,
@dokipen
dokipen / rss_embed.rb
Created February 3, 2011 16:02
Template for Atom embed in Kalimba
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"
@dokipen
dokipen / kalimba_atom.rb
Created February 3, 2011 16:04
Atom xml generation in Kalimba
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',