goodercode-zune 0.1 → 0.2

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.
Files changed (4) hide show
  1. data/Rakefile +2 -6
  2. data/lib/zune.rb +20 -5
  3. metadata +3 -4
  4. data/lib/zune/xml_dsl.rb +0 -100
data/Rakefile CHANGED
@@ -1,8 +1,3 @@
1
- #
2
- # To change this template, choose Tools | Templates
3
- # and open the template in the editor.
4
-
5
-
6
1
  require 'rubygems'
7
2
  require 'rake'
8
3
  require 'rake/clean'
@@ -12,13 +7,14 @@ require 'rake/testtask'
12
7
 
13
8
  spec = Gem::Specification.new do |s|
14
9
  s.name = 'goodercode-zune'
15
- s.version = '0.1'
10
+ s.version = '0.2'
16
11
  s.has_rdoc = true
17
12
  s.extra_rdoc_files = ['README', 'LICENSE']
18
13
  s.summary = 'A Ruby API for accessing Zune user data'
19
14
  s.description = s.summary
20
15
  s.author = 'Kerry R Wilson'
21
16
  s.email = 'kwilson@goodercode.com'
17
+ s.homepage = 'http://github.com/webdevwilson/ruby-zune'
22
18
  # s.executables = ['your_executable_here']
23
19
  s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
24
20
  s.require_path = "lib"
data/lib/zune.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'net/http'
1
2
  require 'xml/mapping'
2
3
 
3
4
  module Zune
@@ -26,18 +27,32 @@ module Zune
26
27
  class Album; end;
27
28
  class Artist; end;
28
29
  class Track; end;
29
-
30
+
31
+ ZUNE_URL = 'http://social.zune.net/zcard/usercardservice.ashx?zunetag='
32
+
30
33
  class ZuneCard
31
34
 
35
+ def self.for(zune_tag)
36
+
37
+ # get text
38
+ url = URI.parse("#{ZUNE_URL}#{zune_tag}")
39
+ req = Net::HTTP::Get.new(url.request_uri)
40
+ res = Net::HTTP.start(url.host, url.port) do |http|
41
+ http.request(req)
42
+ end
43
+ xml = REXML::Document.new(res.body)
44
+ ZuneCard.load_from_xml xml.root
45
+ end
46
+
32
47
  include XML::Mapping
33
48
 
34
49
  # simple properties
35
50
  [:id, :label, :first_name, :status].each do |name|
36
- text_node name, "user/#{name.to_node_name}", :default_value => nil
51
+ text_node name, "user/#{name.to_node_name}"
37
52
  end
38
53
 
39
54
  [:name, :location, :bio, :total_plays, :user_id].each do |name|
40
- text_node name, "user/manifest/userData/#{name.to_node_name}", :default_value => nil
55
+ text_node name, "user/manifest/userData/#{name.to_node_name}"
41
56
  end
42
57
 
43
58
  # images
@@ -81,8 +96,8 @@ module Zune
81
96
 
82
97
  include XML::Mapping
83
98
 
84
- [ :id, :label, :release_time, :url ].each do |name|
85
- text_node name, name.to_node_name, :default_value => nil
99
+ [ :id, :label, :release_time, :url ].each do |name|
100
+ text_node name, name.to_node_name, :default_value => nil
86
101
  end
87
102
 
88
103
  [ :album_cover_large, :album_cover_small ].each do |format|
metadata CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- version: "0.1"
7
+ - 2
8
+ version: "0.2"
9
9
  platform: ruby
10
10
  authors:
11
11
  - Kerry R Wilson
@@ -30,10 +30,9 @@ files:
30
30
  - LICENSE
31
31
  - README
32
32
  - Rakefile
33
- - lib/zune/xml_dsl.rb
34
33
  - lib/zune.rb
35
34
  has_rdoc: true
36
- homepage:
35
+ homepage: http://github.com/webdevwilson/ruby-zune
37
36
  licenses: []
38
37
 
39
38
  post_install_message:
data/lib/zune/xml_dsl.rb DELETED
@@ -1,100 +0,0 @@
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