Class: Pandata::Scraper
- Inherits:
-
Object
- Object
- Pandata::Scraper
- Defined in:
- lib/pandata/scraper.rb
Overview
Downloads a user’s Pandora.com data. A user’s profile must be public for Pandata to download its data.
Instance Attribute Summary collapse
-
#download_cb ⇒ Object
A Proc that gets called after some data has been downloaded.
-
#webname ⇒ Object
readonly
What Pandora uses to identify a user and it remains constant even if the user ties a new email address to their Pandora account.
Class Method Summary collapse
-
.get(user_id) ⇒ Scraper, Array
If possible, get a Scraper instance for the user_id otherwise return an array of similar webnames.
Instance Method Summary collapse
-
#bookmarks(bookmark_type = :all) ⇒ Object
Get the user’s bookmarked data.
-
#followers ⇒ Array
Get the user’s public followers.
-
#following ⇒ Array
Get the public users being followed by the user.
-
#initialize(webname) ⇒ Scraper
constructor
A new instance of Scraper.
-
#likes(like_type = :all) ⇒ Object
Get the user’s liked data.
-
#playing_station ⇒ String
Get the user’s playing station.
-
#recent_activity ⇒ Array
Get the user’s recent activity.
-
#stations ⇒ Array
Get the user’s stations.
Constructor Details
Instance Attribute Details
#download_cb ⇒ Object
A Proc that gets called after some data has been downloaded.
16 17 18 |
# File 'lib/pandata/scraper.rb', line 16 def download_cb @download_cb end |
#webname ⇒ Object (readonly)
What Pandora uses to identify a user and it remains constant even if the user ties a new email address to their Pandora account.
13 14 15 |
# File 'lib/pandata/scraper.rb', line 13 def webname @webname end |
Class Method Details
.get(user_id) ⇒ Scraper, Array
If possible, get a Scraper instance for the user_id otherwise return an array of similar webnames.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pandata/scraper.rb', line 23 def self.get(user_id) search_url = DATA_FEED_URLS[:user_search] % { searchString: user_id } html = Downloader.read_page(search_url) webnames = Parser.new.get_webnames_from_search(html) if webnames.include?(user_id) new(user_id) # If user_id looks like an email and still gets a result. elsif webnames.size == 1 && /.*@.*\..*/ =~ user_id new(webnames.first) else webnames end end |
Instance Method Details
#bookmarks(bookmark_type = :all) ⇒ Object
Get the user’s bookmarked data.
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pandata/scraper.rb', line 67 def bookmarks(bookmark_type = :all) case bookmark_type when :tracks scrape_for(:bookmarked_tracks, :get_bookmarked_tracks) when :artists scrape_for(:bookmarked_artists, :get_bookmarked_artists) when :all { artists: bookmarks(:artists), tracks: bookmarks(:tracks) } end end |
#followers ⇒ Array
Get the user’s public followers.
115 116 117 |
# File 'lib/pandata/scraper.rb', line 115 def followers scrape_for(:followers, :get_followers) end |
#following ⇒ Array
Get the public users being followed by the user.
109 110 111 |
# File 'lib/pandata/scraper.rb', line 109 def following scrape_for(:following, :get_following) end |
#likes(like_type = :all) ⇒ Object
Get the user’s liked data. (The results from giving a ‘thumbs up.’)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pandata/scraper.rb', line 86 def likes(like_type = :all) case like_type when :tracks scrape_for(:liked_tracks, :get_liked_tracks) when :artists scrape_for(:liked_artists, :get_liked_artists) when :stations scrape_for(:liked_stations, :get_liked_stations) when :albums scrape_for(:liked_albums, :get_liked_albums) when :all { artists: likes(:artists), albums: likes(:albums), stations: likes(:stations), tracks: likes(:tracks) } end end |
#playing_station ⇒ String
Get the user’s playing station.
52 53 54 |
# File 'lib/pandata/scraper.rb', line 52 def scrape_for(:playing_station, :get_playing_station).first end |
#recent_activity ⇒ Array
Get the user’s recent activity.
46 47 48 |
# File 'lib/pandata/scraper.rb', line 46 def recent_activity scrape_for(:recent_activity, :get_recent_activity) end |
#stations ⇒ Array
Get the user’s stations.
58 59 60 |
# File 'lib/pandata/scraper.rb', line 58 def stations scrape_for(:stations, :get_stations) end |