Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Removed Whitespace #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


A Ruby gem for accessing the blip.tv API (http://wiki.blip.tv/index.php/REST_Upload_API) 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 gem sources -a http://gems.github.com
sudo gem install kellysutton-bliptv sudo gem install kellysutton-bliptv
Expand All @@ -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. library to make life even easier. The BlipTV Ruby gem is just that.


Let's say you want to upload a video: Let's say you want to upload a video:

require 'rubygems' require 'rubygems'
require 'bliptv' require 'bliptv'

client = BlipTV::Base.new client = BlipTV::Base.new

options = { options = {
:username => "barack_obama", :username => "barack_obama",
:password => "michellexoxo", :password => "michellexoxo",
:file => File.open('movie.mov'), :file => File.open('movie.mov'),
:title => "Ordering Hamburgers in DC", :title => "Ordering Hamburgers in DC",
:description => "I love this one burger joint, but the press keeps following me." :description => "I love this one burger joint, but the press keeps following me."
} }

video = client.upload_video(options) #=> BlipTV::Video video = client.upload_video(options) #=> BlipTV::Video

The upload_video method call returns a BlipTV::Video object The upload_video method call returns a BlipTV::Video object
that you can play around with. that you can play around with.


Expand All @@ -40,29 +40,29 @@ Or what if you wanted a list of all videos by a user? Also easy:
require 'bliptv' require 'bliptv'


client = BlipTV::Base.new 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. find_all_videos_by_user will return a list of BlipTV::Video objects.


More usage coming soon. More usage coming soon.

== Authors == Authors


Kelly Sutton (http://michaelkellysutton.com) Kelly Sutton (http://michaelkellysutton.com)


== Features == Features


Provides an easy way to interact with the blip.tv API in Ruby. Provides an easy way to interact with the blip.tv API in Ruby.

== Special Thanks == Special Thanks


This gem is extensively based on Shane Vitrana's Viddler This gem is extensively based on Shane Vitrana's Viddler
gem as well as the YouTubeG gem. Much of the code was simply gem as well as the YouTubeG gem. Much of the code was simply
copied and then tweaked to fit the blip.tv nomenclature copied and then tweaked to fit the blip.tv nomenclature
of certain calls. of certain calls.


== License == License


Copyright (c) 2009 Michael Kelly Sutton Copyright (c) 2009 Michael Kelly Sutton


Expand Down
2 changes: 1 addition & 1 deletion lib/bliptv.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
# #
# This is the main entry point for the library. All files in the project are # 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 $:.unshift(File.dirname(__FILE__)) unless
Expand Down
16 changes: 8 additions & 8 deletions lib/bliptv/api_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApiSpec
:file, :file,
:userlogin, :userlogin,
:password :password
], ],
:optional => [ :optional => [
:thumbnail, :thumbnail,
:nsfw, :nsfw,
Expand All @@ -17,7 +17,7 @@ class ApiSpec
:interactive_post :interactive_post
] ]
} }

VIDEOS_DELETE_ATTRS = { VIDEOS_DELETE_ATTRS = {
:required => [ :required => [
:userlogin, :userlogin,
Expand All @@ -27,24 +27,24 @@ class ApiSpec
:username # kind of sloppy, because a user is unlikely to specify both a userlogin AND a username :username # kind of sloppy, because a user is unlikely to specify both a userlogin AND a username
] ]
} }

def self.check_attributes(bliptv_method, attributes) def self.check_attributes(bliptv_method, attributes)
valid_attributes = bliptv_method_to_const(bliptv_method) valid_attributes = bliptv_method_to_const(bliptv_method)
required = valid_attributes[:required] || Array.new required = valid_attributes[:required] || Array.new
optional = valid_attributes[:optional] || Array.new optional = valid_attributes[:optional] || Array.new

# blip calls it a "userlogin" instead of a "username" # blip calls it a "userlogin" instead of a "username"
if attributes[:username] != nil if attributes[:username] != nil
attributes[:userlogin] = attributes[:username] attributes[:userlogin] = attributes[:username]
attributes.delete(:username) attributes.delete(:username)
end end

attributes.assert_valid_keys(required + optional) attributes.assert_valid_keys(required + optional)
attributes.assert_required_keys(required) attributes.assert_required_keys(required)
end end

protected protected

def self.bliptv_method_to_const(method) def self.bliptv_method_to_const(method)
const_name = method.gsub('.', '_').upcase const_name = method.gsub('.', '_').upcase
const_get("#{const_name}_ATTRS") const_get("#{const_name}_ATTRS")
Expand Down
26 changes: 13 additions & 13 deletions lib/bliptv/base.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ def message
'This method is not yet implemented.' 'This method is not yet implemented.'
end end
end end

# #
# This is the class that should be instantiated for basic # This is the class that should be instantiated for basic
# communication with the Blip.tv API # communication with the Blip.tv API
# #
class Base class Base

# TODO allow user to specify userlogin and password on intialize # TODO allow user to specify userlogin and password on intialize
def initialize def initialize
end end

# Implements the Blip.tv REST Upload API # Implements the Blip.tv REST Upload API
# #
# <tt>new_attributes</tt> hash should contain next required keys: # <tt>new_attributes</tt> hash should contain next required keys:
Expand All @@ -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')) # 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={}) def upload_video(new_attributes={})
BlipTV::ApiSpec.check_attributes('videos.upload', new_attributes) BlipTV::ApiSpec.check_attributes('videos.upload', new_attributes)

new_attributes = { new_attributes = {
:post => "1", :post => "1",
:item_type => "file", :item_type => "file",
:skin => "xmlhttprequest", :skin => "xmlhttprequest",
:file_role => "Web" :file_role => "Web"
}.merge(new_attributes) # blip.tv requires the "post" param to be set to 1 }.merge(new_attributes) # blip.tv requires the "post" param to be set to 1

request = BlipTV::Request.new(:post, 'videos.upload') request = BlipTV::Request.new(:post, 'videos.upload')
request.run do |p| request.run do |p|
for param, value in new_attributes for param, value in new_attributes
Expand All @@ -69,8 +69,8 @@ def upload_video(new_attributes={})


BlipTV::Video.new(request.response['post_url'].to_s) BlipTV::Video.new(request.response['post_url'].to_s)
end end


# Looks up all videos on Blip.tv with a given <tt>username</tt> # Looks up all videos on Blip.tv with a given <tt>username</tt>
# #
# Options hash could contain next values: # Options hash could contain next values:
Expand All @@ -92,8 +92,8 @@ def find_all_videos_by_user(username, options={})
hash = Hash.from_xml(request) hash = Hash.from_xml(request)
hash == nil ? [] : parse_videos_list(hash) hash == nil ? [] : parse_videos_list(hash)
end end


# Searches through and returns videos based on the <tt>search_string</tt>. # 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. # This method is a direct call of Blip.tv's search method. You get what you get. No guarantees are made.
Expand All @@ -109,13 +109,13 @@ def search_videos(search_string)
hash = Hash.from_xml(request) hash = Hash.from_xml(request)
parse_videos_list(hash) parse_videos_list(hash)
end end

private private

def parse_videos_list(hash) def parse_videos_list(hash)
list = [] list = []
begin begin
hash["response"]["payload"]["asset"].each do |entry| hash["response"]["payload"]["asset"].each do |entry|
list << Video.new(entry) list << Video.new(entry)
end end
rescue NoMethodError rescue NoMethodError
Expand Down
18 changes: 9 additions & 9 deletions lib/bliptv/multipart_params.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@


class MultipartParams #:nodoc: class MultipartParams #:nodoc:
attr_accessor :content_type, :body attr_accessor :content_type, :body

def initialize(param_hash={}) def initialize(param_hash={})
@boundary_token = generate_boundary_token @boundary_token = generate_boundary_token
self.content_type = "multipart/form-data; boundary=#{@boundary_token}" self.content_type = "multipart/form-data; boundary=#{@boundary_token}"
self.body = pack_params(param_hash) self.body = pack_params(param_hash)
end end


protected protected

def generate_boundary_token def generate_boundary_token
[Array.new(8) {rand(256)}].join [Array.new(8) {rand(256)}].join
end end

def pack_params(hash) def pack_params(hash)
marker = "--#{@boundary_token}\r\n" marker = "--#{@boundary_token}\r\n"
files_params = hash.find_all{|k,v| v.is_a?(File)}.to_h files_params = hash.find_all{|k,v| v.is_a?(File)}.to_h
text_params = hash - files_params text_params = hash - files_params

pack_hash(text_params, marker) + marker + pack_hash(files_params, marker) + "--#{@boundary_token}--\r\n" pack_hash(text_params, marker) + marker + pack_hash(files_params, marker) + "--#{@boundary_token}--\r\n"
end end

def pack_hash(hash, marker) def pack_hash(hash, marker)
hash.map do |name, value| hash.map do |name, value|
marker + case value marker + case value
Expand All @@ -33,7 +33,7 @@ def pack_hash(hash, marker)
end end
end.join('') end.join('')
end end

def file_to_multipart(key,file) def file_to_multipart(key,file)
filename = File.basename(file.path) filename = File.basename(file.path)
mime_types = MIME::Types.of(filename) mime_types = MIME::Types.of(filename)
Expand Down
Loading