Skip to content

Commit

Permalink
fetch real data
Browse files Browse the repository at this point in the history
  • Loading branch information
zuzana-kunckova committed Mar 19, 2021
1 parent ee1b54b commit 1ef1fee
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/composer.lock
/phpunit.xml
.phpunit.result.cache
/tests/tweet.html
/tests/tweet.html
.env
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"require": {
"php": "^7.4 || ^8.0",
"dg/twitter-php": "^4.1",
"illuminate/support": "^7.0 || ^8.0",
"illuminate/view": "^7.0 || ^8.0"
},
Expand Down
27 changes: 8 additions & 19 deletions resources/views/components/tweet.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@
<div class="relative bg-white shadow-lg rounded sm:rounded-md p-4 sm:p-6 lg:p-8 space-y-4">
<header class="flex flex-row items-center space-x-2">
<div>
<!-- twitter.user.avatar -->
<img src="/assets/logo.png" class="h-12 sm:h-16 w-12 sm:w-16" alt=" avatar">
<img src="{{ $user->profile_image_url_https }}" class="h-12 sm:h-16 w-12 sm:w-16" alt=" avatar">
</div>
<div class="flex-grow">
<div class="flex flex-row space-x-2">
<!-- twitter.user.name -->
<div class="text-xl text-gray-600 font-bold tracking-wide">Larabelles</div>
<!-- twitter.user.handle -->
<div class="text-gray-400">@LarabellesPHP</div>
<div class="text-xl text-gray-600 font-bold tracking-wide">{{ $user->name }}</div>
<div class="text-gray-400">{{ '@'.$user->screen_name }}</div>
</div>
<!-- tweet.date -->
<div class="text-sm text-gray-400">8:39 AM - Feb 12, 2021</div>
<div class="text-sm text-gray-400">{{ \Carbon\Carbon::parse($created_at)->toDayDateTimeString() }}</div>
</div>
<div>
<!-- tweet.url -->
<a href="#">
<a href="https://twitter.com/{{ $user->screen_name }}/status/{{ $id }}">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
width="289.984" height="289.984" viewBox="0 0 289.984 289.984" xml:space="preserve" class="h-4 sm:h-6">
<desc>Created with Fabric.js 1.7.22</desc>
Expand All @@ -47,19 +42,13 @@

<main>
<p class="overflow-clip overflow-hidden inline">
<!-- tweet.body -->
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque convallis, turpis et
hendrerit viverra, tortor mi imperdiet eros, sit amet tristique nisl ligula vitae magna.
{{ $text }}
</p>
<!-- tweet.url -->
<a class="text-blue-400" href="#">tweet.url</a>
</main>

<footer class="space-x-4">
<!-- tweet.like -->
<span class="text-gray-400 text-sm">&#9825; 35</span>
<!-- twitter.user.handle -->
<span class="text-gray-400 text-sm"><a href="#">&#9733; See LarabellesPHPs other Tweets</a></span>
<span class="text-gray-400 text-sm">&#9825; {{ $favorite_count }}</span>
<span class="text-gray-400 text-sm"><a href="https://twitter.com/{{ $user->screen_name }}">&#9733; See {{ $user->name }}'s other Tweets</a></span>
</footer>
</div>
</article>
Expand Down
17 changes: 16 additions & 1 deletion src/View/Components/Tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

namespace Larabelles\TweetComponent\View\Components;

use DG\Twitter\Twitter;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Tweet extends Component
{
protected string $id;

public function __construct(string $id)
{
$this->id = $id;
}

public function render() : View
{
return view('tweet-component::components.tweet');
return view('tweet-component::components.tweet', $this->retrieveData());
}

protected function retrieveData() : array
{
$twitter = new Twitter(env('TWITTER_CONSUMER_KEY'), env('TWITTER_CONSUMER_SECRET'), env('TWITTER_ACCESS_TOKEN'), env('TWITTER_ACCESS_TOKEN_SECRET'));

return collect($twitter->request("statuses/show/{$this->id}", 'GET'))->dump()->toArray();
}
}
11 changes: 11 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@

abstract class TestCase extends OrchestraTestCase
{
protected $loadEnvironmentVariables = true;

protected function resolveApplication()
{
$app = parent::resolveApplication();

$app->useEnvironmentPath(__DIR__.'/..');

return $app;
}

protected function getPackageProviders($app) : array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion tests/TweetComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TweetComponentTest extends TestCase
/** @test */
public function it_renders() : void
{
$html = $this->blade('<x-tweet />');
$html = $this->blade('<x-tweet id="1372946230783934465" />');

file_put_contents(__DIR__.'/tweet.html', $html);
}
Expand Down

0 comments on commit 1ef1fee

Please sign in to comment.