pandora 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,24 +86,24 @@ module Pandora
86
86
  # description:: Description of the station
87
87
  # date:: Date the station was created
88
88
  # artwork:: Artwork of the station
89
- # songSeed_song:: Name of song used to create station
90
- # songSeed_artist:: Name of the artist for the song used to create the station
91
- # composerSeed:: Name of the composer used to create the station
92
- # artistSeed:: Name of the artist used to create the station
89
+ # songSeed:: Array of hashes {:song => "..", :artist => ".."} representing songs used to create the station
90
+ # composerSeed:: Array of names of the composers used to create the station
91
+ # artistSeed:: Array of names of the artists used to create the station
93
92
  #
94
93
  def stations
95
94
  doc = request(@user, "stations")
96
95
  stations = []
97
96
  doc.xpath('//rss/channel/item').each do |node|
98
- stations << { :title => node.xpath('title').text.strip,
99
- :link => node.xpath('link').text.strip,
100
- :description => node.xpath('description').text.strip,
101
- :date => node.xpath('pubDate').text.strip,
102
- :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip,
103
- :songSeed_song => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text.strip,
104
- :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text.strip,
105
- :composerSeed => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text.strip,
106
- :artistSeed => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist').text.strip}
97
+ seeds = parse_seeds(node)
98
+
99
+ stations << { :title => node.xpath('title').text.strip,
100
+ :link => node.xpath('link').text.strip,
101
+ :description => node.xpath('description').text.strip,
102
+ :date => node.xpath('pubDate').text.strip,
103
+ :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip,
104
+ :songSeed => seeds[:song],
105
+ :composerSeed => seeds[:composer],
106
+ :artistSeed => seeds[:artist]}
107
107
  end
108
108
  stations
109
109
  end
@@ -119,24 +119,24 @@ module Pandora
119
119
  # description:: Description of the station
120
120
  # date:: Date the station was last played
121
121
  # artwork:: Artwork of the station
122
- # songSeed_song:: Name of song used to create station
123
- # songSeed_artist:: Name of the artist for the song used to create the station
124
- # composerSeed:: Name of the composer used to create the station
125
- # artistSeed:: Name of the artist used to create the station
122
+ # songSeed:: Array of hashes {:song => "..", :artist => ".."} representing songs used to create the station
123
+ # composerSeed:: Array of names of the composers used to create the station
124
+ # artistSeed:: Array of names of the artists used to create the station
126
125
  #
127
126
  def now_playing
128
127
  doc = request(@user, "nowplaying")
129
128
  station = []
130
129
  doc.xpath('//rss/channel/item').each do |node|
131
- station << { :title => node.xpath('title').text.strip,
132
- :link => node.xpath('link').text.strip,
133
- :description => node.xpath('description').text.strip,
134
- :date => node.xpath('pubDate').text.strip,
135
- :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip,
136
- :songSeed_song => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text.strip,
137
- :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text.strip,
138
- :composerSeed => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text.strip,
139
- :artistSeed => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist').text.strip }
130
+ seeds = parse_seeds(node)
131
+
132
+ station << { :title => node.xpath('title').text.strip,
133
+ :link => node.xpath('link').text.strip,
134
+ :description => node.xpath('description').text.strip,
135
+ :date => node.xpath('pubDate').text.strip,
136
+ :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text.strip,
137
+ :songSeed => seeds[:song],
138
+ :composerSeed => seeds[:composer],
139
+ :artistSeed => seeds[:artist]}
140
140
  end
141
141
  station
142
142
  end
@@ -173,5 +173,37 @@ module Pandora
173
173
  end
174
174
  items
175
175
  end
176
+
177
+ private
178
+ def parse_seeds(node)
179
+ seeds = {
180
+ :song => [],
181
+ :composer => [],
182
+ :artist => []
183
+ }
184
+
185
+ if node.is_a? Nokogiri::XML::Node
186
+ node.xpath('pandora:seeds/pandora:songSeed').each do |s|
187
+
188
+ song = s.xpath("pandora:song").text.strip
189
+ artist = s.xpath("pandora:artist").text.strip
190
+
191
+ seeds[:song] << {
192
+ :song => song,
193
+ :artist => artist
194
+ }
195
+ end
196
+
197
+ node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').each do |c|
198
+ seeds[:composer] << c.text.strip
199
+ end
200
+
201
+ node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist').each do |a|
202
+ seeds[:artist] << a.text.strip
203
+ end
204
+ end
205
+
206
+ seeds
207
+ end
176
208
  end
177
209
  end
@@ -1,3 +1,3 @@
1
1
  module Pandora
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{A Ruby wrapper for the Pandora public user feeds}
13
13
 
14
14
  s.add_runtime_dependency 'nokogiri','~> 1.4'
15
+ s.add_development_dependency 'rake'
16
+ s.add_development_dependency 'yard'
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -1,37 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pandora
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
4
5
  prerelease:
5
- version: 0.1.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Anil
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-02 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: nokogiri
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70178239905760 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "1.4"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
24
22
  type: :runtime
25
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: *70178239905760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70178239905340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70178239905340
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70178239904740 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70178239904740
26
47
  description: A Ruby wrapper for the Pandora public user feeds
27
48
  email:
28
49
  executables: []
29
-
30
50
  extensions: []
31
-
32
51
  extra_rdoc_files: []
33
-
34
- files:
52
+ files:
35
53
  - .gitignore
36
54
  - .yardopts
37
55
  - Gemfile
@@ -44,30 +62,33 @@ files:
44
62
  - pandora.gemspec
45
63
  homepage: http://github.com/anilv/pandora
46
64
  licenses: []
47
-
48
65
  post_install_message:
49
66
  rdoc_options: []
50
-
51
- require_paths:
67
+ require_paths:
52
68
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
69
+ required_ruby_version: !ruby/object:Gem::Requirement
54
70
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
- required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -1909941597842625503
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
79
  none: false
61
- requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: "0"
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -1909941597842625503
65
87
  requirements: []
66
-
67
88
  rubyforge_project:
68
- rubygems_version: 1.8.5
89
+ rubygems_version: 1.8.10
69
90
  signing_key:
70
91
  specification_version: 3
71
92
  summary: Get Music data from Pandora
72
93
  test_files: []
73
-
94
+ has_rdoc: