Skip to content
Browse files

adding methods for getting the media package xml and removing workflo…

…w 'tracks'
  • Loading branch information...
1 parent 53c4bef commit 91c054d658ea1afe956d66789ad158a0cb763383 @atomical atomical committed Mar 13, 2013
View
2 lib/rubyhorn/matterhorn_client.rb
@@ -3,6 +3,7 @@
require 'rubyhorn/rest_client/ingest'
require 'rubyhorn/rest_client/workflow'
require 'rubyhorn/rest_client/exceptions'
+require 'rubyhorn/rest_client/hls_distribution'
module Rubyhorn
class MatterhornClient
@@ -11,6 +12,7 @@ class MatterhornClient
include Rubyhorn::RestClient::Ingest
include Rubyhorn::RestClient::Workflow
include Rubyhorn::RestClient::Exceptions
+ include Rubyhorn::RestClient::HLSDistribution
# repository configuration (see #initialize)
attr_reader :config
View
18 lib/rubyhorn/rest_client/common.rb
@@ -32,9 +32,11 @@ def execute_request uri, req
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)
+ code_as_int = res.code.to_i
+ if code_as_int == 404
+ raise Rubyhorn::RestClient::Exceptions::HTTPNotFound.new
+ elsif code_as_int.between?(500,599)
+ raise Rubyhorn::RestClient::Exceptions::ServerError.new(code_as_int)
else
res
end
@@ -66,6 +68,16 @@ def post url, args = {}
return response.body
end
+ def delete( url, args )
+ url = config[:url] + url
+ uri = URI.parse(url)
+ request = Net::HTTP::Delete.new(uri.request_uri)
+ request.form_data = args
+ request['Cookie'] = @cookie
+ response = execute_request(uri, request)
+ return response.body
+ end
+
def multipart_post url, file, args = {}
if args.has_key? "filename"
filename = args["filename"]
View
7 lib/rubyhorn/rest_client/exceptions.rb
@@ -18,5 +18,12 @@ def initialize(params)
super("You failed to include #{params.join(', ')} in your request.")
end
end
+
+ class HTTPNotFound < RubyhornException
+ def initialize
+ super("Not found")
+ end
+ end
+
end
end
View
23 lib/rubyhorn/rest_client/hls_distribution.rb
@@ -0,0 +1,23 @@
+module Rubyhorn::RestClient
+ module HLSDistribution
+
+ def delete_track( media_package, track )
+ args = {
+ :mediapackage => media_package,
+ :elementId => track
+ }
+
+ post("distribution/streaming/retract", args)
+ end
+
+ # example usage of delete_track
+ # def delete_workflow_tracks(workflow_id)
+ # media_package = Rubyhorn.client.get_media_package(workflow_id)
+ # tracks = media_package.xpath('//track').map{|node| node.get_attribute('id')}
+
+ # tracks.each do |track|
+ # Rubyhorn.client.delete_track(media_package.to_s, track)
+ # end
+ # end
+ end
+end
View
21 lib/rubyhorn/rest_client/workflow.rb
@@ -3,23 +3,44 @@ module Workflow
def handlers
return JSON.parse(get("workflow/handlers.json"))
end
+
def statistics_json
return JSON.parse(get("workflow/statistics.json"))
end
+
def statistics_xml
#TODO write me and parse into OM document or just use Nokogiri?
end
+
def instance_json id
return JSON.parse(get("workflow/instance/#{id}.json"))
end
+
def instance_xml id
return Rubyhorn::Workflow.from_xml(get("workflow/instance/#{id}.xml"))
end
+
def instances_json args
return JSON.parse(get("workflow/instances.json", args))
end
+
def stop id
return Rubyhorn::Workflow.from_xml(post("workflow/stop", {"id"=>id}))
end
+
+ def delete_instance
+ return Rubyhorn::Workflow.from_xml(delete("workflow/remove", {"id"=>id}))
+ end
+
+ def get_media_package(workflow_id)
+ package = Rubyhorn::Workflow.from_xml(get("workflow/instance/#{workflow_id}.xml"))
+ doc = Nokogiri.XML(package.to_xml)
+ doc.remove_namespaces!
+ doc = doc.xpath('//mediapackage')
+ first_node = doc.first
+ first_node['xmlns'] = 'http://mediapackage.opencastproject.org'
+ doc
+ end
+
end
end

0 comments on commit 91c054d

Please sign in to comment.
Something went wrong with that request. Please try again.