Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Automatically Removed Whitespace #1

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+161 −161
Split
View
@@ -2,7 +2,7 @@
A Ruby gem for accessing the blip.tv API (http://wiki.blip.tv/index.php/REST_Upload_API)
-== Install
+== Install
gem sources -a http://gems.github.com
sudo gem install kellysutton-bliptv
@@ -15,22 +15,22 @@ While the blip.tv API is extremely simple to use, sometimes it's nice to have a
library to make life even easier. The BlipTV Ruby gem is just that.
Let's say you want to upload a video:
-
+
require 'rubygems'
require 'bliptv'
-
+
client = BlipTV::Base.new
-
+
options = {
:username => "barack_obama",
:password => "michellexoxo",
:file => File.open('movie.mov'),
:title => "Ordering Hamburgers in DC",
:description => "I love this one burger joint, but the press keeps following me."
}
-
+
video = client.upload_video(options) #=> BlipTV::Video
-
+
The upload_video method call returns a BlipTV::Video object
that you can play around with.
@@ -40,29 +40,29 @@ Or what if you wanted a list of all videos by a user? Also easy:
require 'bliptv'
client = BlipTV::Base.new
-
- video_list = client.find_all_videos_by_user("barack_obama")
-
+
+ video_list = client.find_all_videos_by_user("barack_obama")
+
find_all_videos_by_user will return a list of BlipTV::Video objects.
More usage coming soon.
-
+
== Authors
Kelly Sutton (http://michaelkellysutton.com)
== Features
Provides an easy way to interact with the blip.tv API in Ruby.
-
+
== Special Thanks
This gem is extensively based on Shane Vitrana's Viddler
gem as well as the YouTubeG gem. Much of the code was simply
copied and then tweaked to fit the blip.tv nomenclature
-of certain calls.
+of certain calls.
-== License
+== License
Copyright (c) 2009 Michael Kelly Sutton
View
@@ -1,6 +1,6 @@
#
# This is the main entry point for the library. All files in the project are
-# included here, as well as anything required across the project.
+# included here, as well as anything required across the project.
#
$:.unshift(File.dirname(__FILE__)) unless
View
@@ -6,7 +6,7 @@ class ApiSpec
:file,
:userlogin,
:password
- ],
+ ],
:optional => [
:thumbnail,
:nsfw,
@@ -17,7 +17,7 @@ class ApiSpec
:interactive_post
]
}
-
+
VIDEOS_DELETE_ATTRS = {
:required => [
:userlogin,
@@ -27,24 +27,24 @@ class ApiSpec
:username # kind of sloppy, because a user is unlikely to specify both a userlogin AND a username
]
}
-
+
def self.check_attributes(bliptv_method, attributes)
valid_attributes = bliptv_method_to_const(bliptv_method)
required = valid_attributes[:required] || Array.new
optional = valid_attributes[:optional] || Array.new
-
+
# blip calls it a "userlogin" instead of a "username"
- if attributes[:username] != nil
+ if attributes[:username] != nil
attributes[:userlogin] = attributes[:username]
attributes.delete(:username)
end
-
+
attributes.assert_valid_keys(required + optional)
attributes.assert_required_keys(required)
end
-
+
protected
-
+
def self.bliptv_method_to_const(method)
const_name = method.gsub('.', '_').upcase
const_get("#{const_name}_ATTRS")
View
@@ -16,17 +16,17 @@ def message
'This method is not yet implemented.'
end
end
-
+
#
# This is the class that should be instantiated for basic
# communication with the Blip.tv API
#
class Base
-
+
# TODO allow user to specify userlogin and password on intialize
def initialize
end
-
+
# Implements the Blip.tv REST Upload API
#
# <tt>new_attributes</tt> hash should contain next required keys:
@@ -48,18 +48,18 @@ def initialize
#
# bliptv.upload_video(:title => 'Check out this guy getting kicked in the nuts!', :file => File.open('/movies/nuts.mov'))
#
- # Returns BlipTV::Video instance.
+ # Returns BlipTV::Video instance.
#
def upload_video(new_attributes={})
BlipTV::ApiSpec.check_attributes('videos.upload', new_attributes)
-
+
new_attributes = {
:post => "1",
:item_type => "file",
:skin => "xmlhttprequest",
:file_role => "Web"
}.merge(new_attributes) # blip.tv requires the "post" param to be set to 1
-
+
request = BlipTV::Request.new(:post, 'videos.upload')
request.run do |p|
for param, value in new_attributes
@@ -69,8 +69,8 @@ def upload_video(new_attributes={})
BlipTV::Video.new(request.response['post_url'].to_s)
end
-
-
+
+
# Looks up all videos on Blip.tv with a given <tt>username</tt>
#
# Options hash could contain next values:
@@ -92,8 +92,8 @@ def find_all_videos_by_user(username, options={})
hash = Hash.from_xml(request)
hash == nil ? [] : parse_videos_list(hash)
end
-
-
+
+
# Searches through and returns videos based on the <tt>search_string</tt>.
#
# This method is a direct call of Blip.tv's search method. You get what you get. No guarantees are made.
@@ -109,13 +109,13 @@ def search_videos(search_string)
hash = Hash.from_xml(request)
parse_videos_list(hash)
end
-
+
private
-
+
def parse_videos_list(hash)
list = []
begin
- hash["response"]["payload"]["asset"].each do |entry|
+ hash["response"]["payload"]["asset"].each do |entry|
list << Video.new(entry)
end
rescue NoMethodError
@@ -2,27 +2,27 @@
class MultipartParams #:nodoc:
attr_accessor :content_type, :body
-
+
def initialize(param_hash={})
- @boundary_token = generate_boundary_token
- self.content_type = "multipart/form-data; boundary=#{@boundary_token}"
- self.body = pack_params(param_hash)
+ @boundary_token = generate_boundary_token
+ self.content_type = "multipart/form-data; boundary=#{@boundary_token}"
+ self.body = pack_params(param_hash)
end
protected
-
+
def generate_boundary_token
[Array.new(8) {rand(256)}].join
end
-
+
def pack_params(hash)
marker = "--#{@boundary_token}\r\n"
files_params = hash.find_all{|k,v| v.is_a?(File)}.to_h
text_params = hash - files_params
-
+
pack_hash(text_params, marker) + marker + pack_hash(files_params, marker) + "--#{@boundary_token}--\r\n"
end
-
+
def pack_hash(hash, marker)
hash.map do |name, value|
marker + case value
@@ -33,7 +33,7 @@ def pack_hash(hash, marker)
end
end.join('')
end
-
+
def file_to_multipart(key,file)
filename = File.basename(file.path)
mime_types = MIME::Types.of(filename)
Oops, something went wrong.