goodercode-zune 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README +6 -0
- data/Rakefile +45 -0
- data/lib/zune/xml_dsl.rb +100 -0
- data/lib/zune.rb +126 -0
- metadata +68 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Kerry R. Wilson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rake'
|
8
|
+
require 'rake/clean'
|
9
|
+
require 'rake/gempackagetask'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
require 'rake/testtask'
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = 'goodercode-zune'
|
15
|
+
s.version = '0.1'
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.extra_rdoc_files = ['README', 'LICENSE']
|
18
|
+
s.summary = 'A Ruby API for accessing Zune user data'
|
19
|
+
s.description = s.summary
|
20
|
+
s.author = 'Kerry R Wilson'
|
21
|
+
s.email = 'kwilson@goodercode.com'
|
22
|
+
# s.executables = ['your_executable_here']
|
23
|
+
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
|
24
|
+
s.require_path = "lib"
|
25
|
+
s.bindir = "bin"
|
26
|
+
end
|
27
|
+
|
28
|
+
Rake::GemPackageTask.new(spec) do |p|
|
29
|
+
p.gem_spec = spec
|
30
|
+
p.need_tar = true
|
31
|
+
p.need_zip = true
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::RDocTask.new do |rdoc|
|
35
|
+
files =['README', 'LICENSE', 'lib/**/*.rb']
|
36
|
+
rdoc.rdoc_files.add(files)
|
37
|
+
rdoc.main = "README" # page to start on
|
38
|
+
rdoc.title = "ruby-zune Docs"
|
39
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
40
|
+
rdoc.options << '--line-numbers'
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::TestTask.new do |t|
|
44
|
+
t.test_files = FileList['test/**/*.rb']
|
45
|
+
end
|
data/lib/zune/xml_dsl.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
module Zune
|
2
|
+
module XmlDsl
|
3
|
+
|
4
|
+
class ::String
|
5
|
+
|
6
|
+
# user_data.to_node_name returns userData
|
7
|
+
def to_node_name
|
8
|
+
|
9
|
+
first = true
|
10
|
+
noded = ''
|
11
|
+
self.split('_').each do |v|
|
12
|
+
if first
|
13
|
+
noded = v
|
14
|
+
first = false
|
15
|
+
else
|
16
|
+
noded += v[0..0].upcase + v[1..-1]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
noded
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
DEFAULT_NODE = 'user'
|
25
|
+
|
26
|
+
def node
|
27
|
+
@node ||= DEFAULT_NODE
|
28
|
+
end
|
29
|
+
|
30
|
+
def node=(node)
|
31
|
+
@node = node
|
32
|
+
end
|
33
|
+
|
34
|
+
def context_template
|
35
|
+
{ :simple => [], :images => [], :arrays => [] }
|
36
|
+
end
|
37
|
+
|
38
|
+
def root_context
|
39
|
+
@root_context ||= context_template
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_context
|
43
|
+
context_path.last
|
44
|
+
end
|
45
|
+
|
46
|
+
def context_path
|
47
|
+
@context_path ||= [ root_context ]
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_node(with_node)
|
51
|
+
node = with_node
|
52
|
+
yield
|
53
|
+
end
|
54
|
+
|
55
|
+
def simple_value(*values)
|
56
|
+
values.each do |value|
|
57
|
+
current_context[:simple] << { :name => value, :node => node }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def image_value(*values)
|
62
|
+
values.each do |value|
|
63
|
+
current_context[:images] << { :name => value, :node => node }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_array(name)
|
68
|
+
array_context = context_template
|
69
|
+
current_context[:arrays] << { :name => name, :context => array_context }
|
70
|
+
context_path.push array_context
|
71
|
+
yield
|
72
|
+
context_path.pop
|
73
|
+
end
|
74
|
+
|
75
|
+
module Instance
|
76
|
+
|
77
|
+
def parse_xml(xml)
|
78
|
+
|
79
|
+
document = REXML::Document.new xml
|
80
|
+
self.class.context.each do |node, properties|
|
81
|
+
|
82
|
+
properties[:simple].each do |property|
|
83
|
+
element_name = "#{node}/#{property.to_s.to_node_name}"
|
84
|
+
value = document.root.elements[element_name].text
|
85
|
+
instance_variable_set "@#{property}".to_sym, value
|
86
|
+
end
|
87
|
+
|
88
|
+
properties[:image].each do |property|
|
89
|
+
element_name = "#{node}/image[@format='#{property.to_s.to_node_name}']/url"
|
90
|
+
value = document.root.elements[element_name].text
|
91
|
+
instance_variable_set "@#{property}".to_sym, value
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/zune.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'xml/mapping'
|
2
|
+
|
3
|
+
module Zune
|
4
|
+
|
5
|
+
class ::Symbol
|
6
|
+
|
7
|
+
# user_data.to_node_name returns userData
|
8
|
+
def to_node_name
|
9
|
+
|
10
|
+
first = true
|
11
|
+
noded = ''
|
12
|
+
self.to_s.split('_').each do |v|
|
13
|
+
if first
|
14
|
+
noded = v
|
15
|
+
first = false
|
16
|
+
else
|
17
|
+
noded += v[0..0].upcase + v[1..-1]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
noded
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Badge; end;
|
26
|
+
class Album; end;
|
27
|
+
class Artist; end;
|
28
|
+
class Track; end;
|
29
|
+
|
30
|
+
class ZuneCard
|
31
|
+
|
32
|
+
include XML::Mapping
|
33
|
+
|
34
|
+
# simple properties
|
35
|
+
[:id, :label, :first_name, :status].each do |name|
|
36
|
+
text_node name, "user/#{name.to_node_name}", :default_value => nil
|
37
|
+
end
|
38
|
+
|
39
|
+
[:name, :location, :bio, :total_plays, :user_id].each do |name|
|
40
|
+
text_node name, "user/manifest/userData/#{name.to_node_name}", :default_value => nil
|
41
|
+
end
|
42
|
+
|
43
|
+
# images
|
44
|
+
[:tile_big, :tile_small].each do |format|
|
45
|
+
text_node format, "user/image[@format='#{format.to_node_name}']/url", :default_value => nil
|
46
|
+
end
|
47
|
+
|
48
|
+
[:background_large, :background_small].each do |format|
|
49
|
+
text_node format, "user/manifest/userData/image[@format='#{format.to_node_name}']/url", :default_value => nil
|
50
|
+
end
|
51
|
+
|
52
|
+
array_node :badges, 'user/manifest/userData/badges', 'badge', :class => Badge, :default_value => []
|
53
|
+
array_node :following, 'user/manifest/userData/following', 'followinfo/artist', :class => Artist, :default_value => []
|
54
|
+
|
55
|
+
[ :favs, :recent_spins ].each do |playlist|
|
56
|
+
array_node playlist, "user/manifest/playlists/playlist[@type='#{playlist}']", 'track', :class => Track, :default_value => []
|
57
|
+
end
|
58
|
+
|
59
|
+
array_node :most_played, 'user/manifest/playlists/playlist[@type=\'most_played\']', 'artist', :class => Artist, :default_value => []
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class Badge
|
64
|
+
|
65
|
+
include XML::Mapping
|
66
|
+
|
67
|
+
[ :id, :label, :description, :type ].each do |name|
|
68
|
+
text_node name, name.to_s, :default_value => nil
|
69
|
+
end
|
70
|
+
|
71
|
+
[ :badge_image_small, :badge_image_large ].each do |format|
|
72
|
+
text_node format, "image[@format='#{format.to_node_name}']/url", :default_value => nil
|
73
|
+
end
|
74
|
+
|
75
|
+
object_node :album, 'album', :class => Album, :default_value => nil
|
76
|
+
object_node :artist, 'artist', :class => Artist, :default_value => nil
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
class Album
|
81
|
+
|
82
|
+
include XML::Mapping
|
83
|
+
|
84
|
+
[ :id, :label, :release_time, :url ].each do |name|
|
85
|
+
text_node name, name.to_node_name, :default_value => nil
|
86
|
+
end
|
87
|
+
|
88
|
+
[ :album_cover_large, :album_cover_small ].each do |format|
|
89
|
+
text_node format, "image[@format='#{format.to_node_name}']/url", :default_value => nil
|
90
|
+
end
|
91
|
+
|
92
|
+
object_node :artist, 'artist', :class => Artist, :default_value => nil
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
class Artist
|
97
|
+
|
98
|
+
include XML::Mapping
|
99
|
+
|
100
|
+
[ :id, :label, :url, :total_plays ].each do |name|
|
101
|
+
text_node name, name.to_node_name, :default_value => nil
|
102
|
+
end
|
103
|
+
|
104
|
+
[ :artist_image_large, :artist_image_small ].each do |format|
|
105
|
+
text_node format, "image[@format='#{format.to_node_name}']/url", :default_value => nil
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
class Track
|
111
|
+
|
112
|
+
include XML::Mapping
|
113
|
+
|
114
|
+
[ :id, :label ].each do |name|
|
115
|
+
text_node name, name.to_node_name, :default_value => nil
|
116
|
+
end
|
117
|
+
|
118
|
+
[ :buy, :send, :set_fav ].each do |url|
|
119
|
+
text_node "#{url}_url".to_sym, "#{url.to_node_name}URL", :default_value => nil
|
120
|
+
end
|
121
|
+
|
122
|
+
object_node :album, 'album', :default_value => nil
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goodercode-zune
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Kerry R Wilson
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2010-10-19 00:00:00 -05:00
|
17
|
+
default_executable:
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: A Ruby API for accessing Zune user data
|
21
|
+
email: kwilson@goodercode.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions: []
|
25
|
+
|
26
|
+
extra_rdoc_files:
|
27
|
+
- README
|
28
|
+
- LICENSE
|
29
|
+
files:
|
30
|
+
- LICENSE
|
31
|
+
- README
|
32
|
+
- Rakefile
|
33
|
+
- lib/zune/xml_dsl.rb
|
34
|
+
- lib/zune.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: A Ruby API for accessing Zune user data
|
67
|
+
test_files: []
|
68
|
+
|