Advertisement
cpahaus

bdbclass.php

Sep 2nd, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <?php
  2.  
  3. class BDB_API {
  4. private $base_url = 'http://api.bdb.io/';
  5. private $integration;
  6. private $api_username;
  7. private $api_password;
  8.  
  9. function __construct( $api_username , $api_password , $integration ) {
  10. if( strlen( $api_username ) == 0 ) {
  11. throw new Exception('$api_username cannot be empty');
  12. } else {
  13. $this->api_username = $api_username;
  14. }
  15. if( strlen( $api_password ) == 0 ) {
  16. throw new Exception('$api_password cannot be empty');
  17. } else {
  18. $this->api_password = $api_password;
  19. }
  20. if( strlen( $integration ) == 0 ) {
  21. throw new Exception('$integration cannot be empty');
  22. } else {
  23. $this->integration = $integration;
  24. }
  25. }
  26.  
  27. function run( $query = array() ) {
  28. $query = (array)$query;
  29. $query['integration'] = $this->integration;
  30. $query['api_username'] = $this->api_username;
  31. $query['api_password'] = $this->api_password;
  32. $ch = curl_init();
  33. $ch_options = array(
  34. CURLOPT_URL => $this->base_url,
  35. CURLOPT_POST => TRUE,
  36. CURLOPT_POSTFIELDS => http_build_query( $query ),
  37. CURLOPT_FOLLOWLOCATION => TRUE,
  38. CURLOPT_SSL_VERIFYHOST => FALSE,
  39. CURLOPT_RETURNTRANSFER => TRUE,
  40. );
  41. curl_setopt_array($ch, $ch_options);
  42. $results = curl_exec($ch);
  43. curl_close($ch);
  44. return $results;
  45.  
  46. }
  47. }
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement