rtunesu 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -6,14 +6,27 @@ module RTunesU
6
6
  @owner = owner
7
7
  @owner.edits[name] = self
8
8
  @edits = []
9
- self.from_xml(name)
10
9
  end
11
10
 
12
11
  end
13
12
 
14
13
  class HasAEntityCollectionProxy < SubentityAssociationProxy
15
14
  delegate :class, :to => :target
16
- attr_reader :target
15
+ attr_reader :target
16
+
17
+ def self.new_or_nil(source_xml, owner, name)
18
+ return nil if source_xml.empty?
19
+ proxy = self.new(source_xml, owner, name)
20
+ proxy.from_xml(name)
21
+ return proxy
22
+ end
23
+
24
+ def self.new_from_target(target, owner, name)
25
+ proxy = self.new(nil, owner, name)
26
+ proxy.instance_variable_set("@target", target)
27
+ return proxy
28
+ end
29
+
17
30
  def from_xml(name)
18
31
  if @source_xml
19
32
  @target = "RTunesU::#{name}".constantize.new(:source_xml => @source_xml.first, :parent_handle => @owner.handle)
@@ -22,8 +35,8 @@ module RTunesU
22
35
  end
23
36
  end
24
37
 
25
- def to_xml(builder)
26
- @target.to_xml(builder) if @target.edits.any?
38
+ def to_xml(xml_builder = Builder::XmlMarkup.new)
39
+ @target.to_xml(xml_builder) if @target.edits.any?
27
40
  end
28
41
 
29
42
  def method_missing(method_name, *args)
@@ -34,6 +47,11 @@ module RTunesU
34
47
  class HasNEntityCollectionProxy < SubentityAssociationProxy
35
48
  delegate :[], :at, :first, :last, :size, :clear, :to => :target
36
49
  attr_reader :target, :edits
50
+
51
+ def initialize(source_xml, owner, name)
52
+ super
53
+ self.from_xml(name)
54
+ end
37
55
 
38
56
  def from_xml(name)
39
57
  if @source_xml
@@ -5,6 +5,15 @@ module RTunesU
5
5
  validates! :polling_interval, [:never, :daily]
6
6
  validates! :security_type, [:none, 'Basic Authentication']
7
7
 
8
+ # an ExternalFeed must serialize in a specific order
9
+ def to_xml(xml_builder = Builder::XmlMarkup.new)
10
+ xml_builder.tag!('ExternalFeed') do
11
+ %w(URL OwnerEmail PollingInterval SecurityType SignatureType BasicAuthUsername BasicAuthPassword).each do |tag_name|
12
+ xml_builder.tag!(tag_name, self.edits[tag_name]) if self.edits[tag_name]
13
+ end
14
+ end
15
+ end
16
+
8
17
  # As an entirely nested entity ExternalFeed instances don't have a parent handle. However, something 'truthy' needs
9
18
  # to be presnet for proper XML document genration.
10
19
  def parent_handle # :nodoc:
@@ -1,6 +1,6 @@
1
1
  module RTunesU
2
2
  class File < Entity
3
- composed_of :name, :path, :size, :shared
3
+ composed_of :name, :path, :shared
4
4
  composed_of :size, :readonly => true
5
5
  end
6
6
  end
@@ -2,10 +2,38 @@ module RTunesU
2
2
  # A Group in iTunes U. A Group is expressed as a tab in the iTunes interface.
3
3
 
4
4
  class Group < Entity
5
+ ACCESS = {
6
+ :no_access => "No Access",
7
+ :steaming => "Streaming",
8
+ :download => "Download",
9
+ :drop_box => "Drop Box",
10
+ :shared => "Shared",
11
+ :edit => "Edit"
12
+ }
13
+ TYPES = {
14
+ :feed => "Feed"
15
+ }
5
16
  composed_of :name, :group_type, :short_name, :allow_subscription, :explicit
6
17
  composed_of :aggregate_file_size, :readonly => true
7
18
  validates! :group_type, [:simple, :smart, :feed]
8
19
  has_a :external_feed
9
20
  has_n :permissions, :tracks, :shared_objects
21
+
22
+ # a Group must serialize in a specific order
23
+ def to_xml(xml_builder = Builder::XmlMarkup.new)
24
+ xml_builder.tag!('Group') do
25
+ %w(Name Handle GroupType Explicit).each do |tag_name|
26
+ xml_builder.tag!(tag_name, self.edits[tag_name]) if self.edits[tag_name]
27
+ end
28
+
29
+ self.tracks.to_xml(xml_builder)
30
+ self.permissions.to_xml(xml_builder)
31
+
32
+ %w(AllowSubscription).each do |tag_name|
33
+ xml_builder.tag!(tag_name, self.edits[tag_name]) if self.edits[tag_name]
34
+ end
35
+ self.external_feed.to_xml(xml_builder) if self.external_feed
36
+ end
37
+ end
10
38
  end
11
39
  end
@@ -1,4 +1,6 @@
1
1
  module RTunesU
2
2
  class Tempalte < Entity
3
+ composed_of :name, :handle
4
+ has_n :permissions
3
5
  end
4
6
  end
@@ -52,7 +52,7 @@ module RTunesU
52
52
  end
53
53
 
54
54
  def self.composed_of(*names)
55
- options = names.last.is_a?(Hash) ? names.pop : {}
55
+ options = names.extract_options!
56
56
  self.attributes.merge(names)
57
57
  names.each do |name|
58
58
  storage_name = options[:as] || name.to_s.camelize
@@ -70,24 +70,26 @@ module RTunesU
70
70
  end
71
71
 
72
72
  def self.has_a(*names)
73
- options = names.last.is_a?(Hash) ? names.pop : {}
73
+ options = names.extract_options!
74
74
  self.attributes.merge(names)
75
75
  names.each do |name|
76
76
  define_method(name) do
77
77
  entity_name = options[:as] || name.to_s.camelize
78
- instance_variable_get("@#{name}") || instance_variable_set("@#{name}", RTunesU::HasAEntityCollectionProxy.new(self.source_xml./(entity_name), self, entity_name))
78
+ edits[entity_name] || RTunesU::HasAEntityCollectionProxy.new_or_nil(self.source_xml./(entity_name), self, entity_name)
79
79
  end
80
80
 
81
81
  unless options[:readonly]
82
82
  define_method(:"#{name}=") do |arg|
83
- edits[options[:as] || name.to_s.camelize] = arg
83
+ entity_name = options[:as] || name.to_s.camelize
84
+ RTunesU::HasAEntityCollectionProxy.new_from_target(arg, self, entity_name)
85
+ #edits[options[:as] || name.to_s.camelize] = arg
84
86
  end
85
87
  end
86
88
  end
87
89
  end
88
90
 
89
91
  def self.has_n(*names)
90
- options = names.last.is_a?(Hash) ? names.pop : {}
92
+ options = names.extract_options!
91
93
  self.attributes.merge(names)
92
94
  names.each do |name|
93
95
  define_method(name) do
@@ -180,11 +182,11 @@ module RTunesU
180
182
  # Converts the entities changed attributes and subentities to XML. Called by Document when building
181
183
  # documents to transfer to iTunes U.
182
184
  def to_xml(xml_builder = Builder::XmlMarkup.new)
183
- xml_builder.tag!(self.class_name) {
185
+ xml_builder.tag!(self.class_name) do
184
186
  self.edits.each do |attribute,edit|
185
187
  edit.is_a?(SubentityAssociationProxy) ? edit.to_xml(xml_builder) : xml_builder.tag!(attribute, edit)
186
188
  end
187
- }
189
+ end
188
190
  end
189
191
 
190
192
  def inspect
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
2
+ require File.dirname(__FILE__) + '/../entity_spec.rb'
3
+
4
+ include RTunesU
5
+
6
+ describe RTunesU::File do
7
+ before(:each) do
8
+ @klass = RTunesU::File
9
+ @entity = RTunesU::File.new
10
+ @file = @entity
11
+ @attributes = {:name => 'foo.png'}
12
+ end
13
+
14
+ it_should_behave_like "an Entity with attribute assignment"
15
+
16
+ it_should_be_composed_of :name, :path, :shared
17
+ it_should_be_composed_of :size, :readonly => true
18
+ end
@@ -16,4 +16,40 @@ describe Group do
16
16
  it_should_be_composed_of :aggregate_file_size, :readonly => true
17
17
  it_should_have_many :permissions, :tracks, :shared_objects
18
18
  it_should_have_a :external_feed
19
+
20
+ describe "external feed" do
21
+ it "should return nil if unset" do
22
+ @entity.external_feed.should be_nil
23
+ end
24
+
25
+ it "should return feed from XML if present" do
26
+ id = 2628591672
27
+ mock_connect!
28
+ FakeWeb.register_uri(:get,
29
+ "https://deimos.apple.com/WebObjects/Core.woa/API/GetUploadURL/example.edu.#{id}?credentials=Administrator%40urn%3Amace%3Aitunesu.com%3Asites%3Aexample.edu&identity=%22Admin%22+%3Cadmin%40example.edu%3E+%28admin%29+%5B0%5D&time=1214619134&signature=121a6cf76c9c5ecda41450d87e3394b9d02c570a5f76b2bd16287f860f068302&type=XMLControlFile",
30
+ :body => mock_upload_url_for_handle(id))
31
+ FakeWeb.register_uri(:post, mock_upload_url_for_handle(id), :body => response_for(@klass, 'show', true))
32
+ @entity = Group.find(id)
33
+ @entity.external_feed.should_not be_nil
34
+ FakeWeb.clean_registry
35
+ end
36
+
37
+ it "should return a feed if set" do
38
+ @entity.external_feed = ExternalFeed.new
39
+ @entity.external_feed.should_not be_nil
40
+ end
41
+ end
42
+
43
+ describe "access rights" do
44
+ it "should have the correct access rights as constant" do
45
+ Group::ACCESS.should == {
46
+ :no_access => "No Access",
47
+ :steaming => "Streaming",
48
+ :download => "Download",
49
+ :drop_box => "Drop Box",
50
+ :shared => "Shared",
51
+ :edit => "Edit"
52
+ }
53
+ end
54
+ end
19
55
  end
data/spec/spec_helper.rb CHANGED
@@ -48,7 +48,7 @@ def it_should_have_a(*associations)
48
48
  associations.each do |association|
49
49
  it "should have a #{association}" do
50
50
  @entity.should respond_to(association)
51
- @entity.send(association).should be_kind_of(HasAEntityCollectionProxy)
51
+ # @entity.send(association).should be_kind_of(HasAEntityCollectionProxy)
52
52
  end
53
53
  end
54
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtunesu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trek Glowacki
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-30 00:00:00 -04:00
12
+ date: 2009-11-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -88,6 +88,7 @@ files:
88
88
  - spec/entities/course_spec.rb
89
89
  - spec/entities/division_spec.rb
90
90
  - spec/entities/external_feed_spec.rb
91
+ - spec/entities/file_spec.rb
91
92
  - spec/entities/group_spec.rb
92
93
  - spec/entities/permission_spec.rb
93
94
  - spec/entities/section_spec.rb
@@ -183,6 +184,7 @@ test_files:
183
184
  - spec/entities/course_spec.rb
184
185
  - spec/entities/division_spec.rb
185
186
  - spec/entities/external_feed_spec.rb
187
+ - spec/entities/file_spec.rb
186
188
  - spec/entities/group_spec.rb
187
189
  - spec/entities/permission_spec.rb
188
190
  - spec/entities/section_spec.rb