rivendell-api 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/lib/rivendell/api.rb +1 -0
- data/lib/rivendell/api/cart.rb +4 -4
- data/lib/rivendell/api/cut.rb +2 -2
- data/lib/rivendell/api/version.rb +1 -1
- data/lib/rivendell/api/xport.rb +52 -4
- data/spec/fixtures/rdxport_list_cuts.xml +138 -0
- data/spec/rivendell/api/xport_spec.rb +152 -3
- data/spec/support/fakeweb.rb +9 -0
- metadata +6 -4
data/Gemfile
CHANGED
data/lib/rivendell/api.rb
CHANGED
data/lib/rivendell/api/cart.rb
CHANGED
@@ -12,10 +12,10 @@ module Rivendell::API
|
|
12
12
|
def number=(number)
|
13
13
|
@number = (number ? number.to_i : nil)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
alias_method :group, :group_name
|
17
17
|
alias_method :group=, :group_name=
|
18
|
-
|
18
|
+
|
19
19
|
def cut_list=(cuts)
|
20
20
|
|
21
21
|
end
|
@@ -24,10 +24,10 @@ module Rivendell::API
|
|
24
24
|
|
25
25
|
end
|
26
26
|
|
27
|
-
def method_missing(name, arguments)
|
27
|
+
def method_missing(name, *arguments)
|
28
28
|
underscored_name = name.to_s.underscore
|
29
29
|
if respond_to?(underscored_name)
|
30
|
-
send underscored_name, arguments
|
30
|
+
send underscored_name, *arguments
|
31
31
|
else
|
32
32
|
super
|
33
33
|
end
|
data/lib/rivendell/api/cut.rb
CHANGED
@@ -16,10 +16,10 @@ module Rivendell::API
|
|
16
16
|
alias_method :cut_name=, :name=
|
17
17
|
alias_method :cut_number=, :number=
|
18
18
|
|
19
|
-
def method_missing(name, arguments)
|
19
|
+
def method_missing(name, *arguments)
|
20
20
|
underscored_name = name.to_s.underscore
|
21
21
|
if respond_to?(underscored_name)
|
22
|
-
send underscored_name, arguments
|
22
|
+
send underscored_name, *arguments
|
23
23
|
else
|
24
24
|
super
|
25
25
|
end
|
data/lib/rivendell/api/xport.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Rivendell::API
|
2
2
|
class Xport
|
3
3
|
include HTTMultiParty
|
4
|
-
|
4
|
+
|
5
5
|
# debug_output $stderr
|
6
6
|
format :xml
|
7
7
|
|
@@ -26,11 +26,33 @@ module Rivendell::API
|
|
26
26
|
Rivendell::API.logger
|
27
27
|
end
|
28
28
|
|
29
|
+
def initialize(options = {})
|
30
|
+
options.each { |k,v| send "#{k}=", v }
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :login_name, :password, :host
|
34
|
+
|
35
|
+
def host
|
36
|
+
@host ||= "localhost"
|
37
|
+
end
|
38
|
+
|
39
|
+
def login_name
|
40
|
+
@login_name ||= "user"
|
41
|
+
end
|
42
|
+
|
43
|
+
def password
|
44
|
+
@password ||= ""
|
45
|
+
end
|
46
|
+
|
47
|
+
def rdxport_uri
|
48
|
+
"http://#{host}/rd-bin/rdxport.cgi"
|
49
|
+
end
|
50
|
+
|
29
51
|
def query(command, attributes = {})
|
30
52
|
attributes = {
|
31
53
|
:command => command,
|
32
|
-
:login_name =>
|
33
|
-
:password =>
|
54
|
+
:login_name => login_name,
|
55
|
+
:password => password
|
34
56
|
}.merge(attributes)
|
35
57
|
|
36
58
|
attributes.inject({}) do |map, (key, value)|
|
@@ -41,7 +63,7 @@ module Rivendell::API
|
|
41
63
|
|
42
64
|
def post(command, attributes = {}, options = {})
|
43
65
|
logger.debug "Post #{command} #{attributes.inspect}"
|
44
|
-
self.class.post
|
66
|
+
self.class.post rdxport_uri, :query => query(command, attributes)
|
45
67
|
end
|
46
68
|
|
47
69
|
def list_groups
|
@@ -70,6 +92,31 @@ module Rivendell::API
|
|
70
92
|
post COMMAND_REMOVECART, :cart_number => cart_number
|
71
93
|
end
|
72
94
|
|
95
|
+
def list_cuts(cart_number)
|
96
|
+
response = post COMMAND_LISTCUTS, :cart_number => cart_number
|
97
|
+
case cuts_xml = response["cutList"]["cut"]
|
98
|
+
when Array
|
99
|
+
cuts_xml.collect do |cut_xml|
|
100
|
+
Rivendell::API::Cut.new(cut_xml)
|
101
|
+
end
|
102
|
+
when nil
|
103
|
+
[]
|
104
|
+
else
|
105
|
+
[ Rivendell::API::Cut.new(cuts_xml) ]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def remove_cut(cart_number, cut_number)
|
110
|
+
post COMMAND_REMOVECUT, :cart_number => cart_number, :cut_number => cut_number
|
111
|
+
end
|
112
|
+
|
113
|
+
# Extension
|
114
|
+
def clear_cuts(cart_number)
|
115
|
+
list_cuts(cart_number).map(&:number).each do |cut_number|
|
116
|
+
remove_cut cart_number, cut_number
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
73
120
|
def import(cart_number, cut_number, file, options = {})
|
74
121
|
arguments = {
|
75
122
|
:channels => 2,
|
@@ -91,4 +138,5 @@ module Rivendell::API
|
|
91
138
|
end
|
92
139
|
|
93
140
|
end
|
141
|
+
|
94
142
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<cutList>
|
3
|
+
<cut>
|
4
|
+
<cutName>045004_001</cutName>
|
5
|
+
<cartNumber>45004</cartNumber>
|
6
|
+
<cutNumber>1</cutNumber>
|
7
|
+
<evergreen>false</evergreen>
|
8
|
+
<description>Rivendell 1</description>
|
9
|
+
<outcue></outcue>
|
10
|
+
<isrc></isrc>
|
11
|
+
<isci></isci>
|
12
|
+
<length>7862</length>
|
13
|
+
<originDatetime>Wed, 22 Apr 2009 21:23:22 GMT</originDatetime>
|
14
|
+
<startDatetime></startDatetime>
|
15
|
+
<endDatetime></endDatetime>
|
16
|
+
<sun>true</sun>
|
17
|
+
<mon>true</mon>
|
18
|
+
<tue>true</tue>
|
19
|
+
<wed>true</wed>
|
20
|
+
<thu>true</thu>
|
21
|
+
<fri>true</fri>
|
22
|
+
<sat>true</sat>
|
23
|
+
<startDaypart></startDaypart>
|
24
|
+
<endDaypart></endDaypart>
|
25
|
+
<originName>hyppo</originName>
|
26
|
+
<weight>1</weight>
|
27
|
+
<lastPlayDatetime>Thu, 13 Sep 2012 07:05:35 GMT</lastPlayDatetime>
|
28
|
+
<playCounter>34</playCounter>
|
29
|
+
<localCounter>22</localCounter>
|
30
|
+
<validity>2</validity>
|
31
|
+
<codingFormat>0</codingFormat>
|
32
|
+
<sampleRate>44100</sampleRate>
|
33
|
+
<bitRate>0</bitRate>
|
34
|
+
<channels>2</channels>
|
35
|
+
<playGain>0</playGain>
|
36
|
+
<startPoint>52</startPoint>
|
37
|
+
<endPoint>7914</endPoint>
|
38
|
+
<fadeupPoint>-1</fadeupPoint>
|
39
|
+
<fadedownPoint>-1</fadedownPoint>
|
40
|
+
<segueStartPoint>6008</segueStartPoint>
|
41
|
+
<segueEndPoint>7888</segueEndPoint>
|
42
|
+
<segueGain>-3000</segueGain>
|
43
|
+
<hookStartPoint>-1</hookStartPoint>
|
44
|
+
<hookEndPoint>-1</hookEndPoint>
|
45
|
+
<talkStartPoint>-1</talkStartPoint>
|
46
|
+
<talkEndPoint>0</talkEndPoint>
|
47
|
+
</cut>
|
48
|
+
<cut>
|
49
|
+
<cutName>045004_002</cutName>
|
50
|
+
<cartNumber>45004</cartNumber>
|
51
|
+
<cutNumber>2</cutNumber>
|
52
|
+
<evergreen>false</evergreen>
|
53
|
+
<description>Rivendell 2</description>
|
54
|
+
<outcue></outcue>
|
55
|
+
<isrc></isrc>
|
56
|
+
<isci></isci>
|
57
|
+
<length>9064</length>
|
58
|
+
<originDatetime>Wed, 22 Apr 2009 21:25:00 GMT</originDatetime>
|
59
|
+
<startDatetime></startDatetime>
|
60
|
+
<endDatetime></endDatetime>
|
61
|
+
<sun>true</sun>
|
62
|
+
<mon>true</mon>
|
63
|
+
<tue>true</tue>
|
64
|
+
<wed>true</wed>
|
65
|
+
<thu>true</thu>
|
66
|
+
<fri>true</fri>
|
67
|
+
<sat>true</sat>
|
68
|
+
<startDaypart></startDaypart>
|
69
|
+
<endDaypart></endDaypart>
|
70
|
+
<originName>hyppo</originName>
|
71
|
+
<weight>1</weight>
|
72
|
+
<lastPlayDatetime>Thu, 13 Sep 2012 07:05:48 GMT</lastPlayDatetime>
|
73
|
+
<playCounter>34</playCounter>
|
74
|
+
<localCounter>22</localCounter>
|
75
|
+
<validity>2</validity>
|
76
|
+
<codingFormat>0</codingFormat>
|
77
|
+
<sampleRate>44100</sampleRate>
|
78
|
+
<bitRate>0</bitRate>
|
79
|
+
<channels>2</channels>
|
80
|
+
<playGain>0</playGain>
|
81
|
+
<startPoint>78</startPoint>
|
82
|
+
<endPoint>9142</endPoint>
|
83
|
+
<fadeupPoint>-1</fadeupPoint>
|
84
|
+
<fadedownPoint>-1</fadedownPoint>
|
85
|
+
<segueStartPoint>8280</segueStartPoint>
|
86
|
+
<segueEndPoint>9116</segueEndPoint>
|
87
|
+
<segueGain>-3000</segueGain>
|
88
|
+
<hookStartPoint>-1</hookStartPoint>
|
89
|
+
<hookEndPoint>-1</hookEndPoint>
|
90
|
+
<talkStartPoint>-1</talkStartPoint>
|
91
|
+
<talkEndPoint>0</talkEndPoint>
|
92
|
+
</cut>
|
93
|
+
<cut>
|
94
|
+
<cutName>045004_003</cutName>
|
95
|
+
<cartNumber>45004</cartNumber>
|
96
|
+
<cutNumber>3</cutNumber>
|
97
|
+
<evergreen>false</evergreen>
|
98
|
+
<description>Rivendell 3</description>
|
99
|
+
<outcue></outcue>
|
100
|
+
<isrc></isrc>
|
101
|
+
<isci></isci>
|
102
|
+
<length>8307</length>
|
103
|
+
<originDatetime>Wed, 22 Apr 2009 21:25:38 GMT</originDatetime>
|
104
|
+
<startDatetime></startDatetime>
|
105
|
+
<endDatetime></endDatetime>
|
106
|
+
<sun>true</sun>
|
107
|
+
<mon>true</mon>
|
108
|
+
<tue>true</tue>
|
109
|
+
<wed>true</wed>
|
110
|
+
<thu>true</thu>
|
111
|
+
<fri>true</fri>
|
112
|
+
<sat>true</sat>
|
113
|
+
<startDaypart></startDaypart>
|
114
|
+
<endDaypart></endDaypart>
|
115
|
+
<originName>hyppo</originName>
|
116
|
+
<weight>1</weight>
|
117
|
+
<lastPlayDatetime>Thu, 13 Sep 2012 07:05:22 GMT</lastPlayDatetime>
|
118
|
+
<playCounter>33</playCounter>
|
119
|
+
<localCounter>21</localCounter>
|
120
|
+
<validity>2</validity>
|
121
|
+
<codingFormat>0</codingFormat>
|
122
|
+
<sampleRate>44100</sampleRate>
|
123
|
+
<bitRate>0</bitRate>
|
124
|
+
<channels>2</channels>
|
125
|
+
<playGain>0</playGain>
|
126
|
+
<startPoint>130</startPoint>
|
127
|
+
<endPoint>8437</endPoint>
|
128
|
+
<fadeupPoint>-1</fadeupPoint>
|
129
|
+
<fadedownPoint>-1</fadedownPoint>
|
130
|
+
<segueStartPoint>-1</segueStartPoint>
|
131
|
+
<segueEndPoint>-1</segueEndPoint>
|
132
|
+
<segueGain>-3000</segueGain>
|
133
|
+
<hookStartPoint>-1</hookStartPoint>
|
134
|
+
<hookEndPoint>-1</hookEndPoint>
|
135
|
+
<talkStartPoint>-1</talkStartPoint>
|
136
|
+
<talkEndPoint>0</talkEndPoint>
|
137
|
+
</cut>
|
138
|
+
</cutList>
|
@@ -14,6 +14,88 @@ describe Rivendell::API::Xport do
|
|
14
14
|
File.read fixture_file(file)
|
15
15
|
end
|
16
16
|
|
17
|
+
describe "initialization" do
|
18
|
+
|
19
|
+
it "should use specified attributes" do
|
20
|
+
Rivendell::API::Xport.new(:login_name => "dummy").login_name.should == "dummy"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#login_name" do
|
28
|
+
|
29
|
+
before do
|
30
|
+
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_groups.xml"))
|
31
|
+
|
32
|
+
def subject.make_request
|
33
|
+
list_groups
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be 'user' by default" do
|
38
|
+
subject.login_name.should == 'user'
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be used in queries" do
|
42
|
+
subject.login_name = "dummy"
|
43
|
+
subject.make_request
|
44
|
+
FakeWeb.last_request.form_data["LOGIN_NAME"].should == "dummy"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#password" do
|
50
|
+
|
51
|
+
before do
|
52
|
+
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_groups.xml"))
|
53
|
+
|
54
|
+
def subject.make_request
|
55
|
+
list_groups
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be '' by default" do
|
60
|
+
subject.password.should == ''
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be used in queries" do
|
64
|
+
subject.password = "dummy"
|
65
|
+
subject.make_request
|
66
|
+
FakeWeb.last_request.form_data["PASSWORD"].should == "dummy"
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "host" do
|
72
|
+
|
73
|
+
let(:host) { "example.com" }
|
74
|
+
|
75
|
+
subject { Rivendell::API::Xport.new :host => host }
|
76
|
+
|
77
|
+
before do
|
78
|
+
FakeWeb.register_uri(:post, "http://#{host}/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_groups.xml"))
|
79
|
+
def subject.make_request
|
80
|
+
list_groups
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should used host specified in constructor" do
|
85
|
+
subject.make_request
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".rdxport_uri" do
|
91
|
+
|
92
|
+
it "should use host" do
|
93
|
+
subject.host = "dummy"
|
94
|
+
subject.rdxport_uri.should == "http://dummy/rd-bin/rdxport.cgi"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
17
99
|
describe "#list_groups" do
|
18
100
|
|
19
101
|
before(:each) do
|
@@ -50,7 +132,7 @@ describe Rivendell::API::Xport do
|
|
50
132
|
|
51
133
|
end
|
52
134
|
|
53
|
-
describe "add_cart" do
|
135
|
+
describe "#add_cart" do
|
54
136
|
|
55
137
|
before(:each) do
|
56
138
|
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_add_cart.xml"))
|
@@ -77,7 +159,7 @@ describe Rivendell::API::Xport do
|
|
77
159
|
|
78
160
|
end
|
79
161
|
|
80
|
-
describe "add_cut" do
|
162
|
+
describe "#add_cut" do
|
81
163
|
|
82
164
|
before(:each) do
|
83
165
|
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_add_cut.xml"))
|
@@ -94,7 +176,7 @@ describe Rivendell::API::Xport do
|
|
94
176
|
|
95
177
|
end
|
96
178
|
|
97
|
-
describe "list_carts" do
|
179
|
+
describe "#list_carts" do
|
98
180
|
|
99
181
|
before(:each) do
|
100
182
|
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_carts.xml"))
|
@@ -116,4 +198,71 @@ describe Rivendell::API::Xport do
|
|
116
198
|
|
117
199
|
end
|
118
200
|
|
201
|
+
describe "#list_cuts" do
|
202
|
+
|
203
|
+
before(:each) do
|
204
|
+
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_cuts.xml"))
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should use COMMAND 9" do
|
208
|
+
subject.list_cuts(123)
|
209
|
+
FakeWeb.last_request["COMMAND"] == "9"
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should return Cuts" do
|
213
|
+
subject.list_cuts(123).map(&:description).should include("Rivendell 1", "Rivendell 2", "Rivendell 3")
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "#clear_cuts" do
|
219
|
+
|
220
|
+
let(:number) { 123 }
|
221
|
+
|
222
|
+
def cut(cut_number)
|
223
|
+
Rivendell::API::Cut.new :number => cut_number
|
224
|
+
end
|
225
|
+
|
226
|
+
let(:cuts) { [ cut(1), cut(2) ]}
|
227
|
+
|
228
|
+
it "should load specified Cart" do
|
229
|
+
subject.should_receive(:list_cuts).with(number).and_return(cuts)
|
230
|
+
subject.clear_cuts number
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should remove Cart's Cuts" do
|
234
|
+
subject.stub :list_cuts => cuts
|
235
|
+
subject.should_receive(:remove_cut).with(number, 1)
|
236
|
+
subject.should_receive(:remove_cut).with(number, 2)
|
237
|
+
subject.clear_cuts number
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
describe "#remove_cut" do
|
243
|
+
|
244
|
+
before(:each) do
|
245
|
+
FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => xml_response)
|
246
|
+
end
|
247
|
+
|
248
|
+
let(:cart_number) { 123 }
|
249
|
+
let(:cut_number) { 1 }
|
250
|
+
|
251
|
+
it "should use COMMAND 11" do
|
252
|
+
subject.remove_cut cart_number, cut_number
|
253
|
+
FakeWeb.last_request["COMMAND"] == "11"
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should specify cart_number" do
|
257
|
+
subject.remove_cut 123, cut_number
|
258
|
+
FakeWeb.last_request["CART_NUMBER"] == "123"
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should specify cut_number" do
|
262
|
+
subject.remove_cut cart_number, 1
|
263
|
+
FakeWeb.last_request["CUT_NUMBER"] == 1
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|
267
|
+
|
119
268
|
end
|
data/spec/support/fakeweb.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rivendell-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httmultiparty
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- spec/fixtures/rdxport_add_cut.xml
|
183
183
|
- spec/fixtures/rdxport_import.xml
|
184
184
|
- spec/fixtures/rdxport_list_carts.xml
|
185
|
+
- spec/fixtures/rdxport_list_cuts.xml
|
185
186
|
- spec/fixtures/rdxport_list_groups.xml
|
186
187
|
- spec/rivendell/api/xport_spec.rb
|
187
188
|
- spec/spec_helper.rb
|
@@ -202,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
203
|
version: '0'
|
203
204
|
segments:
|
204
205
|
- 0
|
205
|
-
hash:
|
206
|
+
hash: 3217387288640019372
|
206
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
208
|
none: false
|
208
209
|
requirements:
|
@@ -211,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
212
|
version: '0'
|
212
213
|
segments:
|
213
214
|
- 0
|
214
|
-
hash:
|
215
|
+
hash: 3217387288640019372
|
215
216
|
requirements: []
|
216
217
|
rubyforge_project:
|
217
218
|
rubygems_version: 1.8.23
|
@@ -224,6 +225,7 @@ test_files:
|
|
224
225
|
- spec/fixtures/rdxport_add_cut.xml
|
225
226
|
- spec/fixtures/rdxport_import.xml
|
226
227
|
- spec/fixtures/rdxport_list_carts.xml
|
228
|
+
- spec/fixtures/rdxport_list_cuts.xml
|
227
229
|
- spec/fixtures/rdxport_list_groups.xml
|
228
230
|
- spec/rivendell/api/xport_spec.rb
|
229
231
|
- spec/spec_helper.rb
|