Class: Rivendell::API::Xport

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Xport

Returns a new instance of Xport.



29
30
31
# File 'lib/rivendell/api/xport.rb', line 29

def initialize(options = {})
  options.each { |k,v| send "#{k}=", v }
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



33
34
35
# File 'lib/rivendell/api/xport.rb', line 33

def host
  @host
end

#login_nameObject

Returns the value of attribute login_name.



33
34
35
# File 'lib/rivendell/api/xport.rb', line 33

def 
  @login_name
end

#passwordObject

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, options = {})
  arguments = { 
    :channels => 2, 
    :normalization_level => -13,
    :autotrim_level => -30,
    :use_metadata => true,
  }.merge(options)

  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(options = {})
  options[:group_name] ||= options.delete(:group)
  
  response = post COMMAND_LISTCARTS, options
  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_groupsObject



69
70
71
# File 'lib/rivendell/api/xport.rb', line 69

def list_groups
  post COMMAND_LISTGROUPS
end

#loggerObject



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 = {}, options = {})
  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 => , 
    :password => password 
  }.merge(attributes)

  attributes.inject({}) do |map, (key, value)|
    map[key.to_s.upcase] = value
    map
  end
end

#rdxport_uriObject



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