Skip to content

Commit

Permalink
Start of submitUpdates method - Retrieving Contact XML, parsing and m…
Browse files Browse the repository at this point in the history
…odifying to match Contact object
  • Loading branch information
Jordan Hall committed Jul 27, 2015
1 parent 8d80b7e commit fffe1d8
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion factories/ContactFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,39 @@ public static function getBySelfURL($selfURL)
return new Contact($contactDetails);
}

public static function update(Contact $contact)
public static function submitUpdates(Contact $updatedContact)
{
$client = GoogleHelper::getClient();

$req = new \Google_Http_Request($updatedContact->selfURL);

$val = $client->getAuth()->authenticatedRequest($req);

$response = $val->getResponseBody();

$xmlContact = simplexml_load_string($response);
$xmlContact->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');

$xmlContactsEntry = $xmlContact;

$xmlContactsEntry->title = $updatedContact->name;

$contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005');

foreach ($contactGDNodes as $key => $value) {
$attributes = $value->attributes();

if ($key == 'email') {
$attributes['address'] = $updatedContact->email;
} else {
$xmlContactsEntry->$key = $updatedContact->$key;
$attributes['uri'] = '';
}
}

$updatedXML = $xmlContactsEntry->asXML();

// TODO: Submission of updated XML to edit URL

}
}

0 comments on commit fffe1d8

Please sign in to comment.