Skip to content

Commit 8aa9106

Browse files
committed
🛠 Re-worked TwitterOAuth.php 🛠
:octocat: -To fill a need for conversion of media URLs to base64 (negating the need for storing the media prior to uploading) -Added public function `shipit` that privately calls to -Added private function `uploadMediaNotStored`
1 parent 1560454 commit 8aa9106

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Diff for: src/TwitterOAuth.php

+29-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,35 @@ public function mediaStatus(string $media_id)
315315
false,
316316
);
317317
}
318-
318+
/**
319+
* Convert a URL to media to upload.twitter.com.
320+
*
321+
* @param string $path
322+
* @param array $parameters
323+
*
324+
* @return array|object
325+
*/
326+
public function shipit($path, $parameters = []) {
327+
return $this->uploadMediaNotStored($path, $parameters);
328+
/**
329+
* Private method to convert a URL to media to upload.twitter.com.
330+
*
331+
* @param string $path
332+
* @param array $parameters
333+
* @param boolean $chunked
334+
*
335+
* @return array|object
336+
*/
337+
}
338+
private function uploadMediaNotStored($path, array $parameters)
339+
{
340+
if (! is_readable($parameters['media']) &&
341+
($file = file_get_contents($parameters['media'])) === false) {
342+
throw new \InvalidArgumentException('You must supply a readable file');
343+
}
344+
$parameters['media'] = base64_encode($file);
345+
return $this->http('POST', self::UPLOAD_HOST, $path, $parameters);
346+
}
319347
/**
320348
* Private method to upload media (not chunked) to upload.twitter.com.
321349
*

0 commit comments

Comments
 (0)