Skip to content

Commit

Permalink
Merge pull request #47 from resand/master
Browse files Browse the repository at this point in the history
Added note for creation and list & updated README.md
  • Loading branch information
DivineOmega authored Oct 13, 2017
2 parents 880971b + b4adb44 commit 5efb7ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $contact = rapidweb\googlecontacts\factories\ContactFactory::getBySelfURL($selfU
echo $contact->name;
echo $contact->phoneNumber;
echo $contact->email;
echo $contact->content;
```

### Updating existing Google Contacts
Expand All @@ -83,6 +84,7 @@ var_dump($contact);
$contact->name = 'Test';
$contact->phoneNumber = '07812363789';
$contact->email = '[email protected]';
$contact->content = 'Note for example';

$contactAfterUpdate = rapidweb\googlecontacts\factories\ContactFactory::submitUpdates($contact);

Expand All @@ -97,8 +99,9 @@ Creating a new Google Contact is very easy. Simply call the `ContactFactory::cre
$name = "Frodo Baggins";
$phoneNumber = "06439111222";
$emailAddress = "[email protected]";
$note = "Note for example";

$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress);
$newContact = rapidweb\googlecontacts\factories\ContactFactory::create($name, $phoneNumber, $emailAddress, $note);
```

### Config file override
Expand Down
9 changes: 8 additions & 1 deletion factories/ContactFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static function getAll($customConfig = NULL)

$contactDetails['id'] = (string) $xmlContactsEntry->id;
$contactDetails['name'] = (string) $xmlContactsEntry->title;
$contactDetails['content'] = (string) $xmlContactsEntry->content;

foreach ($xmlContactsEntry->children() as $key => $value) {
$attributes = $value->attributes();
Expand Down Expand Up @@ -93,6 +94,7 @@ public static function getBySelfURL($selfURL, $customConfig = NULL)

$contactDetails['id'] = (string) $xmlContactsEntry->id;
$contactDetails['name'] = (string) $xmlContactsEntry->title;
$contactDetails['content'] = (string) $xmlContactsEntry->content;

foreach ($xmlContactsEntry->children() as $key => $value) {
$attributes = $value->attributes();
Expand Down Expand Up @@ -187,6 +189,7 @@ public static function submitUpdates(Contact $updatedContact, $customConfig = NU

$contactDetails['id'] = (string) $xmlContactsEntry->id;
$contactDetails['name'] = (string) $xmlContactsEntry->title;
$contactDetails['content'] = (string) $xmlContactsEntry->content;

foreach ($xmlContactsEntry->children() as $key => $value) {
$attributes = $value->attributes();
Expand Down Expand Up @@ -215,7 +218,7 @@ public static function submitUpdates(Contact $updatedContact, $customConfig = NU
return new Contact($contactDetails);
}

public static function create($name, $phoneNumber, $emailAddress, $customConfig = NULL)
public static function create($name, $phoneNumber, $emailAddress, $note, $customConfig = NULL)
{
$doc = new \DOMDocument();
$doc->formatOutput = true;
Expand All @@ -237,6 +240,10 @@ public static function create($name, $phoneNumber, $emailAddress, $customConfig
$contact->setAttribute('rel', 'http://schemas.google.com/g/2005#work');
$entry->appendChild($contact);

$note = $doc->createElement('atom:content', $note);
$note->setAttribute('rel', 'http://schemas.google.com/g/2005#kind');
$entry->appendChild($note);

$xmlToSend = $doc->saveXML();

$client = GoogleHelper::getClient($customConfig);
Expand Down
1 change: 1 addition & 0 deletions test_individual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
$contact->name = 'Test';
$contact->phoneNumber = '07812363789';
$contact->email = '[email protected]';
$contact->content = 'Note for example';

$contactAfterUpdate = ContactFactory::submitUpdates($contact);

Expand Down

0 comments on commit 5efb7ed

Please sign in to comment.