Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. <?php
  2.  
  3. // See https://salsasupport.zendesk.com/entries/23514381-Definitions-for-common-terms
  4. // to find out to retrieve the API URL in $url.
  5.  
  6. $url = "https://hq-org.salsalabs.com/api";
  7. $username = "BAGCounter"; # Campaign Manager username goes here
  8. $password = "oo@LL@oo"; # Campaign Manager password goes here
  9.  
  10. // Method #1 for building post objects to send to Salsa
  11. $authfields["email"] = $username;
  12. $authfields["password"] = $password;
  13.  
  14. // Method #2 for building post objects to send to Salsa
  15. // Note: unless you have a small number of supporters, this will fail.
  16. // try removing the 'groupBy' => 'Date_Created' statement.
  17. $fields = array('object' => 'supporter_action');
  18. $fields2 = array('object' => 'donation');
  19.  
  20. // Initialize cURL connection
  21. // * See http://us3.php.net/manual/en/book.curl.php for more information
  22. // on the cURL capability in PHP.
  23. $ch = curl_init();
  24.  
  25. // Set basic connection parameters
  26. curl_setopt($ch, CURLOPT_POST, 1);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  28. curl_setopt($ch, CURLOPT_TIMEOUT, 100);
  29.  
  30. // Set parameters to maintain cookies across sessions
  31. curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  32. curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies_file');
  33. curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies_file');
  34.  
  35. //Execute connection to authenticate to Salsa
  36. //* Example:
  37. // https://sandbox.salsalabs.com/api/authenticate.sjs?email=whatever&password=whatever
  38.  
  39. curl_setopt($ch, CURLOPT_URL, "$url/authenticate.sjs");
  40. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($authfields));
  41. $auth = curl_exec($ch);
  42.  
  43. // Execute query to return data back to the User/Application
  44. // * Example:
  45. // https://sandbox.salsalabs.com/api/getCounts.sjs?object=supporter&groupBy=Date_Created
  46. //
  47. //curl_setopt($ch, CURLOPT_URL, "$url/getCounts.sjs");
  48. //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
  49. //$count = curl_exec($ch);
  50.  
  51. curl_setopt($ch, CURLOPT_URL, "$url/getCount.sjs?object=supporter_action");
  52. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
  53. $countSupporterTotal = curl_exec($ch);
  54. $responseSupporterTotal = simplexml_load_string($countSupporterTotal);
  55.  
  56. curl_setopt($ch, CURLOPT_URL, "$url/getCount.sjs?object=donation");
  57. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields2));
  58. $countDonationTotal = curl_exec($ch);
  59. $responseDonationTotal = simplexml_load_string($countDonationTotal);
  60.  
  61. //Close the connection
  62. curl_close($ch);
  63.  
  64. $bagTotal = 2023079092;
  65. $bagTotal = $bagTotal + intval($responseDonationTotal->donation->count) + intval($responseSupporterTotal->supporter_action->count);
  66.  
  67. echo number_format($bagTotal);
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement