-
Notifications
You must be signed in to change notification settings - Fork 9
Add attachments feature #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krichprollsch
wants to merge
1
commit into
Calendart:master
Choose a base branch
from
krichprollsch:attachments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
| /** | ||
| * This file is part of the CalendArt package | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE file | ||
| * that was distributed with this source code. | ||
| * | ||
| * @copyright Wisembly | ||
| * @license http://www.opensource.org/licenses/MIT-License MIT License | ||
| */ | ||
|
|
||
| namespace CalendArt\Adapter\Office365\Model; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| abstract class Attachment | ||
| { | ||
| /** | ||
| * Hydrate a new Event object with data received from Office365 api | ||
| * | ||
| * @param array $data Data to feed the Event object with | ||
| * @return CalendArt\Attachment | ||
| */ | ||
| public static function hydrate(array $data) | ||
| { | ||
| if (!isset($data['Id'], $data['@odata.type'])) { | ||
| throw new InvalidArgumentException(sprintf('Missing at least one of the mandatory properties "Id", "@odata.type" ; got ["%s"]', implode('", "', array_keys($data)))); | ||
| } | ||
|
|
||
| if ('#Microsoft.OutlookServices.FileAttachment' === $data['@odata.type']) { | ||
| return FileAttachment::hydrate($data); | ||
| } | ||
|
|
||
| if ('#Microsoft.OutlookServices.ItemAttachment' === $data['@odata.type']) { | ||
| return ItemAttachment::hydrate($data); | ||
| } | ||
|
|
||
| throw new InvalidArgumentException(sprintf('Unknown attachment type %s', $data['@odata.type'])); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <?php | ||
| /** | ||
| * This file is part of the CalendArt package | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE file | ||
| * that was distributed with this source code. | ||
| * | ||
| * @copyright Wisembly | ||
| * @license http://www.opensource.org/licenses/MIT-License MIT License | ||
| */ | ||
|
|
||
| namespace CalendArt\Adapter\Office365\Model; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| use CalendArt\UriAttachment; | ||
|
|
||
| class FileAttachment implements UriAttachment | ||
| { | ||
| private $name; | ||
| private $uri; | ||
| private $content; | ||
| private $id; | ||
| private $size; | ||
| private $contentType; | ||
| private $raw; | ||
|
|
||
| public function __construct($name, $uri) | ||
| { | ||
| $this->name = $name; | ||
| $this->uri = $uri; | ||
| } | ||
|
|
||
| /** | ||
| * Hydrate a new Event object with data received from Office365 api | ||
| * | ||
| * @param array $data Data to feed the Event object with | ||
| * @return CalendArt\Attachment | ||
| */ | ||
| public static function hydrate(array $data) | ||
| { | ||
| if (!isset($data['Id'], $data['@odata.type'])) { | ||
| throw new InvalidArgumentException(sprintf('Missing at least one of the mandatory properties "Id", "@odata.type" ; got ["%s"]', implode('", "', array_keys($data)))); | ||
| } | ||
|
|
||
| if ('#Microsoft.OutlookServices.FileAttachment' !== $data['@odata.type']) { | ||
| throw new InvalidArgumentException(sprintf('Unknown attachment type %s', $data['@odata.type'])); | ||
| } | ||
|
|
||
| $attachment = new static($data['Name'], $data['ContentLocation']); | ||
| $attachment->id = $data['Id']; | ||
| $attachment->content = $data['ContentBytes']; | ||
| $attachment->size = $data['Size']; | ||
| $attachment->contentType = $data['ContentType']; | ||
| $attachment->raw = $data; | ||
|
|
||
| return $attachment; | ||
| } | ||
|
|
||
| public function getName() | ||
| { | ||
| return $this->name; | ||
| } | ||
|
|
||
| public function getUri() | ||
| { | ||
| return $this->uri; | ||
| } | ||
|
|
||
| public function getSize() | ||
| { | ||
| return $this->size; | ||
| } | ||
|
|
||
| public function getContentType() | ||
| { | ||
| return $this->contentType; | ||
| } | ||
|
|
||
| public function getId() | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| public function getRaw() | ||
| { | ||
| return $this->raw; | ||
| } | ||
|
|
||
| public function getContents() | ||
| { | ||
| return $this->content; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
| /** | ||
| * This file is part of the CalendArt package | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE file | ||
| * that was distributed with this source code. | ||
| * | ||
| * @copyright Wisembly | ||
| * @license http://www.opensource.org/licenses/MIT-License MIT License | ||
| */ | ||
|
|
||
| namespace CalendArt\Adapter\Office365\Model; | ||
|
|
||
| use InvalidArgumentException; | ||
|
|
||
| use CalendArt\Attachement; | ||
|
|
||
| class FileAttachment implements UriAttachment | ||
| { | ||
| private $id; | ||
| private $name; | ||
| private $contentType; | ||
| private $item; | ||
|
|
||
| public function __construct($name, Event $event) | ||
| { | ||
| $this->event = $event; | ||
| $this->name = $name; | ||
| } | ||
|
|
||
| /** | ||
| * Hydrate a new Event object with data received from Office365 api | ||
| * | ||
| * @param array $data Data to feed the Event object with | ||
| * @return CalendArt\Attachment | ||
| */ | ||
| public static function hydrate(array $data) | ||
| { | ||
| if (!isset($data['Id'], $data['@odata.type'])) { | ||
| throw new InvalidArgumentException(sprintf('Missing at least one of the mandatory properties "Id", "@odata.type" ; got ["%s"]', implode('", "', array_keys($data)))); | ||
| } | ||
|
|
||
| if ('#Microsoft.OutlookServices.ItemAttachment' !== $data['@odata.type']) { | ||
| throw new InvalidArgumentException(sprintf('Unknown attachment type %s', $data['@odata.type'])); | ||
| } | ||
|
|
||
| $attachment = new static($data['Name'], Event::hydrate($data['Event'])); | ||
| $attachment->id = $data['Id']; | ||
| $attachment->contentType = $data['ContentType']; | ||
| $attachment->raw = $data; | ||
|
|
||
| return $attachment; | ||
| } | ||
|
|
||
| public function getEvent() | ||
| { | ||
| return $this->event; | ||
| } | ||
|
|
||
| public function getContentType() | ||
| { | ||
| return $this->contentType; | ||
| } | ||
|
|
||
| public function getId() | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| public function getRaw() | ||
| { | ||
| return $this->raw; | ||
| } | ||
|
|
||
| public function getContents() | ||
| { | ||
| return $this->getEvent(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be
$list?