Skip to content

Instantly share code, notes, and snippets.

@audreyt
Created September 14, 2012 12:45
Show Gist options
  • Select an option

  • Save audreyt/3721712 to your computer and use it in GitHub Desktop.

Select an option

Save audreyt/3721712 to your computer and use it in GitHub Desktop.
Test
Simply run:
npm i
./main.js
#!/usr/bin/env node
var express = require('express'),
restler = require('restler'),
url = require('url');
var app = express();
// oembed only comes in xml or json and we're ignoring xml
app.get('/oembed.json', function(req, res){
var urlRequested = req.query.url;
var parsed = url.parse(urlRequested);
parsed.pathname = parsed.pathname.replace(
RegExp("^/([^/]+)/([^/]+)"), "/data/workspaces/$1/pages/$2"
);
parsed.query = { accept: "application/json", xhtml: 1 };
restler.get(url.format(parsed))
.on('complete', function(data) {
var oembedObject = {
"version": "1.0",
"type": "rich",
"title": data.metadata.Subject,
"url": data.page_uri,
"author_url": "https://www.socialtext.net/st/profile/" + data.creator_id,
"provider_name": "Socialtext",
"provider_url": "http://socialtext.com",
"width": 500,
"height": null,
"html": data.xhtml
};
res.json(oembedObject);
});
});
app.listen(3000);
console.log("Please connect to:\nhttp://localhost:3000/oembed.json?url=https://www.socialtext.net/perl5/contributing_to_cpan");
#!/usr/bin/env ./node_modules/LiveScript/bin/livescript
express = require \express
restler = require \restler
URL = require \url
app = express!
# oembed only comes in xml or json and we're ignoring xml
app.get \/oembed.json ({query: {url}}, res) ->
parsed = URL.parse(url)
parsed.pathname.=replace(
// ^/([^/]+)/([^/]+) //
'/data/workspaces/$1/pages/$2'
)
parsed.query =
accept: \application/json
xhtml: 1
data <- restler.get(URL.format(parsed)).on \complete
{metadata: {Subject}, page_uri, creator_id, xhtml} = data
res.json do
version: 1.0
type: \rich
title: Subject
url: page_uri
author_url: "https://www.socialtext.net/st/profile/#creator_id"
provider_name: \Socialtext
provider_url: \http://socialtext.com
width: 500
height: null
html: xhtml
app.listen 3000
console.log """
Please connect to:
http://localhost:3000/oembed.json?url=https://www.socialtext.net/perl5/contributing_to_cpan
"""
{ "name": "test"
, "description": "oEmbed server for Socialtext Wiki"
, "version": "0.1.1"
, "dependencies": {
"restler": "*",
"express": "*",
"LiveScript": "*"}
, "main": "main"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment