Class: Rivendell::API::Xport
- Inherits:
-
Object
- Object
- Rivendell::API::Xport
- Includes:
- HTTMultiParty
- Defined in:
- lib/rivendell/api/xport.rb
Constant Summary collapse
- COMMAND_EXPORT =
1
- COMMAND_IMPORT =
2
- COMMAND_DELETEAUDIO =
3
- COMMAND_LISTGROUPS =
4
- COMMAND_LISTGROUP =
5
- COMMAND_LISTCARTS =
6
- COMMAND_LISTCART =
7
- COMMAND_LISTCUT =
8
- COMMAND_LISTCUTS =
9
- COMMAND_ADDCUT =
10
- COMMAND_REMOVECUT =
11
- COMMAND_ADDCART =
12
- COMMAND_REMOVECART =
13
- COMMAND_EDITCART =
14
- COMMAND_EDITCUT =
15
- COMMAND_EXPORT_PEAKS =
16
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#login_name ⇒ Object
Returns the value of attribute login_name.
-
#password ⇒ Object
Returns the value of attribute password.
Instance Method Summary collapse
- #add_cart(attributes = {}) ⇒ Object
- #add_cut(cart_number) ⇒ Object
-
#clear_cuts(cart_number) ⇒ Object
Extension.
- #import(cart_number, cut_number, file, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Xport
constructor
A new instance of Xport.
-
#list_carts(options = {}) ⇒ Object
FIXME accents in carts create invalid UTF-8 response.
- #list_cuts(cart_number) ⇒ Object
- #list_groups ⇒ Object
- #logger ⇒ Object
- #post(command, attributes = {}, options = {}) ⇒ Object
- #query(command, attributes = {}) ⇒ Object
- #rdxport_uri ⇒ Object
- #remove_cart(cart_number) ⇒ Object
- #remove_cut(cart_number, cut_number) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Xport
Returns a new instance of Xport.
29 30 31 |
# File 'lib/rivendell/api/xport.rb', line 29 def initialize( = {}) .each { |k,v| send "#{k}=", v } end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
33 34 35 |
# File 'lib/rivendell/api/xport.rb', line 33 def host @host end |
#login_name ⇒ Object
Returns the value of attribute login_name.
33 34 35 |
# File 'lib/rivendell/api/xport.rb', line 33 def login_name @login_name end |
#password ⇒ Object
Returns the value of attribute password.
33 34 35 |
# File 'lib/rivendell/api/xport.rb', line 33 def password @password end |
Instance Method Details
#add_cart(attributes = {}) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rivendell/api/xport.rb', line 73 def add_cart(attributes = {}) attributes = { :type => "audio" }.merge(attributes) attributes[:group_name] ||= attributes.delete(:group) response = post COMMAND_ADDCART, attributes Rivendell::API::Cart.new(response["cartAdd"]["cart"]) end |
#add_cut(cart_number) ⇒ Object
135 136 137 138 |
# File 'lib/rivendell/api/xport.rb', line 135 def add_cut(cart_number) response = post COMMAND_ADDCUT, :cart_number => cart_number Rivendell::API::Cut.new(response["cutAdd"]["cut"]) end |
#clear_cuts(cart_number) ⇒ Object
Extension
114 115 116 117 118 |
# File 'lib/rivendell/api/xport.rb', line 114 def clear_cuts(cart_number) list_cuts(cart_number).map(&:number).each do |cut_number| remove_cut cart_number, cut_number end end |
#import(cart_number, cut_number, file, options = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rivendell/api/xport.rb', line 120 def import(cart_number, cut_number, file, = {}) arguments = { :channels => 2, :normalization_level => -13, :autotrim_level => -30, :use_metadata => true, }.merge() arguments = arguments.merge(:cart_number => cart_number, :cut_number => cut_number, :filename => File.new(file)) arguments[:use_metadata] = 1 if arguments[:use_metadata] post COMMAND_IMPORT, arguments, :timeout => 10*60 end |
#list_carts(options = {}) ⇒ Object
FIXME accents in carts create invalid UTF-8 response
82 83 84 85 86 87 88 89 |
# File 'lib/rivendell/api/xport.rb', line 82 def list_carts( = {}) [:group_name] ||= .delete(:group) response = post COMMAND_LISTCARTS, response["cartList"]["cart"].collect do |cart_xml| Rivendell::API::Cart.new(cart_xml) end end |
#list_cuts(cart_number) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rivendell/api/xport.rb', line 95 def list_cuts(cart_number) response = post COMMAND_LISTCUTS, :cart_number => cart_number case cuts_xml = response["cutList"]["cut"] when Array cuts_xml.collect do |cut_xml| Rivendell::API::Cut.new(cut_xml) end when nil [] else [ Rivendell::API::Cut.new(cuts_xml) ] end end |
#list_groups ⇒ Object
69 70 71 |
# File 'lib/rivendell/api/xport.rb', line 69 def list_groups post COMMAND_LISTGROUPS end |
#logger ⇒ Object
25 26 27 |
# File 'lib/rivendell/api/xport.rb', line 25 def logger Rivendell::API.logger end |
#post(command, attributes = {}, options = {}) ⇒ Object
64 65 66 67 |
# File 'lib/rivendell/api/xport.rb', line 64 def post(command, attributes = {}, = {}) logger.debug "Post #{command} #{attributes.inspect}" self.class.post rdxport_uri, :query => query(command, attributes) end |
#query(command, attributes = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rivendell/api/xport.rb', line 51 def query(command, attributes = {}) attributes = { :command => command, :login_name => login_name, :password => password }.merge(attributes) attributes.inject({}) do |map, (key, value)| map[key.to_s.upcase] = value map end end |
#rdxport_uri ⇒ Object
47 48 49 |
# File 'lib/rivendell/api/xport.rb', line 47 def rdxport_uri "http://#{host}/rd-bin/rdxport.cgi" end |
#remove_cart(cart_number) ⇒ Object
91 92 93 |
# File 'lib/rivendell/api/xport.rb', line 91 def remove_cart(cart_number) post COMMAND_REMOVECART, :cart_number => cart_number end |
#remove_cut(cart_number, cut_number) ⇒ Object
109 110 111 |
# File 'lib/rivendell/api/xport.rb', line 109 def remove_cut(cart_number, cut_number) post COMMAND_REMOVECUT, :cart_number => cart_number, :cut_number => cut_number end |