src/Core/Communicator.php
public function add(ProcessableComponentInterface $component)
    {
        switch (get_class($component)) {
            case "IP1\RESTClient\Recipient\Contact":
                $response = $this->sendRequest("api/contacts", "POST", json_encode($component));
                return RecipientFactory::createProcessedContactFromJSON($response);

            case "IP1\RESTClient\Recipient\Group":
                $response = $this->sendRequest("api/groups", "POST", json_encode($component));
                return RecipientFactory::createProcessedGroupFromJSON($response);

            case "IP1\RESTClient\Recipient\Membership":
                $response = $this->sendRequest("api/memberships", "POST", json_encode($component));
                return RecipientFactory::createProcessedMembershipFromJSON($response);

            case "IP1\RESTClient\SMS\OutGoingSMS":
                $response = $this->sendRequest("api/sms/send", "POST", json_encode($component));
                return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response);
            case "IP1\RESTClient\Recipient\BlacklistEntry":
                $response = $this->sendRequest("api/blacklist", "POST", json_encode($component));
                $stdResponse = json_decode($response);
                $created = new \DateTime($stdResponse->Created);
                return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created);
            default:
                throw new \InvalidArgumentException("Given JsonSerializable not supported.");
        }
    }
public function add(ProcessableComponentInterface $component)
    {
        switch (get_class($component)) {
            case "IP1\RESTClient\Recipient\Contact":
                $response = $this->sendRequest("api/contacts", "POST", json_encode($component));
                return RecipientFactory::createProcessedContactFromJSON($response);

            case "IP1\RESTClient\Recipient\Group":
                $response = $this->sendRequest("api/groups", "POST", json_encode($component));
                return RecipientFactory::createProcessedGroupFromJSON($response);

            case "IP1\RESTClient\Recipient\Membership":
                $response = $this->sendRequest("api/memberships", "POST", json_encode($component));
                return RecipientFactory::createProcessedMembershipFromJSON($response);

            case "IP1\RESTClient\SMS\OutGoingSMS":
                $response = $this->sendRequest("api/sms/send", "POST", json_encode($component));
                return RecipientFactory::createProcessedOutGoingSMSFromJSONArray($response);
            case "IP1\RESTClient\Recipient\BlacklistEntry":
                $response = $this->sendRequest("api/blacklist", "POST", json_encode($component));
                $stdResponse = json_decode($response);
                $created = new \DateTime($stdResponse->Created);
                return new ProcessedBlacklistEntry($stdResponse->Phone, $stdResponse->ID, $created);
            default:
                throw new \InvalidArgumentException("Given JsonSerializable not supported.");
        }
    }
public function add ( ProcessableComponentInterface $ component ) { switch ( get_class ( $ component ) ) { case "IP1\RESTClient\Recipient\Contact" : $ response = $ this -> sendRequest ( "api/contacts" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedContactFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\Group" : $ response = $ this -> sendRequest ( "api/groups" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedGroupFromJSON ( $ response ) ; case "IP1\RESTClient\Recipient\Membership" : $ response = $ this -> sendRequest ( "api/memberships" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedMembershipFromJSON ( $ response ) ; case "IP1\RESTClient\SMS\OutGoingSMS" : $ response = $ this -> sendRequest ( "api/sms/send" , "POST" , json_encode ( $ component ) ) ; return RecipientFactory :: createProcessedOutGoingSMSFromJSONArray ( $ response ) ; case "IP1\RESTClient\Recipient\BlacklistEntry" : $ response = $ this -> sendRequest ( "api/blacklist" , "POST" , json_encode ( $ component ) ) ; $ stdResponse = json_decode ( $ response ) ; $ created = new \ DateTime ( $ stdResponse -> Created ) ; return new ProcessedBlacklistEntry ( $ stdResponse -> Phone , $ stdResponse -> ID , $ created ) ; default : throw new \ InvalidArgumentException ( "Given JsonSerializable not supported." ) ; } }
Adds the param to the API and returns the response as the corresponding object.
@param ProcessableComponentInterface $component A Contact, Group, Membership or OutGoingSMS.
@return ProcessedComponentInterface ProcessedContact, ProcessedGroup, PrcessedMembership or a ClassValidatinArray
filled with ProcessedOutGoingSMS.
@throws \InvalidArgumentException When param isn't any of the classes listed in param args.
Adds the param to the API and returns the response as the corresponding object .