forked from php-xapi/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support to send and fetch attachments
- Loading branch information
Showing
11 changed files
with
224 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the xAPI package. | ||
* | ||
* (c) Christian Flothmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Xabbuh\XApi\Client\Http; | ||
|
||
use Xabbuh\XApi\Model\Attachment; | ||
|
||
/** | ||
* HTTP message body containing serialized statements and their attachments. | ||
* | ||
* @author Christian Flothmann <[email protected]> | ||
*/ | ||
final class MultipartStatementBody | ||
{ | ||
private $boundary; | ||
private $serializedStatements; | ||
private $attachments; | ||
|
||
/** | ||
* @param string $serializedStatements The JSON encoded statement(s) | ||
* @param Attachment[] $attachments The statement attachments that include not only a file URL | ||
*/ | ||
public function __construct($serializedStatements, array $attachments) | ||
{ | ||
$this->boundary = uniqid(); | ||
$this->serializedStatements = $serializedStatements; | ||
$this->attachments = $attachments; | ||
} | ||
|
||
public function getBoundary() | ||
{ | ||
return $this->boundary; | ||
} | ||
|
||
public function build() | ||
{ | ||
$body = '--'.$this->boundary."\r\n"; | ||
$body .= "Content-Type: application/json\r\n"; | ||
$body .= 'Content-Length: '.strlen($this->serializedStatements)."\r\n"; | ||
$body .= "\r\n"; | ||
$body .= $this->serializedStatements."\r\n"; | ||
|
||
foreach ($this->attachments as $attachment) { | ||
$body .= '--'.$this->boundary."\r\n"; | ||
$body .= 'Content-Type: '.$attachment->getContentType()."\r\n"; | ||
$body .= "Content-Transfer-Encoding: binary\r\n"; | ||
$body .= 'Content-Length: '.$attachment->getLength()."\r\n"; | ||
$body .= 'X-Experience-API-Hash: '.$attachment->getSha2()."\r\n"; | ||
$body .= "\r\n"; | ||
$body .= $attachment->getContent()."\r\n"; | ||
} | ||
|
||
$body .= '--'.$this->boundary.'--'."\r\n"; | ||
|
||
return $body; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.