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
-
#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.
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
#followers ⇒ Array
Get the user’s public followers.
80 81 82 |
# File 'lib/pandata/scraper.rb', line 80 def followers scrape_for(:followers, :get_followers) end |
#following ⇒ Array
Get the public users being followed by the user.
74 75 76 |
# File 'lib/pandata/scraper.rb', line 74 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.’)
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pandata/scraper.rb', line 51 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 |