Share
Embed
Bitestats: From API to PDF
Future of Web Apps presentation about the architecture of bitestats and how all the various pieces fit together to make a great PHP application
Lorna Mitchell
October 16, 2012
Transcript
51 slides
-
About BiteStats About BiteStats “A one-page report summarising your web
stats, which arrives in your inbox monthly” -
Zend Framework Website Zend Framework Website Outward facing site, written
in Zend Framework 1 http://framework.zend.com Users can: register pay get one-off reports enable/disable reporting for each site -
Wordpress Wordpress Simple site for managing content and has feedback
forms http://wordpress.com Zend_Layout and some @miss_jwo magic to make the two systems match -
Google OAuth (v1) Google OAuth (v1) Allow users to authorise
BiteStats to have access to their data 1) Get a Request Token <?php // Get Request Token $oauth = new new OAuth($config['consumer_key'], $config['consumer_secret'] ); $oauth->setAuthType(OAUTH_AUTH_TYPE_URI); $request_options = array array("scope" => $config['scope'], "oauth_callback" => $config['callbackurl']); $url = $config['requesturl'] . '?' . http_build_query($request_options); $token_req = $oauth->getRequestToken($url); -
Google OAuth (v1) Google OAuth (v1) Allow users to authorise
BiteStats to have access to their data 2) Send the user off to google to authenticate <?php $oauth_options = array array( "oauth_token" => $token_req['oauth_token'], "oauth_token_secret" => $token_req['oauth_token_secret'] ); $url = $config['oauthurl'] . '?' . http_build_query($oauth_options); $this->_redirect($url); -
Google OAuth (v1) Google OAuth (v1) Allow users to authorise
BiteStats to have access to their data 3) User returns, and we can get the access token <?php $oauth = new new OAuth($config['consumer_key'], $config['consumer_secret'] ); $oauth->setAuthType(OAUTH_AUTH_TYPE_URI); $oauth->setToken($config['request_token'], $config['request_token_secret']); $access = $oauth->getAccessToken($config['access_uri'], null null, $config['verification']); -
Google Analytics Google Analytics Which profiles and sites does a
user have access to? <?php $oauth = new new OAuth($consumer_key, $consumer_secret ); $oauth->setToken($access_token, $access_token_secret); $result = $oauth->fetch( 'https://www.google.com/analytics/feeds/datasources/ga/accounts/' . $account_id . '/webproperties/~all/profiles'); They can pick which ones they want every month, or request one NOW -
Gearman Gearman Gearman is a job queue. http://gearman.org The web
servers add jobs to the queue Web server then gets on with whatever it was doing Worker processes fetch jobs from the queue, and process them Gearman oversees each job being succesfully completed -
Adding Jobs to Gearman Adding Jobs to Gearman <?php $job_data
= array array(); $job_data['user_id'] = $auth->user_id; $job_data['date_requested'] = $data['date_requested']; $job_data['google_profile'] = $auth->gp; $gearman_client = new new Application_Model_Gearman_Client($options); $gearman_client->doBackground('basicReport', json_encode($job_data)); -
Paypal Integration Paypal Integration Set up subscriptions and button via
PayPal website IPN: Instant Payment Notification PayPal POSTs requests to us when events occur -
Handling Paypal IPN Calls Handling Paypal IPN Calls We acknowledge
Paypal's call, otherwise they keep sending it! Relate the transactions back to the user and keep state -
Bootstrap ZF from the Command Bootstrap ZF from the Command
Line Line Used by worker scripts and cron jobs Separate bootstrap process and config, shared MVC structure -
Workers Workers Command line scripts, monitored by supervisord http://supervisord.org Check
for new jobs, sleep, check ... -
Worker Account Checks Worker Account Checks Look at incoming data,
which report, which date range, which user? Check that Google OAuth token is valid Check that the Paypal subscription is current -
Zend_Pdf Zend_Pdf A Zend Framework module with helper functions for
PDF Still need to do some maths yourself! The origin (0,0) is in the bottom left of the page ... public function drawLine($x1, $y1, $x2, $y2); public function drawText($text, $x, $y, $charEncoding = ''); public function drawImage(Zend_Pdf_Resource_Image $image, $x1, $y1, $x2, $y2); -
Google Analytics Data Google Analytics Data Fetch visits by day
for two date ranges: -
Google Image Charts Google Image Charts Build a URL, use
as src attribute for img tag. http://chart.apis.google.com/chart?chs=800x256&cht=lc&chco=524066,46464666& chd=t:_,_,841,805,794,391,383,834,916,848,886,744,406,385,900,1553,916,1037,1418, 510,470,1055,1038,972,966,828,422,366,922,1015,959,361,0|979,839,760,845,778,370, 399,944,1244,1041,917,782,415,364,825,958,1342,1892,998,542,637,1203,994,923,1022, 787,413,402,1003,910,_,_,_&chdl=Aug|Jul&chds=0,1892&chxt=x,x,y&chxl=0:|M|T|W|T|F| S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|1:||Day+Of+Week|&chem=y; s=bubble_text_small;d=bb,Max:+1553,FFFFFF,524066;ds=0;dp=15|y;s=bubble_text_small; d=bbtr,Min:+0,FFFFFF,524066;ds=0;dp=32&chma=0,0,60,60&chxr=2,0,1892&chdls=000000, 14&chtt=Visitors+per+Day&chts=000000,14 -
Google Image Charts Google Image Charts Build a URL, use
as src attribute for img tag. http://chart.apis.google.com/chart?chs=800x256&cht=lc&chco=524066,46464666&chd=t:_, _,841,805,794,391,383,834,916,848,886,744,406,385,900,1553,916,1037,1418, 510,470,1055,1038,972,966,828,422,366,922,1015,959,361,0|979,839,760,845, 778,370,399,944,1244,1041,917,782,415,364,825,958,1342,1892,998,542,637, 1203,994,923,1022,787,413,402,1003,910,_,_,_&chdl=Aug|Jul&chds=0,1892&chxt=x, x,ychxl=0:|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|1:|| Day+Of+Week|&chem=y;s=bubble_text_small;d=bb,Max:+1553,FFFFFF,524066;ds=0;dp=15|y; s=bubble_text_small;d=bbtr,Min:+0,FFFFFF,524066;ds=0;dp=32&chma=0,0,60,60&chxr=2, 0,1892&chdls=000000,14&chtt=Visitors+per+Day&chts=000000,14 -
Google Image Charts Google Image Charts Build a URL, use
as src attribute for img tag. http://chart.apis.google.com/chart?chs=800x256&cht=lc&chco=524066,46464666&chd=t: _,_,841,805,794,391,383,834,916,848,886,744,406,385,900,1553,916,1037,1418,510,470, 1055,1038,972,966,828,422,366,922,1015,959,361,0|979,839,760,845,778,370,399,944, 1244,1041,917,782,415,364,825,958,1342,1892,998,542,637,1203,994,923,1022,787,413, 402,1003,910,_,_,_&chdl=Aug|Jul&chds=0,1892&chxt=x,x,y&chxl=0:|M|T|W|T|F|S| S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|1:||Day+Of+Week|& chem=y;s=bubble_text_small;d=bb,Max:+1553,FFFFFF,524066;ds=0;dp=15|y; s=bubble_text_small;d=bbtr,Min:+0,FFFFFF,524066;ds=0;dp=32&chma=0,0,60,60& chxr=2,0,1892&chdls=000000,14&chtt=Visitors+per+Day&chts=000000,14 -
Google Image Charts Google Image Charts Build a URL, use
as src attribute for img tag. http://chart.apis.google.com/chart?chs=800x256&cht=lc&chco=524066,46464666&chd=t: _,_,841,805,794,391,383,834,916,848,886,744,406,385,900,1553,916,1037,1418,510,470, 1055,1038,972,966,828,422,366,922,1015,959,361,0|979,839,760,845,778,370,399,944, 1244,1041,917,782,415,364,825,958,1342,1892,998,542,637,1203,994,923,1022,787,413, 402,1003,910,_,_,_&chdl=Aug|Jul&chds=0,1892&chxt=x,x,y&chxl=0:|M|T|W|T|F|S|S|M|T| W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|1:||Day+Of+Week|&chem=y; s=bubble_text_small;d=bb,Max:+1553,FFFFFF,524066;ds=0;dp=15|y; s=bubble_text_small;d=bbtr,Min:+0,FFFFFF,524066;ds=0;dp=32&chma=0,0,60,60& chxr=2,0,1892&chdls=000000,14&chtt=Visitors+per+Day&chts=000000,14 -
Google Image Charts Google Image Charts Build a URL, use
as src attribute for img tag. http://chart.apis.google.com/chart?chs=800x256&cht=lc&chco=524066,46464666&chd=t: _,_,841,805,794,391,383,834,916,848,886,744,406,385,900,1553,916,1037,1418,510,470, 1055,1038,972,966,828,422,366,922,1015,959,361,0|979,839,760,845,778,370,399,944, 1244,1041,917,782,415,364,825,958,1342,1892,998,542,637,1203,994,923,1022,787,413, 402,1003,910,_,_,_&chdl=Aug|Jul&chds=0,1892&chxt=x,x,y&chxl=0:|M|T|W|T|F|S|S|M|T| W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|S|S|M|T|W|T|F|1:||Day+Of+Week|&chem=y; s=bubble_text_small;d=bb,Max:+1553,FFFFFF,524066;ds=0;dp=15|y;s=bubble_text_small; d=bbtr,Min:+0,FFFFFF,524066;ds=0;dp=32&chma=0,0,60,60&chxr=2,0,1892& chdls=000000,14&chtt=Visitors+per+Day&chts=000000,14 -
Google Analytics Data Google Analytics Data Fetch visits by week
for two date ranges: -
Other Tools Other Tools Mercurial on BitBucket http://bitbucket.org Phing for
deployment http://phing.info -
Mercurial and BitBucket Mercurial and BitBucket A DVCS aimed at
normal people - intentionally humane and intuitive BitBucket offers: Git and Hg Unlimited private repositories Up to 5 collaborators on free accounts -
Phing Phing PHP-based deployment tool My build.xml follows these steps:
create incrementally-numbered tag export code and tar it up transfer it to live, and untar it handle db patches and things point the docroot symlink at the new files restart the gearman workers ... all in one command