Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from atomical/ruby_horn_raises_exception_on_fai…

…lure

ruby horn raises exceptions on failure
  • Loading branch information...
commit 53c4befd15c92ed4f20aa4844baf66b38d9f2ced 2 parents 93dc467 + 1aa8c14
@atomical atomical authored
View
2  .gitmodules
@@ -1,3 +1,3 @@
[submodule "felix"]
path = felix
- url = git://github.com/variations-on-video/hydrant-felix.git
+ url = git://github.com/avalonmediasystem/avalon-felix.git
View
2  Gemfile
@@ -1,7 +1,7 @@
source "http://rubygems.org"
group :development, :test do
- gem 'felixwrapper', :git => "git://github.com/avalonmediasystem/felixwrapper.git"
+ gem 'felixwrapper', :git => "git://github.com/avalonmediasystem/felixwrapper.git"
end
gemspec
View
2  lib/rubyhorn/matterhorn_client.rb
@@ -2,6 +2,7 @@
require 'rubyhorn/rest_client/info'
require 'rubyhorn/rest_client/ingest'
require 'rubyhorn/rest_client/workflow'
+require 'rubyhorn/rest_client/exceptions'
module Rubyhorn
class MatterhornClient
@@ -9,6 +10,7 @@ class MatterhornClient
include Rubyhorn::RestClient::Info
include Rubyhorn::RestClient::Ingest
include Rubyhorn::RestClient::Workflow
+ include Rubyhorn::RestClient::Exceptions
# repository configuration (see #initialize)
attr_reader :config
View
45 lib/rubyhorn/rest_client/common.rb
@@ -9,33 +9,36 @@ module Common
attr_reader :cookie
def connect
- uri = URI.parse(config[:url])
- @http = Net::HTTP.new uri.host, uri.port
- @http.set_debug_output $stderr if !config[:debug].nil? and config[:debug].downcase == 'true'
- login
+ uri = URI.parse(config[:url])
+ @http = Net::HTTP.new uri.host, uri.port
+ @http.set_debug_output $stderr if !config[:debug].nil? and config[:debug].downcase == 'true'
+ login
end
def login url = "welcome.html"
- uri = URI.parse(config[:url] + url)
- req = Net::HTTP::Head.new uri.request_uri
- res = execute_request(uri, req)
- @cookie = res['set-cookie']
+ uri = URI.parse(config[:url] + url)
+ req = Net::HTTP::Head.new uri.request_uri
+ res = execute_request(uri, req)
+ @cookie = res['set-cookie']
end
def execute_request uri, req
- uri.user = config[:user]
- uri.password = config[:password]
- head = Net::HTTP::Head.new uri.request_uri
- head['X-REQUESTED-AUTH'] = 'Digest'
- res = @http.request head
-
-# if res.code.to_i != 200
- digest_auth = Net::HTTP::DigestAuth.new
- auth = digest_auth.auth_header uri, res['www-authenticate'], req.method
- req.add_field 'Authorization', auth
- res = @http.request req
-# end
-# res
+ uri.user = config[:user]
+ uri.password = config[:password]
+ head = Net::HTTP::Head.new uri.request_uri
+ head['X-REQUESTED-AUTH'] = 'Digest'
+ res = @http.request head
+ digest_auth = Net::HTTP::DigestAuth.new
+ auth = digest_auth.auth_header uri, res['www-authenticate'], req.method
+ req.add_field 'Authorization', auth
+ res = @http.request req
+
+ if res.code.to_i.between?(500,599)
+ raise Rubyhorn::RestClient::Exceptions::ServerError.new(res.code) if res.code.to_i.between?(500,599)
+ else
+ res
+ end
+
end
def get url, args = {}
View
22 lib/rubyhorn/rest_client/exceptions.rb
@@ -0,0 +1,22 @@
+module Rubyhorn::RestClient
+ module Exceptions
+ class RubyhornException < StandardError
+ end
+
+ class ServerError < RubyhornException
+ attr_reader :status_code
+ def initialize(status_code)
+ @status_code = status_code
+ super("Server responded with status code: #{status_code}.")
+ end
+ end
+
+ class MissingRequiredParams < RubyhornException
+ attr_reader :params
+ def initialize(params)
+ @params = params
+ super("You failed to include #{params.join(', ')} in your request.")
+ end
+ end
+ end
+end
View
13 lib/rubyhorn/rest_client/ingest.rb
@@ -10,14 +10,11 @@ def addMediaPackage(file, params)
# Adds a mediapackage and starts ingesting, using an URL as the resource
def addMediaPackageWithUrl(params)
- logger.debug "<<<<< IM IN URL MeTHOd >>>>>"
-
- raise "Missing required field url" unless params.include? "url"
- raise "Missing required field flavor" unless params.include? "flavor"
- raise "Missing required field title" unless params.include? "title"
-
- uri = "ingest/addMediaPackage" + (params["workflow"].nil? ? "" : "/#{params["workflow"]}")
- return Rubyhorn::Workflow.from_xml post(uri, params)
+ missing_params = ['url','flavor','title','filename','workflow'].collect{|field| field if ! params.include?(field) }.compact
+ raise Rubyhorn::RestClient::Exceptions::MissingRequiredParams.new(missing_params) if missing_params.present?
+ uri = "ingest/addMediaPackage"
+ uri += "/#{params["workflow"]}" unless params["workflow"].nil?
+ Rubyhorn::Workflow.from_xml post(uri, params)
end
end
end
View
21 spec/lib/ingest_spec.rb
@@ -11,25 +11,38 @@
after(:all) do
@ids.each {|id| @client.stop id}
end
+ describe '#addMediaPackageWithUrl' do
+ it 'throws an exception when one of the required arguments is not passed' do
+ expect {
+ @client.addMediaPackageWithUrl({"title" => "hydrant:13", "workflow" => "avalon"}) # missing flavor, url, filename
+ }.to raise_error Rubyhorn::RestClient::Exceptions::MissingRequiredParams
+ end
+
+ it 'throws an exception when the server returns an http error status code' do
+ expect {
+ @client.addMediaPackageWithUrl({'title' => 'hydrant:13', 'flavor' => 'presenter/source', 'workflow' => "hydrant", 'url'=> 'http://localhost:8080', 'filename'=>'hi'})
+ }.to raise_error Rubyhorn::RestClient::Exceptions::ServerError
+ end
+ end
describe "addMediaPackage" do
it "should return a Workflow object after call to ingest" do
video = File.new "spec/fixtures/dance_practice.ogx"
- workflow_doc = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "hydrant"})
+ workflow_doc = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "avalon"})
workflow_doc.should be_an_instance_of Rubyhorn::Workflow
workflow = workflow_doc.workflow
@ids << workflow.id[0]
- workflow.template[0].should eql "hydrant"
+ workflow.template[0].should eql "avalon"
workflow.mediapackage.title[0].should eql "hydrant:13"
workflow.mediapackage.media.track.type[0].should eql "presenter/source"
end
it "should be able to rename file uploaded" do
video = File.new "spec/fixtures/dance_practice.ogx"
- workflow_doc = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "hydrant", "filename" => "video.ogx"})
+ workflow_doc = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "avalon", "filename" => "video.ogx"})
workflow_doc.should be_an_instance_of Rubyhorn::Workflow
workflow = workflow_doc.workflow
@ids << workflow.id[0]
- workflow.template[0].should eql "hydrant"
+ workflow.template[0].should eql "avalon"
workflow.mediapackage.title[0].should eql "hydrant:13"
workflow.mediapackage.media.track.type[0].should eql "presenter/source"
workflow.mediapackage.media.track.url[0].should match "video.ogx"
View
6 spec/lib/workflow_spec.rb
@@ -5,7 +5,7 @@
Rubyhorn.init
@client = Rubyhorn.client
video = File.new "spec/fixtures/dance_practice.ogx"
- workflow = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "hydrant"})
+ workflow = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "avalon"})
@id = workflow.id[0]
# puts "Created media package with workflow #{@id}: #{workflow.to_xml}"
end
@@ -19,7 +19,7 @@
workflow_doc = @client.instance_xml @id
workflow_doc.should be_an_instance_of Rubyhorn::Workflow
workflow = workflow_doc.workflow
- workflow.template[0].should eql "hydrant"
+ workflow.template[0].should eql "avalon"
workflow.mediapackage.title[0].should eql "hydrant:13"
workflow.mediapackage.media.track.type[0].should eql "presenter/source"
end
@@ -28,7 +28,7 @@
describe "instances_json" do
it "should return a JSON doc with a list of instances that have the state RUNNING" do
video = File.new "spec/fixtures/dance_practice.ogx"
- workflow = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "hydrant"})
+ workflow = @client.addMediaPackage(video, {"title" => "hydrant:13", "flavor" => "presenter/source", "workflow" => "avalon"})
sleep 5
json = @client.instances_json({"state" => "running"})
json["workflows"]["totalCount"].to_i.should > 1
Please sign in to comment.
Something went wrong with that request. Please try again.