rtunesu 0.4.0 → 0.4.1

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.0
1
+ 0.4.1
data/index.html ADDED
@@ -0,0 +1,80 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+ <head>
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
7
+
8
+ <title>trek/rtunesu @ GitHub</title>
9
+
10
+ <style type="text/css">
11
+ body {
12
+ margin-top: 1.0em;
13
+ background-color: #c4122a;
14
+ font-family: "Helvetica,Arial,FreeSans";
15
+ color: #ffffff;
16
+ }
17
+ #container {
18
+ margin: 0 auto;
19
+ width: 700px;
20
+ }
21
+ h1 { font-size: 3.8em; color: #3bedd5; margin-bottom: 3px; }
22
+ h1 .small { font-size: 0.4em; }
23
+ h1 a { text-decoration: none }
24
+ h2 { font-size: 1.5em; color: #3bedd5; }
25
+ h3 { text-align: center; color: #3bedd5; }
26
+ a { color: #3bedd5; }
27
+ .description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
28
+ .download { float: right; }
29
+ pre { background: #000; color: #fff; padding: 15px;}
30
+ hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
31
+ .footer { text-align:center; padding-top:30px; font-style: italic; }
32
+ </style>
33
+
34
+ </head>
35
+
36
+ <body>
37
+ <a href="http://github.com/trek/rtunesu"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
38
+
39
+ <div id="container">
40
+
41
+ <div class="download">
42
+ <a href="http://github.com/trek/rtunesu/zipball/master">
43
+ <img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a>
44
+ <a href="http://github.com/trek/rtunesu/tarball/master">
45
+ <img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a>
46
+ </div>
47
+
48
+ <h1><a href="http://github.com/trek/rtunesu">rtunesu</a>
49
+ <span class="small">by <a href="http://github.com/trek">trek</a></span></h1>
50
+
51
+ <div class="description">
52
+ Gem for interacting with Apple's iTunes U Webservices
53
+ </div>
54
+
55
+ <h2>Authors</h2>
56
+ <p>Trek Glowacki (pietrekg@umich.edu)
57
+ <h2>Contact</h2>
58
+ <p>Trek Glowacki (pietrekg@umich.edu)
59
+
60
+
61
+ <h2>Download</h2>
62
+ <p>
63
+ You can download this project in either
64
+ <a href="http://github.com/trek/rtunesu/zipball/master">zip</a> or
65
+ <a href="http://github.com/trek/rtunesu/tarball/master">tar</a> formats.
66
+ </p>
67
+ <p>You can also clone the project with <a href="http://git-scm.com">Git</a>
68
+ by running:
69
+ <pre>$ git clone git://github.com/trek/rtunesu</pre>
70
+ </p>
71
+
72
+ <div class="footer">
73
+ get the source code on GitHub : <a href="http://github.com/trek/rtunesu">trek/rtunesu</a>
74
+ </div>
75
+
76
+ </div>
77
+
78
+
79
+ </body>
80
+ </html>
@@ -64,7 +64,7 @@ module RTunesU
64
64
  boundary = "x" + Time.now.to_i.to_s(16)
65
65
 
66
66
  headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
67
- headers["User-Agent"] = "RTunesU/#{RTunesU::VERSION::STRING}"
67
+ headers["User-Agent"] = "RTunesU/#{RTunesU::VERSION}"
68
68
  params.each do |key,value|
69
69
  esc_key = key.to_s
70
70
  body << "--#{boundary}#{crlf}"
@@ -8,4 +8,8 @@ module RTunesU
8
8
  def delete(connection)
9
9
  raise "You cannot delete your entire site"
10
10
  end
11
+
12
+ def create(connection)
13
+ raise "only apple can create a Site for you."
14
+ end
11
15
  end
@@ -24,7 +24,6 @@ module RTunesU
24
24
  # c.groups << Group.new(:name => 'Videos') # Adds the new Group object to the end of hte Groups array
25
25
  # c.groups.collect {|g| g.name} # ['Lectures', 'Videos']
26
26
  class Entity
27
-
28
27
  attr_accessor :connection, :parent, :parent_handle, :saved, :source_xml
29
28
  attr_reader :handle
30
29
 
@@ -44,6 +43,10 @@ module RTunesU
44
43
  @base_connection = connection
45
44
  end
46
45
 
46
+ def self.base_connection=(connection)
47
+ self.set_base_connection(connection)
48
+ end
49
+
47
50
  def self.validates!(name, values)
48
51
  return
49
52
  end
@@ -122,26 +125,6 @@ module RTunesU
122
125
  end
123
126
  end
124
127
 
125
- # Finds a specific entity in iTunes U. To find an entity you will need to know both its type
126
- # (Course, Group, etc) and handle. Handles uniquely identify entities in iTunes U and the entity
127
- # type is used to search the returned XML for the specific entity you are looking for. For example,
128
- # Course.find(123456, rtunes_connection_object)
129
- def self.find(handle, connection = nil)
130
- connection ||= self.base_connection
131
-
132
- entity = self.new
133
- entity.instance_variable_set('@handle', handle)
134
- entity.load_from_xml(connection.upload_file(RTunesU::SHOW_TREE_FILE, handle))
135
- entity
136
-
137
- rescue LocationNotFound
138
- raise EntityNotFound, "Could not find #{entity.class_name} with handle of #{handle}."
139
- end
140
-
141
- def load_from_xml(xml_or_entity)
142
- self.source_xml = Hpricot.XML(xml_or_entity).at("//ITunesUResponse//#{self.class_name}//Handle[text()=#{self.handle}]..")
143
- end
144
-
145
128
  # Edits stores the changes made to an entity
146
129
  def edits
147
130
  @edits ||= {}
@@ -204,49 +187,6 @@ module RTunesU
204
187
  }
205
188
  end
206
189
 
207
- # called when .save is called on an object that is already stored in iTunes U
208
- def update(connection = nil)
209
- connection ||= self.base_connection
210
-
211
- connection.process(Document::Merge.new(self).xml)
212
- edits.clear
213
- self
214
- end
215
-
216
- # called when .save is called on an object that has no Handle (i.e. does not already exist in iTunes U)
217
- def create(connection = nil)
218
- connection ||= self.base_connection
219
-
220
- response = Hpricot.XML(connection.process(Document::Add.new(self).xml))
221
- raise CannotSave, response.at('error').innerHTML if response.at('error')
222
- @handle = response.at('AddedObjectHandle').innerHTML
223
- edits.clear
224
- self
225
- end
226
-
227
- # Saves the entity to iTunes U. Save takes single argument (an iTunes U connection object).
228
- # If the entity is unsaved this will create the entity and populate its handle attribte.
229
- # If the entity has already been saved it will send the updated data (if any) to iTunes U.
230
- def save(connection = nil)
231
- connection ||= self.base_connection
232
- saved? ? update(connection) : create(connection)
233
- end
234
-
235
- # Has the entity be previously saved in iTunes U
236
- def saved?
237
- self.handle ? true : false
238
- end
239
-
240
- # Deletes the entity from iTunes U. This cannot be undone.
241
- def delete(connection = nil)
242
- connection ||= self.base_connection
243
-
244
- response = Hpricot.XML(connection.process(Document::Delete.new(self).xml))
245
- raise Exception, response.at('error').innerHTML if response.at('error')
246
- @handle = nil
247
- self
248
- end
249
-
250
190
  def inspect
251
191
  inspected = "#<#{self.class.to_s} handle:#{@handle.inspect} "
252
192
  self.class.attributes.each do |attribute|
@@ -0,0 +1,75 @@
1
+ module RTunesU
2
+ module Persistence
3
+ module Finder
4
+ # Finds a specific entity in iTunes U. To find an entity you will need to know both its type
5
+ # (Course, Group, etc) and handle. Handles uniquely identify entities in iTunes U and the entity
6
+ # type is used to search the returned XML for the specific entity you are looking for. For example,
7
+ # Course.find(123456, rtunes_connection_object)
8
+ def find(handle, connection = nil)
9
+ connection ||= self.base_connection
10
+
11
+ entity = self.new
12
+ entity.instance_variable_set('@handle', handle)
13
+ entity.load_from_xml(connection.upload_file(RTunesU::SHOW_TREE_FILE, handle))
14
+ entity
15
+
16
+ rescue LocationNotFound
17
+ raise EntityNotFound, "Could not find #{entity.class_name} with handle of #{handle}."
18
+ end
19
+ end
20
+
21
+ def self.included(base)
22
+ base.extend(Finder)
23
+ end
24
+
25
+ def load_from_xml(xml_or_entity)
26
+ self.source_xml = Hpricot.XML(xml_or_entity).at("//ITunesUResponse//#{self.class_name}//Handle[text()=#{self.handle}]..")
27
+ end
28
+
29
+ # called when .save is called on an object that is already stored in iTunes U
30
+ def update(connection = nil)
31
+ connection ||= self.base_connection
32
+
33
+ connection.process(Document::Merge.new(self).xml)
34
+ edits.clear
35
+ self
36
+ end
37
+
38
+ # called when .save is called on an object that has no Handle (i.e. does not already exist in iTunes U)
39
+ def create(connection = nil)
40
+ connection ||= self.base_connection
41
+
42
+ response = Hpricot.XML(connection.process(Document::Add.new(self).xml))
43
+ raise CannotSave, response.at('error').innerHTML if response.at('error')
44
+ @handle = response.at('AddedObjectHandle').innerHTML
45
+ edits.clear
46
+ self
47
+ end
48
+
49
+ # Saves the entity to iTunes U. Save takes single argument (an iTunes U connection object).
50
+ # If the entity is unsaved this will create the entity and populate its handle attribte.
51
+ # If the entity has already been saved it will send the updated data (if any) to iTunes U.
52
+ def save(connection = nil)
53
+ connection ||= self.base_connection
54
+ saved? ? update(connection) : create(connection)
55
+ end
56
+
57
+ # Has the entity be previously saved in iTunes U
58
+ def saved?
59
+ self.handle ? true : false
60
+ end
61
+
62
+ # Deletes the entity from iTunes U. This cannot be undone.
63
+ def delete(connection = nil)
64
+ connection ||= self.base_connection
65
+
66
+ response = Hpricot.XML(connection.process(Document::Delete.new(self).xml))
67
+ raise Exception, response.at('error').innerHTML if response.at('error')
68
+ @handle = nil
69
+ self
70
+ end
71
+ end
72
+ [Course, Division, Group, Section, Site, Track].each do |entity|
73
+ entity.send(:include, Persistence)
74
+ end
75
+ end
data/lib/rtunesu.rb CHANGED
@@ -4,7 +4,6 @@ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname
4
4
  require 'hpricot'
5
5
  require 'activesupport'
6
6
 
7
- require 'rtunesu/version'
8
7
  require 'rtunesu/connection'
9
8
  require 'rtunesu/user'
10
9
  require 'rtunesu/document'
@@ -19,6 +18,7 @@ require 'rtunesu/entities/section'
19
18
  require 'rtunesu/entities/site'
20
19
  require 'rtunesu/entities/track'
21
20
  require 'rtunesu/entities/theme'
21
+ require 'rtunesu/persistence'
22
22
  require 'rtunesu/log'
23
23
  require 'rtunesu/associations'
24
24
 
@@ -28,4 +28,6 @@ module RTunesU
28
28
  BROWSE_URL = 'https://deimos.apple.com/WebObjects/Core.woa/Browse'.freeze
29
29
  SHOW_TREE_URL = 'https://deimos.apple.com/WebObjects/Core.woa/API/ShowTree'.freeze
30
30
  SHOW_TREE_FILE = ::File.new(::File.join(::File.dirname(__FILE__), 'show_tree.xml'))
31
+
32
+ VERSION = ::File.read(::File.join(::File.dirname(__FILE__), '../VERSION')).strip!.freeze
31
33
  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.0
4
+ version: 0.4.1
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-27 00:00:00 -04:00
12
+ date: 2009-10-30 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,7 @@ files:
57
57
  - README.txt
58
58
  - Rakefile
59
59
  - VERSION
60
+ - index.html
60
61
  - lib/rtunesu.rb
61
62
  - lib/rtunesu/associations.rb
62
63
  - lib/rtunesu/connection.rb
@@ -74,8 +75,8 @@ files:
74
75
  - lib/rtunesu/entities/track.rb
75
76
  - lib/rtunesu/entity.rb
76
77
  - lib/rtunesu/log.rb
78
+ - lib/rtunesu/persistence.rb
77
79
  - lib/rtunesu/user.rb
78
- - lib/rtunesu/version.rb
79
80
  - lib/show_tree.xml
80
81
  - script/console
81
82
  - script/destroy
@@ -1,5 +0,0 @@
1
- module RTunesU
2
- module VERSION #:nodoc:
3
- STRING = File.read(File.join(File.dirname(__FILE__), '../../VERSION')).strip!.freeze
4
- end
5
- end