Skip to content

Commit

Permalink
Merge pull request #2 from atomical/get_media_package_and_delete_trac…
Browse files Browse the repository at this point in the history
…k_methods

adding methods for getting the media package xml and removing workflow '...
  • Loading branch information
atomical committed Mar 13, 2013
2 parents 53c4bef + 91c054d commit 83184cb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/rubyhorn/matterhorn_client.rb
Expand Up @@ -3,6 +3,7 @@
require 'rubyhorn/rest_client/ingest' require 'rubyhorn/rest_client/ingest'
require 'rubyhorn/rest_client/workflow' require 'rubyhorn/rest_client/workflow'
require 'rubyhorn/rest_client/exceptions' require 'rubyhorn/rest_client/exceptions'
require 'rubyhorn/rest_client/hls_distribution'


module Rubyhorn module Rubyhorn
class MatterhornClient class MatterhornClient
Expand All @@ -11,6 +12,7 @@ class MatterhornClient
include Rubyhorn::RestClient::Ingest include Rubyhorn::RestClient::Ingest
include Rubyhorn::RestClient::Workflow include Rubyhorn::RestClient::Workflow
include Rubyhorn::RestClient::Exceptions include Rubyhorn::RestClient::Exceptions
include Rubyhorn::RestClient::HLSDistribution


# repository configuration (see #initialize) # repository configuration (see #initialize)
attr_reader :config attr_reader :config
Expand Down
18 changes: 15 additions & 3 deletions lib/rubyhorn/rest_client/common.rb
Expand Up @@ -32,9 +32,11 @@ def execute_request uri, req
auth = digest_auth.auth_header uri, res['www-authenticate'], req.method auth = digest_auth.auth_header uri, res['www-authenticate'], req.method
req.add_field 'Authorization', auth req.add_field 'Authorization', auth
res = @http.request req res = @http.request req

code_as_int = res.code.to_i
if res.code.to_i.between?(500,599) if code_as_int == 404
raise Rubyhorn::RestClient::Exceptions::ServerError.new(res.code) if res.code.to_i.between?(500,599) raise Rubyhorn::RestClient::Exceptions::HTTPNotFound.new
elsif code_as_int.between?(500,599)
raise Rubyhorn::RestClient::Exceptions::ServerError.new(code_as_int)
else else
res res
end end
Expand Down Expand Up @@ -66,6 +68,16 @@ def post url, args = {}
return response.body return response.body
end 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 = {} def multipart_post url, file, args = {}
if args.has_key? "filename" if args.has_key? "filename"
filename = args["filename"] filename = args["filename"]
Expand Down
7 changes: 7 additions & 0 deletions lib/rubyhorn/rest_client/exceptions.rb
Expand Up @@ -18,5 +18,12 @@ def initialize(params)
super("You failed to include #{params.join(', ')} in your request.") super("You failed to include #{params.join(', ')} in your request.")
end end
end end

class HTTPNotFound < RubyhornException
def initialize
super("Not found")
end
end

end end
end end
23 changes: 23 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions lib/rubyhorn/rest_client/workflow.rb
Expand Up @@ -3,23 +3,44 @@ module Workflow
def handlers def handlers
return JSON.parse(get("workflow/handlers.json")) return JSON.parse(get("workflow/handlers.json"))
end end

def statistics_json def statistics_json
return JSON.parse(get("workflow/statistics.json")) return JSON.parse(get("workflow/statistics.json"))
end end

def statistics_xml def statistics_xml
#TODO write me and parse into OM document or just use Nokogiri? #TODO write me and parse into OM document or just use Nokogiri?
end end

def instance_json id def instance_json id
return JSON.parse(get("workflow/instance/#{id}.json")) return JSON.parse(get("workflow/instance/#{id}.json"))
end end

def instance_xml id def instance_xml id
return Rubyhorn::Workflow.from_xml(get("workflow/instance/#{id}.xml")) return Rubyhorn::Workflow.from_xml(get("workflow/instance/#{id}.xml"))
end end

def instances_json args def instances_json args
return JSON.parse(get("workflow/instances.json", args)) return JSON.parse(get("workflow/instances.json", args))
end end

def stop id def stop id
return Rubyhorn::Workflow.from_xml(post("workflow/stop", {"id"=>id})) return Rubyhorn::Workflow.from_xml(post("workflow/stop", {"id"=>id}))
end 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
end end

0 comments on commit 83184cb

Please sign in to comment.