rivendell-api 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'active_support/core_ext/string/inflections'
2
2
 
3
3
  module Rivendell::API
4
4
  class Cart
5
-
5
+
6
6
  attr_accessor :number, :type, :group_name, :title, :artist, :album, :year, :label, :client, :agency, :publisher, :composer, :user_defined, :usage_code, :forced_length, :average_length, :length_deviation, :average_segue_lenth, :average_hook_length, :cut_quantity, :last_cut_played, :validity, :enforce_length, :asyncronous, :owner, :metadata_datetime
7
7
 
8
8
  def initialize(attributes = {})
@@ -12,16 +12,20 @@ module Rivendell::API
12
12
  def number=(number)
13
13
  @number = (number ? number.to_i : nil)
14
14
  end
15
-
15
+
16
+ def has_title?
17
+ not [ nil, "", "[new cart]" ].include? title
18
+ end
19
+
16
20
  alias_method :group, :group_name
17
21
  alias_method :group=, :group_name=
18
-
22
+
19
23
  def cut_list=(cuts)
20
-
24
+
21
25
  end
22
26
 
23
27
  def macro_list=(cuts)
24
-
28
+
25
29
  end
26
30
 
27
31
  def method_missing(name, *arguments)
@@ -32,6 +36,6 @@ module Rivendell::API
32
36
  super
33
37
  end
34
38
  end
35
-
39
+
36
40
  end
37
41
  end
@@ -1,5 +1,5 @@
1
1
  module Rivendell
2
2
  module Api
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -39,8 +39,8 @@ module Rivendell::API
39
39
  def login_name
40
40
  @login_name ||= "user"
41
41
  end
42
-
43
- def password
42
+
43
+ def password
44
44
  @password ||= ""
45
45
  end
46
46
 
@@ -49,10 +49,10 @@ module Rivendell::API
49
49
  end
50
50
 
51
51
  def query(command, attributes = {})
52
- attributes = {
53
- :command => command,
54
- :login_name => login_name,
55
- :password => password
52
+ attributes = {
53
+ :command => command,
54
+ :login_name => login_name,
55
+ :password => password
56
56
  }.merge(attributes)
57
57
 
58
58
  attributes.inject({}) do |map, (key, value)|
@@ -65,7 +65,7 @@ module Rivendell::API
65
65
  logger.debug "Post #{command} #{attributes.inspect}"
66
66
 
67
67
  options = options.merge :query => query(command, attributes)
68
-
68
+
69
69
  response = self.class.post rdxport_uri, options
70
70
  response.error! unless response.success?
71
71
  response
@@ -83,10 +83,24 @@ module Rivendell::API
83
83
  Rivendell::API::Cart.new(response["cartAdd"]["cart"])
84
84
  end
85
85
 
86
+ def edit_cart(number, attributes = {})
87
+ attributes[:cart_number] = number
88
+ attributes.delete(:number)
89
+ attributes[:group_name] ||= attributes.delete(:group)
90
+
91
+ response = post COMMAND_EDITCART, attributes
92
+ Rivendell::API::Cart.new(response["cartList"]["cart"])
93
+ end
94
+
95
+ def list_cart(cart_number)
96
+ response = post COMMAND_LISTCART, :cart_number => cart_number
97
+ Rivendell::API::Cart.new response["cartList"]["cart"]
98
+ end
99
+
86
100
  # FIXME accents in carts create invalid UTF-8 response
87
101
  def list_carts(options = {})
88
102
  options[:group_name] ||= options.delete(:group)
89
-
103
+
90
104
  response = post COMMAND_LISTCARTS, options
91
105
  response["cartList"]["cart"].collect do |cart_xml|
92
106
  Rivendell::API::Cart.new(cart_xml)
@@ -123,8 +137,8 @@ module Rivendell::API
123
137
  end
124
138
 
125
139
  def import(cart_number, cut_number, file, options = {})
126
- arguments = {
127
- :channels => 2,
140
+ arguments = {
141
+ :channels => 2,
128
142
  :normalization_level => -13,
129
143
  :autotrim_level => -30,
130
144
  :use_metadata => true,
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+ <cartList>
3
+ <cart>
4
+ <number>1005</number>
5
+ <type>audio</type>
6
+ <groupName>TEST</groupName>
7
+ <title>[new cart]</title>
8
+ <artist></artist>
9
+ <album></album>
10
+ <year></year>
11
+ <label></label>
12
+ <client></client>
13
+ <agency></agency>
14
+ <publisher></publisher>
15
+ <composer></composer>
16
+ <userDefined></userDefined>
17
+ <usageCode>0</usageCode>
18
+ <forcedLength>0:00:00.0</forcedLength>
19
+ <averageLength>0:00:00.0</averageLength>
20
+ <lengthDeviation>0:00:00.0</lengthDeviation>
21
+ <averageSegueLenth>0:00:00.0</averageSegueLenth>
22
+ <averageHookLength>0:00:00.0</averageHookLength>
23
+ <cutQuantity>0</cutQuantity>
24
+ <lastCutPlayed>0</lastCutPlayed>
25
+ <validity>2</validity>
26
+ <enforceLength>false</enforceLength>
27
+ <asyncronous>false</asyncronous>
28
+ <owner></owner>
29
+ <metadataDatetime></metadataDatetime>
30
+ </cart>
31
+ </cartList>
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rivendell::API::Cart do
4
+
5
+ describe "has_title?" do
6
+
7
+ it "should return false if title is nil" do
8
+ subject.title = nil
9
+ subject.should_not have_title
10
+ end
11
+
12
+ it "should return false if title is empty" do
13
+ subject.title = ""
14
+ subject.should_not have_title
15
+ end
16
+
17
+ it "should return false if title is '[new cart]'" do
18
+ subject.title = "[new cart]"
19
+ subject.should_not have_title
20
+ end
21
+
22
+ it "should return true if title is something else" do
23
+ subject.title = "dummy"
24
+ subject.should have_title
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -15,7 +15,7 @@ describe Rivendell::API::Xport do
15
15
  end
16
16
 
17
17
  describe "initialization" do
18
-
18
+
19
19
  it "should use specified attributes" do
20
20
  Rivendell::API::Xport.new(:login_name => "dummy").login_name.should == "dummy"
21
21
  end
@@ -53,7 +53,7 @@ describe Rivendell::API::Xport do
53
53
  list_groups
54
54
  end
55
55
  end
56
-
56
+
57
57
  it "should be '' by default" do
58
58
  subject.password.should == ''
59
59
  end
@@ -78,7 +78,7 @@ describe Rivendell::API::Xport do
78
78
  list_groups
79
79
  end
80
80
  end
81
-
81
+
82
82
  it "should used host specified in constructor" do
83
83
  subject.make_request
84
84
  end
@@ -91,7 +91,7 @@ describe Rivendell::API::Xport do
91
91
  subject.host = "dummy"
92
92
  subject.rdxport_uri.should == "http://dummy/rd-bin/rdxport.cgi"
93
93
  end
94
-
94
+
95
95
  end
96
96
 
97
97
  describe "#list_groups" do
@@ -136,13 +136,13 @@ describe Rivendell::API::Xport do
136
136
  end
137
137
 
138
138
  describe "#add_cart" do
139
-
139
+
140
140
  before(:each) do
141
141
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_add_cart.xml"))
142
142
  end
143
143
 
144
144
  it "should use COMMAND 12" do
145
- subject.add_cart
145
+ subject.add_cart
146
146
  FakeWeb.last_request["COMMAND"] == "12"
147
147
  end
148
148
 
@@ -162,8 +162,31 @@ describe Rivendell::API::Xport do
162
162
 
163
163
  end
164
164
 
165
+ describe "#edit_cart" do
166
+
167
+ before(:each) do
168
+ FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_edit_cart.xml"))
169
+ end
170
+
171
+ it "should use COMMAND 14" do
172
+ subject.edit_cart 123
173
+ FakeWeb.last_request["COMMAND"] == "14"
174
+ end
175
+
176
+ it "should use specified number" do
177
+ subject.edit_cart 123
178
+ FakeWeb.last_request["CART_NUMBER"] == 123
179
+ end
180
+
181
+ it "should use group as group_name" do
182
+ subject.edit_cart 123, :group => "TEST"
183
+ FakeWeb.last_request["GROUP_NAME"] == "TEST"
184
+ end
185
+
186
+ end
187
+
165
188
  describe "#add_cut" do
166
-
189
+
167
190
  before(:each) do
168
191
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_add_cut.xml"))
169
192
  end
@@ -180,7 +203,7 @@ describe Rivendell::API::Xport do
180
203
  end
181
204
 
182
205
  describe "#list_carts" do
183
-
206
+
184
207
  before(:each) do
185
208
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_carts.xml"))
186
209
  end
@@ -202,7 +225,7 @@ describe Rivendell::API::Xport do
202
225
  end
203
226
 
204
227
  describe "#list_cuts" do
205
-
228
+
206
229
  before(:each) do
207
230
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => fixture_content("rdxport_list_cuts.xml"))
208
231
  end
@@ -227,7 +250,7 @@ describe Rivendell::API::Xport do
227
250
  end
228
251
 
229
252
  let(:cuts) { [ cut(1), cut(2) ]}
230
-
253
+
231
254
  it "should load specified Cart" do
232
255
  subject.should_receive(:list_cuts).with(number).and_return(cuts)
233
256
  subject.clear_cuts number
@@ -243,7 +266,7 @@ describe Rivendell::API::Xport do
243
266
  end
244
267
 
245
268
  describe "#remove_cut" do
246
-
269
+
247
270
  before(:each) do
248
271
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :body => xml_response)
249
272
  end
@@ -274,7 +297,7 @@ describe Rivendell::API::Xport do
274
297
  subject.class.should_receive(:post).with(anything, hash_including(:option => "value")).and_return(mock(:success? => true))
275
298
  subject.post "dummy", {}, :option => "value"
276
299
  end
277
-
300
+
278
301
  it "should raise an error when http response is an error" do
279
302
  FakeWeb.register_uri(:post, "http://localhost/rd-bin/rdxport.cgi", :status => ["403", "Error"])
280
303
  lambda { subject.post("dummy") }.should raise_error(Net::HTTPServerException)
metadata CHANGED
@@ -1,168 +1,158 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rivendell-api
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Alban Peignier
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-12-01 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: httmultiparty
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
17
+
18
+ date: 2013-08-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
22
  type: :runtime
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
33
+ name: httmultiparty
34
+ - !ruby/object:Gem::Dependency
23
35
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: activesupport
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
36
  type: :runtime
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ requirement: *id002
47
+ name: activesupport
48
+ - !ruby/object:Gem::Dependency
39
49
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: null_logger
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
50
  type: :runtime
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirement: *id003
61
+ name: null_logger
62
+ - !ruby/object:Gem::Dependency
55
63
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: simplecov
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
64
  type: :development
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirement: *id004
75
+ name: simplecov
76
+ - !ruby/object:Gem::Dependency
71
77
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
78
  type: :development
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirement: *id005
89
+ name: rspec
90
+ - !ruby/object:Gem::Dependency
87
91
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: guard
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
92
  type: :development
93
+ version_requirements: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ requirement: *id006
103
+ name: guard
104
+ - !ruby/object:Gem::Dependency
103
105
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: guard-rspec
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
106
  type: :development
107
+ version_requirements: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirement: *id007
117
+ name: guard-rspec
118
+ - !ruby/object:Gem::Dependency
119
119
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: rake
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
120
  type: :development
121
+ version_requirements: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ requirement: *id008
131
+ name: rake
132
+ - !ruby/object:Gem::Dependency
135
133
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: fakeweb
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
134
  type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- description: Use the rdxport interface to retrieve Groups, create/edit/retrieve Carts
159
- and Cuts, import Cut sound.
160
- email:
135
+ version_requirements: &id009 !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ requirement: *id009
145
+ name: fakeweb
146
+ description: Use the rdxport interface to retrieve Groups, create/edit/retrieve Carts and Cuts, import Cut sound.
147
+ email:
161
148
  - alban@tryphon.eu
162
149
  executables: []
150
+
163
151
  extensions: []
152
+
164
153
  extra_rdoc_files: []
165
- files:
154
+
155
+ files:
166
156
  - .gitignore
167
157
  - COPYING
168
158
  - COPYRIGHT
@@ -181,10 +171,12 @@ files:
181
171
  - spec/fixtures/empty.wav
182
172
  - spec/fixtures/rdxport_add_cart.xml
183
173
  - spec/fixtures/rdxport_add_cut.xml
174
+ - spec/fixtures/rdxport_edit_cart.xml
184
175
  - spec/fixtures/rdxport_import.xml
185
176
  - spec/fixtures/rdxport_list_carts.xml
186
177
  - spec/fixtures/rdxport_list_cuts.xml
187
178
  - spec/fixtures/rdxport_list_groups.xml
179
+ - spec/rivendell/api/cart_spec.rb
188
180
  - spec/rivendell/api/xport_spec.rb
189
181
  - spec/spec_helper.rb
190
182
  - spec/support/fakeweb.rb
@@ -192,42 +184,47 @@ files:
192
184
  - tasks/rspec.rake
193
185
  homepage: http://projects.tryphon.eu/rivendell-api
194
186
  licenses: []
187
+
195
188
  post_install_message:
196
189
  rdoc_options: []
197
- require_paths:
190
+
191
+ require_paths:
198
192
  - lib
199
- required_ruby_version: !ruby/object:Gem::Requirement
193
+ required_ruby_version: !ruby/object:Gem::Requirement
200
194
  none: false
201
- requirements:
202
- - - ! '>='
203
- - !ruby/object:Gem::Version
204
- version: '0'
205
- segments:
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ hash: 3
199
+ segments:
206
200
  - 0
207
- hash: 4025858966392152939
208
- required_rubygems_version: !ruby/object:Gem::Requirement
201
+ version: "0"
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
203
  none: false
210
- requirements:
211
- - - ! '>='
212
- - !ruby/object:Gem::Version
213
- version: '0'
214
- segments:
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ hash: 3
208
+ segments:
215
209
  - 0
216
- hash: 4025858966392152939
210
+ version: "0"
217
211
  requirements: []
212
+
218
213
  rubyforge_project:
219
- rubygems_version: 1.8.23
214
+ rubygems_version: 1.8.24
220
215
  signing_key:
221
216
  specification_version: 3
222
217
  summary: Pilots Rivendell via http/xml API
223
- test_files:
218
+ test_files:
224
219
  - spec/fixtures/empty.wav
225
220
  - spec/fixtures/rdxport_add_cart.xml
226
221
  - spec/fixtures/rdxport_add_cut.xml
222
+ - spec/fixtures/rdxport_edit_cart.xml
227
223
  - spec/fixtures/rdxport_import.xml
228
224
  - spec/fixtures/rdxport_list_carts.xml
229
225
  - spec/fixtures/rdxport_list_cuts.xml
230
226
  - spec/fixtures/rdxport_list_groups.xml
227
+ - spec/rivendell/api/cart_spec.rb
231
228
  - spec/rivendell/api/xport_spec.rb
232
229
  - spec/spec_helper.rb
233
230
  - spec/support/fakeweb.rb