Skip to content

Instantly share code, notes, and snippets.

@reinh
Created September 12, 2008 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinh/10460 to your computer and use it in GitHub Desktop.
Save reinh/10460 to your computer and use it in GitHub Desktop.
Vimeo User REST client
require 'rubygems'
require 'activesupport'
require 'httparty'
module Vimeo
# Wrapper around the Vimeo REST service for a user.
# Usage:
# Vimeo::User.new('brad').clips.each{ |clip| p clip.embed }
#
class User
include HTTParty
base_uri 'http://vimeo.com/api/'
format :json
# Initializes a Vimeo REST client for the given +user+
def initialize(user)
@user = user
end
# Returns a collection of clips
def clips
self.class.get("#@user/clips.json").map{|clip| Clip.new(clip)}
end
# A wrapper around a vimeo clip object that provides an object oriented
# interface to the clip's properties and embed code
class Clip
TEMPLATE = <<-HTML
<object width="320" height="180"><param name="allowfullscreen"value="true">
<param name="allowscriptaccess" value="always">
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=%s&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1">
<embed src="http://vimeo.com/moogaloop.swf?clip_id=%s&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=00ADEF&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="320" height="180">
</object>
HTML
attr_reader :clip_id, :url, :title, :caption, :raw
def initialize(clip = {})
@clip_id = clip['clip_id']
@url = clip['url']
@title = clip['title']
@caption = clip['caption']
@raw = clip
end
# HTML representation of the clip for embedding in a web page
def embed; TEMPLATE % [clip_id, clip_id] end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment