public static function fromCommand(OperationCommand $command)
 {
     $response = json_decode($command->getResponse()->getBody(true), true);
     $class = get_called_class();
     // Cannot do new self() with abstract class
     return new $class($response);
 }
Exemplo n.º 2
0
 /**
  * The fromCommand method is used by Guzzle to create an instance of this class. It "injects"
  * the response data, which is then parsed to populate this and the associated models.
  *
  * @param Guzzle\Service\Command\OperationCommand
  * @return array
  */
 public static function fromCommand(\Guzzle\Service\Command\OperationCommand $command)
 {
     // Grab the results, which will be in JSON format
     //krumo($command->getResponse());
     $result = $command->getResponse()->json();
     // Start building an array, since a call to the API can include several different sites
     $websites = array();
     // Now iterate through the results
     foreach ($result as $key => $row) {
         // "Target" is a stripped-down version of the URL provided
         $url = $row['target'];
         // Create a new Website model
         $website = new Website($url);
         // The 0 axis holds information about trustworthiness
         if (isset($row[0])) {
             $website->setTrustworthiness($row[0][0], $row[0][1]);
         }
         // The 4 axis contins information pertaining to child satefy
         if (isset($row[4])) {
             $website->setChildSafety($row[4][0], $row[4][1]);
         }
         // NOTE: the axes in indexes 1 and 2 are deprecated.
         // If any categories are specified, set them
         if (isset($row['categories'])) {
             $website->setCategories($row['categories']);
         }
         // If provided, set the blacklist information; we'll discard the timestamp information
         if (isset($row['blacklists'])) {
             $website->setBlacklists(array_keys($row['blacklists']));
         }
         // Add the website
         $websites[$key] = $website;
     }
     return $websites;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     $brandAddress = self::hydrateModelProperties(new Address(), $data['agentBrand']['address']);
     $brand = self::hydrateModelProperties(new Brand(), $data['agentBrand'], array(), array('address' => $brandAddress));
     $address = self::hydrateModelProperties(new Address(), $data['address']);
     return self::hydrateModelProperties(new self(), $data, array(), array('address' => $address, 'agentBrand' => $brand));
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $items = new Collection();
     foreach ($command->getResponse()->json() as $key => $item) {
         $items[$key] = self::hydrateModelProperties(new self(), $item, array('address1' => 'addressLineOne', 'address2' => 'addressLineTwo', 'address3' => 'addressLineThree', 'address4' => 'addressLineFour', 'address5' => 'addressLineFive'));
     }
     return $items;
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $activities = new Collection();
     foreach ($command->getResponse()->json() as $key => $activity) {
         $activities->add($key, self::hydrateModelProperties(new self(), $activity));
     }
     return $activities;
 }
Exemplo n.º 6
0
 public static function fromCommand(OperationCommand $command)
 {
     $xml = $command->getResponse()->xml();
     if (!isset($xml->AuthInfo)) {
         throw new AuthenticationException((string) $xml, $xml->attributes()['errorcode']);
     }
     $authToken = (string) $xml->AuthInfo->attributes()['authToken'];
     return $authToken;
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     // If there is no content then assume an empty collection
     if (204 == $command->getResponse()->getStatusCode()) {
         return new Collection();
     }
     $data = $command->getResponse()->json();
     // Collection of products
     if (self::isResponseDataIndexedArray($data)) {
         $products = new Collection();
         foreach ($data as $key => $productData) {
             $products->add($key, self::hydrateModelProperties(new self(), $productData, array('productId' => 'id')));
         }
         return $products;
     } else {
         return self::hydrateModelProperties(new self(), $data, array('productId' => 'id'));
     }
 }
 /**
  * Create a response model object from a completed command.
  *
  * @param OperationCommand $command That serialized the request
  * @return \Illuminate\Support\Collection
  */
 public static function fromCommand(OperationCommand $command)
 {
     // Initialize the collection
     $collection = new self($command->getResponse()->json());
     // Set the Usergrid API client on the collection
     $collection->setApiClient($command->getClient()->getApiClient());
     // Return the collection
     return $collection;
 }
Exemplo n.º 9
0
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse();
     $info = $response->getInfo();
     if ($info['content_type'] === 'image/png' || $info['content_type'] === 'image/jpg') {
         return new static(['logo' => $info['url']]);
     }
     throw new BadResponseException('Content type invalid. API returned ' . $info['content_type']);
 }
Exemplo n.º 10
0
 public static function fromCommand(OperationCommand $command)
 {
     $xml = $command->getResponse()->xml();
     $styles = $xml->StyleList->style;
     $output = array();
     foreach ($styles as $style) {
         $output[(int) $style->attributes()['guid']] = trim((string) $style);
     }
     return $output;
 }
Exemplo n.º 11
0
 public static function fromCommand(OperationCommand $command)
 {
     $xml = $command->getResponse()->xml();
     $makes = $xml->MakeList->make;
     $output = array();
     foreach ($makes as $make) {
         $output[] = trim((string) $make);
     }
     return $output;
 }
Exemplo n.º 12
0
 public static function fromCommand(OperationCommand $command)
 {
     $xml = $command->getResponse()->xml();
     $years = $xml->YearList->year;
     $output = array();
     foreach ($years as $year) {
         $output[] = (int) $year;
     }
     return $output;
 }
Exemplo n.º 13
0
 /**
  * Create a response model object from a completed command
  *
  * @param OperationCommand $command That serialized the request
  *
  * @return CurrencyCollection
  */
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse();
     $json = $response->json();
     $currencies = array();
     foreach ($json as $currency) {
         $currencies[] = new Currency($currency['code'], $currency['name'], $currency['rate']);
     }
     return new self($currencies);
 }
 /**
  * FromCommand
  *
  * @return ResponseSearchModel
  * @author James Pudney
  */
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse();
     $json = $response->json();
     $columns = self::getColumnNames($json['response']['metaData']['columns']);
     $results = $json['response']['results'];
     // reformat the results
     $results = self::formatSearchResults($results, $columns);
     // return the model
     return new self($results, $columns);
 }
Exemplo n.º 15
0
 public static function fromCommand(OperationCommand $command)
 {
     $json = $command->getResponse()->json();
     // support collections
     if (array_key_exists(0, $json)) {
         return array_map(function (array $properties) {
             return new static($properties);
         }, $json);
     }
     return new static($json);
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $instance = new self();
     $response = $command->getResponse();
     $body = $response->getBody();
     if ($body instanceof Stream) {
         $contentDispositionParts = self::parseContentDisposition($response->getContentDisposition());
         $instance->setStream($body)->setSize($response->getBody()->getSize())->setMimeType($response->getContentType())->setFileExtension($contentDispositionParts['extension'])->setFileName($contentDispositionParts['filename'])->setData($response->getBody(true));
     }
     return $instance;
 }
Exemplo n.º 17
0
 /**
  * Create a response model object from a completed command
  *
  * @param OperationCommand $command That serialized the request
  *
  * @return self
  */
 public static function fromCommand(OperationCommand $command)
 {
     $body = (string) $command->getResponse()->getBody();
     $lines = str_getcsv($body, "\n");
     $metadata = array();
     foreach ($lines as $line) {
         list($key, $value) = str_getcsv($line);
         $metadata[$key] = $value;
     }
     return new self($metadata);
 }
Exemplo n.º 18
0
 /**
  * Constructor
  *
  * @param OperationCommand $command
  */
 public function __construct(OperationCommand $command)
 {
     $this->setClient($command->getClient());
     $this->setCommandName($command->getName());
     $data = $command->getResponse()->json();
     foreach ($data as $key => $value) {
         $setter = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
         if (method_exists($this, $setter)) {
             $this->{$setter}($value);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     $records = new Collection();
     if (isset($data['records']) && is_array($data['records'])) {
         foreach ($data['records'] as $key => $object) {
             $records->add($key, self::hydrateModelProperties(new ReferencingApplicationFindResult(), $object, array('applicationUuid' => 'referencingApplicationUuId')));
         }
     }
     $instance = self::hydrateModelProperties(new self(), $data, array(), array('records' => $records));
     return $instance;
 }
 /**
  * Create a response model object from a completed command
  *
  * @param OperationCommand $command That serialized the request
  *
  * @return self
  */
 public static function fromCommand(OperationCommand $command)
 {
     $lines = explode("\n", $command->getResponse()->getBody(true));
     $head = str_getcsv(array_shift($lines), ';');
     foreach ($head as $key => $headItem) {
         $head[$key] = self::strtocamelcase($headItem);
     }
     $array = array();
     foreach ($lines as $line) {
         $array[] = array_combine($head, str_getcsv($line, ';'));
     }
     return $array;
 }
Exemplo n.º 21
0
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse()->json();
     // If 'ok' is not set or not true, something went wrong
     if (!isset($response['response']) || empty($response['ok']) || $response['ok'] != 1) {
         throw new \Exception('response not ok');
     }
     // If response is not an array return true if 1, otherwise false
     if (!is_array($response['response'])) {
         return $response['response'] == 1 ? true : false;
     }
     return $response['response'];
 }
Exemplo n.º 22
0
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse()->json();
     if (self::isListing($response)) {
         $things = array();
         foreach ($response['data']['children'] as $input) {
             $things[] = self::thingFactory()->createThing($input);
         }
         return $things;
     } else {
         $thing = self::thingFactory()->createThing($response);
         return $thing;
     }
 }
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     // Collection of notes
     if (self::isResponseDataIndexedArray($data)) {
         $notes = new Collection();
         foreach ($data as $key => $noteData) {
             $notes->add($key, self::hydrateModelProperties(new self(), $noteData));
         }
         return $notes;
     } else {
         return self::hydrateModelProperties(new self(), $data);
     }
 }
Exemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     // Indexed array of agent users
     if (self::isResponseDataIndexedArray($data)) {
         $users = new Collection();
         foreach ($data as $key => $userData) {
             $users->add($key, self::hydrateModelProperties(new self(), $userData, array('agentUserId' => 'agentUserUuId', 'fullName' => 'name')));
         }
         return $users;
     } else {
         return self::hydrateModelProperties(new self(), $data, array('agentUserId' => 'agentUserUuId', 'fullName' => 'name'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     // Collection of notifications
     if (self::isResponseDataIndexedArray($data)) {
         $notifications = new Collection();
         foreach ($data as $key => $documentData) {
             $notifications->add($key, self::hydrateModelProperties(new self(), $documentData, array('applicationId' => 'referencingApplicationUuId')));
         }
         return $notifications;
     } else {
         return self::hydrateModelProperties(new self(), $data, array('applicationId' => 'referencingApplicationUuId'));
     }
 }
Exemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $instance = new self();
     foreach ($command->getResponse()->json() as $categoryName => $items) {
         $lookupCategory = new LookupCategory();
         $lookupCategory->setName($categoryName);
         foreach ($items as $item) {
             $lookupItem = new LookupItem();
             $lookupItem->setId($item['index'])->setName($item['value']);
             $lookupCategory->addItem($lookupItem);
         }
         $instance->addCategory($lookupCategory);
     }
     return $instance;
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $uriSegments = $command->getRequest()->getUrl(true)->getPathSegments();
     $referencingCaseUuId = end($uriSegments);
     if (!is_string($referencingCaseUuId) || 36 != strlen($referencingCaseUuId)) {
         $referencingCaseUuId = null;
     }
     $data = $command->getResponse()->json();
     $address = isset($data['address']) ? self::hydrateModelProperties(new Address(), $data['address']) : null;
     $prospectiveLandlordAddress = isset($data['prospectiveLandlord']['address']) ? self::hydrateModelProperties(new Address(), $data['prospectiveLandlord']['address']) : null;
     $prospectiveLandlord = isset($data['prospectiveLandlord']) ? self::hydrateModelProperties(new ProspectiveLandlord(), $data['prospectiveLandlord'], array(), array('address' => $prospectiveLandlordAddress)) : null;
     $applications = array();
     if (isset($data['applications']) && is_array($data['applications'])) {
         foreach ($data['applications'] as $key => $object) {
             $application = ReferencingApplication::hydrate($object);
             $applications[$key] = $application;
         }
     }
     return self::hydrateModelProperties(new self(), $data, array('caseId' => 'referencingCaseUuId', 'tenancyTerm' => 'tenancyTermInMonths'), array('caseId' => $referencingCaseUuId, 'address' => $address, 'prospectiveLandlord' => $prospectiveLandlord, 'applications' => $applications));
 }
Exemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     $data = $command->getResponse()->json();
     $address = new Address();
     // Reflect the address object ready to iterate through its properties
     $addressReflection = new \ReflectionObject($address);
     // Loop through address properties looking for matches with incoming
     //   data
     foreach ($addressReflection->getProperties() as $reflectionProperty) {
         $addressField = $reflectionProperty->getName();
         if (isset($data[$addressField])) {
             // String equivalent of the setter, based on the property name
             $setMethod = 'set' . ucfirst($addressField);
             // Check that the setter method exists, if so, use it
             if (method_exists($address, $setMethod)) {
                 $address->{$setMethod}($data[$addressField]);
             }
         }
     }
     return self::hydrateModelProperties(new self(), $data, array(), array('address' => $address));
 }
 /**
  * {@inheritDoc}
  */
 public static function fromCommand(OperationCommand $command)
 {
     return self::parseResult($command->getResponse()->getBody());
 }
Exemplo n.º 30
0
 /**
  * @see ResponseClassInterface
  */
 public static function fromCommand(OperationCommand $command)
 {
     $response = $command->getResponse();
     return new self(['status' => $response->getStatusCode(), 'reason' => $response->getReasonPhrase(), 'text' => $response->getBody(true)]);
 }