pandora 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .rvmrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ coverage/*
9
+ doc/*
10
+ log/*
11
+ pkg/*
@@ -0,0 +1,6 @@
1
+ --no-private
2
+ --protected
3
+ --tag format:"Supported formats"
4
+ --tag authenticated:"Requires Authentication"
5
+ --tag rate_limited:"Rate Limited"
6
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pandora.gemspec
4
+ gemspec
@@ -0,0 +1,45 @@
1
+ The Pandora Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the Pandora public user feeds
4
+
5
+
6
+ Installation
7
+ ------------
8
+ gem install pandora
9
+
10
+ Documentation
11
+ -------------
12
+ [http://rdoc.info/gems/pandora](http://rdoc.info/gems/pandora)
13
+
14
+ Usage
15
+ -----
16
+ This gem only works for public users. All users who did not set 'make my listening activity private'
17
+
18
+ Usage Examples
19
+ --------------
20
+ require "rubygems"
21
+ require "pandora"
22
+
23
+ # Initialize a new User
24
+ user = Pandora::User.new("joe")
25
+
26
+ # Get a user's bookmarked songs
27
+ songs = user.bookmarked_songs # iterate over the songs array for each song
28
+
29
+ # Get a user's bookmarked artits
30
+ artists = user.bookmarked_artists # iterate over the artists array for each artist
31
+
32
+ # Get a user's stations
33
+ stations = user.stations # iterate over the stations array for each station
34
+
35
+ # Get a user's station(now playing)
36
+ station = user.now_playing
37
+
38
+ # Get a user's recent activity
39
+ items = user.recent_activity
40
+
41
+ TODO
42
+ ----
43
+ * TESTS!!!
44
+
45
+
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ namespace :doc do
5
+ require 'yard'
6
+ YARD::Rake::YardocTask.new do |task|
7
+ task.files = [ 'lib/**/*.rb']
8
+ task.options = [
9
+ '--protected',
10
+ '--output-dir', 'doc/yard',
11
+ '--tag', 'format:Supported formats',
12
+ '--tag', 'authenticated:Requires Authentication',
13
+ '--tag', 'rate_limited:Rate Limited',
14
+ '--markup', 'markdown',
15
+ ]
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ require 'pandora/request'
5
+ require 'pandora/user'
@@ -0,0 +1,20 @@
1
+ # = Pandora
2
+ # Defines all the methods related to getting data from Pandora.
3
+ #
4
+ module Pandora
5
+ # The Request starts here with parsing the method call from 'user' and Nokogiri processing
6
+ # the XML file.
7
+ #
8
+ module Request
9
+ # The link to the Pandora XML files used throughout
10
+ BASE_FEED = "http://feeds.pandora.com/feeds/people/"
11
+
12
+ # The 'user' can only be a public user on pandora, who hasn't set listening activity to private.
13
+ # The method comes from user requests.
14
+ # [String, String]
15
+ #
16
+ def request(user, method)
17
+ doc = Nokogiri::XML(open("#{BASE_FEED}#{user}/#{method}.xml"))
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,177 @@
1
+ module Pandora
2
+ # User class to get data for a particular user.
3
+ # == Initiating User
4
+ # user = Pandora::User.new("username")
5
+ # this 'user' defined will be used in examples to invoke methods below.
6
+ # After the methods are invoked the results can be iterated over for each song, artist, staiton, item.
7
+ #
8
+ class User
9
+
10
+ include Pandora::Request # Include the Request module to invoke Nokogiri.
11
+
12
+ attr_accessor :user
13
+
14
+ # Create a new user and make sure no whitespace, since it will be parsed as url in the request.
15
+ def initialize(user)
16
+ @user = user.strip
17
+ end
18
+
19
+ # == Returns the Bookmarked Songs
20
+ #
21
+ # bookmarked_songs = user.bookmarked_songs
22
+ #
23
+ # will return the parameters below:
24
+ # === Parameters:
25
+ # title:: Name of the song
26
+ # link:: Link to the song
27
+ # description:: Description of the song and the artist
28
+ # date:: Date the song was bookmarked
29
+ # track:: Song name
30
+ # artist:: Artist name
31
+ # album:: Album name
32
+ # artwork:: Artwork of the album
33
+ # station:: Station link to the song
34
+ #
35
+ def bookmarked_songs
36
+ doc = request(@user, "favorites")
37
+ songs = []
38
+ doc.xpath('//rss/channel/item').each do |node|
39
+ songs << { :title => node.xpath('title').text,
40
+ :link => node.xpath('link').text,
41
+ :description => node.xpath('description').text,
42
+ :date => node.xpath('pubDate').text,
43
+ :track => node.xpath('mm:Track/dc:title').text,
44
+ :artist => node.xpath('mm:Artist/dc:title').text,
45
+ :album => node.xpath('mm:Album/dc:title').text,
46
+ :artwork => node.xpath('pandora:albumArtUrl').text,
47
+ :station => node.xpath('pandora:stationLink').text }
48
+ end
49
+ songs
50
+ end
51
+
52
+ # == Returns the Bookmarked Artists
53
+ #
54
+ # bookmarked_artists = user.bookmarked_artists
55
+ #
56
+ # will return the parameters below:
57
+ # === Parameters:
58
+ # title:: Name of the artist
59
+ # link:: Link to the artist
60
+ # description:: Description of the artist
61
+ # date:: Date the artist was bookmarked
62
+ # station:: Station link to the station
63
+ #
64
+ def bookmarked_artists
65
+ doc = request(@user, "favoriteartists")
66
+ artists = []
67
+ doc.xpath('//rss/channel/item').each do |node|
68
+ artists << { :title => node.xpath('title').text,
69
+ :link => node.xpath('link').text,
70
+ :description => node.xpath('description').text,
71
+ :date => node.xpath('pubDate').text,
72
+ :artist => node.xpath('mm:Artist/dc:title').text,
73
+ :station => node.xpath('pandora:stationLink').text }
74
+ end
75
+ artists
76
+ end
77
+
78
+ # == Returns the Stations created
79
+ #
80
+ # stations = user.stations
81
+ #
82
+ # will return the parameters below:
83
+ # === Parameters:
84
+ # title:: Title of the station
85
+ # link:: Link to the station
86
+ # description:: Description of the station
87
+ # date:: Date the station was created
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
93
+ #
94
+ def stations
95
+ doc = request(@user, "stations")
96
+ stations = []
97
+ doc.xpath('//rss/channel/item').each do |node|
98
+ stations << { :title => node.xpath('title').text,
99
+ :link => node.xpath('link').text,
100
+ :description => node.xpath('description').text,
101
+ :date => node.xpath('pubDate').text,
102
+ :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text,
103
+ :songSeed_song => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text,
104
+ :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text,
105
+ :composerSeed => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text,
106
+ :artistSeed => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist') }
107
+ end
108
+ stations
109
+ end
110
+
111
+ # == Returns the Station Now Playing
112
+ #
113
+ # now_playing = user.now_playing
114
+ #
115
+ # will return the parameters below:
116
+ # === Parameters:
117
+ # title:: Title of the station
118
+ # link:: Link to the station
119
+ # description:: Description of the station
120
+ # date:: Date the station was last played
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
126
+ #
127
+ def now_playing
128
+ doc = request(@user, "nowplaying")
129
+ station = []
130
+ doc.xpath('//rss/channel/item').each do |node|
131
+ station << { :title => node.xpath('title').text,
132
+ :link => node.xpath('link').text,
133
+ :description => node.xpath('description').text,
134
+ :date => node.xpath('pubDate').text,
135
+ :artwork => node.xpath('pandora:stationAlbumArtImageUrl').text,
136
+ :songSeed_song => node.xpath('pandora:seeds/pandora:songSeed/pandora:song').text,
137
+ :songSeed_artist => node.xpath('pandora:seeds/pandora:songSeed/pandora:artist').text,
138
+ :composerSeed => node.xpath('pandora:seeds/pandora:composerSeed/pandora:composer').text,
139
+ :artistSeed => node.xpath('pandora:seeds/pandora:artistSeed/pandora:artist') }
140
+ end
141
+ station
142
+ end
143
+
144
+ # == Returns the Recent Activity
145
+ #
146
+ # recent_activity = user.recent_activity
147
+ #
148
+ # will return the parameters below:
149
+ # === Parameters:
150
+ # title:: Title of the item(song or artist)
151
+ # link:: Link to the item(song or artist)
152
+ # description:: Description of the song and the artist
153
+ # date:: Date the song was modified
154
+ # track:: Song name
155
+ # artist:: Artist name
156
+ # album:: Album name
157
+ # artwork:: Artwork of the item
158
+ # station:: Station link to the item
159
+ #
160
+ def recent_activity
161
+ doc = request(@user, "recentactivity")
162
+ items = []
163
+ doc.xpath('//rss/channel/item').each do |node|
164
+ items << { :title => node.xpath('title').text,
165
+ :link => node.xpath('link').text,
166
+ :description => node.xpath('description').text,
167
+ :date => node.xpath('pubDate').text,
168
+ :track => node.xpath('mm:Track/dc:title').text,
169
+ :artist => node.xpath('mm:Artist/dc:title').text,
170
+ :album => node.xpath('mm:Album/dc:title').text,
171
+ :artwork => node.xpath('pandora:albumArtUrl').text,
172
+ :station => node.xpath('pandora:stationLink').text }
173
+ end
174
+ items
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,3 @@
1
+ module Pandora
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pandora/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pandora"
7
+ s.version = Pandora::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Anil"]
10
+ s.homepage = "http://github.com/anilv/pandora"
11
+ s.summary = %q{Get Music data from Pandora}
12
+ s.description = %q{With a given username get user's favorite artists, songs. Also recent acitvity,
13
+ current station and list of the user created stations.}
14
+
15
+ s.add_runtime_dependency 'nokogiri','~> 1.4'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pandora
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Anil
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-27 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: nokogiri
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "1.4"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: |-
28
+ With a given username get user's favorite artists, songs. Also recent acitvity,
29
+ current station and list of the user created stations.
30
+ email:
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files: []
36
+
37
+ files:
38
+ - .gitignore
39
+ - .yardopts
40
+ - Gemfile
41
+ - README.md
42
+ - Rakefile
43
+ - lib/pandora.rb
44
+ - lib/pandora/request.rb
45
+ - lib/pandora/user.rb
46
+ - lib/pandora/version.rb
47
+ - pandora.gemspec
48
+ has_rdoc: true
49
+ homepage: http://github.com/anilv/pandora
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.6.2
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Get Music data from Pandora
76
+ test_files: []
77
+