Class: StatsCollect::Locations::FacebookArtist
- Inherits:
-
Object
- Object
- StatsCollect::Locations::FacebookArtist
- Defined in:
- lib/StatsCollect/Locations/FacebookArtist.rb
Instance Method Summary collapse
-
#execute(oStatsProxy, iConf, iLstObjects, iLstCategories) ⇒ Object
Execute the plugin.
-
#getArtistProfile(oStatsProxy, iMechanizeAgent, iConf) ⇒ Object
Get the artist profile statistics.
Instance Method Details
#execute(oStatsProxy, iConf, iLstObjects, iLstCategories) ⇒ Object
Execute the plugin. This method has to add the stats and errors to the proxy. It can filter only objects and categories given. It has access to its configuration.
- Parameters
-
oStatsProxy (StatsProxy): The stats proxy to be used to populate stats
-
iConf (map<Symbol,Object>): The configuration associated to this plugin
-
iLstObjects (list<String>): List of objects to filter (can be empty for all)
-
iLstCategories (list<String>): List of categories to filter (can be empty for all)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/StatsCollect/Locations/FacebookArtist.rb', line 22 def execute(oStatsProxy, iConf, iLstObjects, iLstCategories) require 'mechanize' lMechanizeAgent = Mechanize.new # Set a specific user agent, as Facebook will treat our agent as a mobile one lMechanizeAgent.user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13' lLoginForm = lMechanizeAgent.get('http://www.facebook.com').forms[0] lLoginForm.email = iConf[:LoginEMail] lLoginForm.pass = iConf[:LoginPassword] # Submit to get to the home page lMechanizeAgent.submit(lLoginForm, lLoginForm..first) if ((oStatsProxy.is_object_included?('Global')) and (oStatsProxy.is_category_included?('Likes'))) getArtistProfile(oStatsProxy, lMechanizeAgent, iConf) end end |
#getArtistProfile(oStatsProxy, iMechanizeAgent, iConf) ⇒ Object
Get the artist profile statistics
- Parameters
-
oStatsProxy (StatsProxy): The stats proxy to be used to populate stats
-
iMechanizeAgent (Mechanize): The agent reading pages
-
iConf (map<Symbol,Object>): The conf
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/StatsCollect/Locations/FacebookArtist.rb', line 44 def getArtistProfile(oStatsProxy, iMechanizeAgent, iConf) lProfilePage = iMechanizeAgent.get("http://www.facebook.com/pages/#{iConf[:PageID]}") lNbrLikes = nil lProfilePage.root.css('script').each do |iScriptNode| lMatch = iScriptNode.content.match(/>\\u003cspan class=\\"uiNumberGiant fsxxl fwb\\">(\d*)\\u003c\\\/span>/) if (lMatch != nil) lNbrLikes = Integer(lMatch[1]) break end end if (lNbrLikes == nil) log_err "Unable to get number of likes: #{lProfilePage.root}" else oStatsProxy.add_stat('Global', 'Likes', lNbrLikes) end end |