BillogramApiModelsBillogramClass

Represents the collection of billogram objects on the Billogram service.

Defined (1)

The class is defined in the following location(s).

/Billogram/Api/Models/BillogramClass.php  
  1. class BillogramClass extends SimpleClass 
  2. public $objectClass = 'Billogram\Api\Objects\BillogramObject'; 
  3.  
  4. /** 
  5. * Constructor sets the base url and significant id field for the resource. 
  6. */ 
  7. public function __construct($api) 
  8. $this->api = $api; 
  9. $this->urlName = 'billogram'; 
  10. $this->objectIdField = 'id'; 
  11.  
  12. /** 
  13. * Makes a POST request to the API and creates a new object. 
  14. * @param $data 
  15. * @return \Billogram\Api\Objects\BillogramObject 
  16. */ 
  17. public function create($data) 
  18. return parent::create($data); 
  19.  
  20. /** 
  21. * Creates and sends a billogram using the $data and $method supplied. 
  22. * @param $data 
  23. * @param $method 
  24. * @throws \Billogram\Api\Exceptions\InvalidFieldValueError 
  25. * @return \Billogram\Api\Objects\BillogramObject 
  26. */ 
  27. public function createAndSend($data, $method) 
  28. if (!in_array($method, array('Email', 'Letter', 'Email+Letter'))) 
  29. throw new InvalidFieldValueError("Invalid method, should be 'Email', 'Letter' or 'Email+Letter'"); 
  30. $billogram = $this->create($data); 
  31. try { 
  32. $billogram->send($method); 
  33. } catch (InvalidFieldValueError $e) { 
  34. $billogram->delete(); 
  35. throw $e; 
  36.  
  37. return $billogram; 
  38.  
  39. /** 
  40. * Creates and sells a billogram. 
  41. * @param $data 
  42. * @param $method 
  43. * @return \Billogram\Api\Objects\BillogramObject 
  44. */ 
  45. public function createAndSell($data, $method) 
  46. $data['_event'] = 'sell'; 
  47. $billogram = $this->create($data); 
  48.  
  49. return $billogram;