xero-php icon indicating copy to clipboard operation
xero-php copied to clipboard

Creating an Object from cache

Open zimonline opened this issue 5 years ago • 3 comments

In order to keep things fast and not over work the API I am caching the xero records in my local DB.

How do I in this example recreate a Xero Contact Object from an Array or Json?

It would be nice to be able to

use XeroPHP\Models\Accounting\Contact as XeroContact;

$xero_contact = new XeroContact($this->xero);

$xero_contact->fromArray($data);

And have this be like the original record from xero.

Sample Data:

 {
      Name: "John Doe (A/C 000001)",
      Phones: [
        {
          PhoneType: "DDI"
        },
        {
          PhoneType: "DEFAULT"
        },
        {
          PhoneType: "FAX"
        },
        {
          PhoneType: "MOBILE"
        }
      ],
      LastName: "Doe",
      Addresses: [
        {
          AddressType: "STREET"
        },
        {
          AddressType: "POBOX"
        }
      ],
      ContactID: "5cc44607-7df3-4681-9357-5391e92e1906",
      FirstName: "John",
      IsCustomer: "false",
      IsSupplier: "false",
      EmailAddress: "[email protected]",
      ContactStatus: "ACTIVE",
      HasAttachments: "false",
      UpdatedDateUTC: "2019-09-24T11:22:36+00:00"
    },
    created_at: "2019-09-24T12:22:07+00:00",
    updated_at: "2019-09-24T12:22:07+00:00"
  }

zimonline avatar Sep 24 '19 13:09 zimonline

If you wanted to go that route, I would use an object serializer & deserializer. That being said, are you actually coming up against API limits? I would be concerned about potential inaccuracy of data records between your local DB and the Xero data, which should be point of truth. For your contact example, if you wanted to keep a local version, then I would recommend using webhooks to update your data everytime there is a change in the xero contact.

mogilvie avatar Sep 24 '19 13:09 mogilvie

If you wanted to go that route, I would use an object serializer & deserializer. That being said, are you actually coming up against API limits? I would be concerned about potential inaccuracy of data records between your local DB and the Xero data, which should be point of truth. For your contact example, if you wanted to keep a local version, then I would recommend using webhooks to update your data everytime there is a change in the xero contact.

Not too worried about the inaccuracy the point is I don't want to have to get a known contact just to add them to a group.

Is there an example of this anywhere?

zimonline avatar Sep 24 '19 13:09 zimonline

Our application uses Symfony and its Serializer component, https://symfony.com/doc/current/components/serializer.html

mogilvie avatar Sep 24 '19 14:09 mogilvie