Overview

Namespaces

  • Davek1312
    • ApiIntegrator
      • Models

Classes

  • Davek1312\ApiIntegrator\ApiIntegrator
  • Davek1312\ApiIntegrator\Models\ApiIntegratorBaseModel
  • Davek1312\ApiIntegrator\Models\ApiIntegratorRequestModel
  • Davek1312\ApiIntegrator\Models\ApiIntegratorResponseModel
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 
<?php

namespace Davek1312\ApiIntegrator\Models;

use JMS\Serializer\Annotation\Exclude;

/**
 * Model for api responses
 *
 * @author  David Kelly <davek1312@gmail.com>
 */
abstract class ApiIntegratorResponseModel extends ApiIntegratorBaseModel {

    /**
     * The API's response format: 'json' OR 'xml'
     *
     * @var string
     *
     * @Exclude()
     */
    protected $dataType;

    /**
     * ApiIntegratorResponseModel constructor.
     *
     * @param string $dataType
     */
    public function __construct($dataType) {
        $this->dataType = $dataType;
    }

    /**
     * Deserialises $data into an object of this class
     *
     * @param string $data
     *
     * @return object
     */
    public function deserialiseResponse($data) {
        return $this->deserialise($data, $this->dataType);
    }

    /**
     * Returns the error message returned by the API. This should be overridden to point the child method containing the API's error message
     *
     * @return string
     */
    public function getResponseErrorMessage() {
        return null;
    }

    /**
     * Returns the error code returned by the API. This should be overridden to point the child method containing the API's error code
     *
     * @return string
     */
    public function getResponseErrorCode() {
        return null;
    }

    /**
     * Returns true if getResponseErrorMessage() or getResponseErrorCode() is not empty
     *
     * @return boolean
     */
    public function hasResponseError() {
        return !empty($this->getError()) || !empty($this->getErrorCode());
    }

    /**
     * @return string
     */
    public function getDataType() {
        return $this->dataType;
    }

    /**
     * @param string $dataType
     */
    public function setDataType($dataType) {
        $this->dataType = $dataType;
    }
}
API documentation generated by ApiGen