Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Cjbenavides88 fetch media item comments (#102)
Browse files Browse the repository at this point in the history
Created function to fetch comments from a media item.
  • Loading branch information
cjbenavides88 authored and vinkla committed Apr 11, 2019
1 parent e78afff commit 4c27a16
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ To fetch the user information data you may use the `self()` method.
$instagram->self();
```

To [fetch media item comments](https://www.instagram.com/developer/endpoints/comments/#get_media_comments) you may use the `comments()` method.

```php
$instagram->comments('20033001112203311302_0102938816');
```

> **Note:** You can only fetch a user's recent media from the given access token.
## Rate Limiting
Expand Down
14 changes: 14 additions & 0 deletions src/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public function media(array $parameters = []): array
return $response->data;
}

/**
* Fetch comments from media item.
*
* @param string $mediaId
*
* @return array
*/
public function comments(string $mediaId) : array
{
$response = $this->get('media/'.$mediaId.'/comments');

return $response->data;
}

/**
* Fetch user information.
*
Expand Down
42 changes: 29 additions & 13 deletions tests/InstagramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ public function testMedia()
$this->assertCount(20, $items);
}

public function testCanAppendParametersToMedia()
{
$response = new Response(200, [], json_encode([
'data' => [],
'meta' => [],
]));

$client = new Client();
$client->addResponse($response);

$instagram = new Instagram('jerryseinfeld', $client);
$instagram->media([
'count' => 22,
'min_id' => 'min id',
'max_id' => 'max id',
]);

$request = $client->getLastRequest();

$this->assertSame(
'access_token=jerryseinfeld&count=22&min_id=min+id&max_id=max+id',
$request->getUri()->getQuery()
);
}

public function testSelf()
{
$response = new Response(200, [], json_encode([
Expand All @@ -59,29 +84,20 @@ public function testSelf()
$this->assertIsObject($user);
}

public function testCanAppendParametersToMedia()
public function testComments()
{
$response = new Response(200, [], json_encode([
'data' => [],
'data' => range(1, 5),
'meta' => [],
]));

$client = new Client();
$client->addResponse($response);

$instagram = new Instagram('jerryseinfeld', $client);
$instagram->media([
'count' => 22,
'min_id' => 'min id',
'max_id' => 'max id',
]);

$request = $client->getLastRequest();
$comments = $instagram->comments('media-id');

$this->assertSame(
'access_token=jerryseinfeld&count=22&min_id=min+id&max_id=max+id',
$request->getUri()->getQuery()
);
$this->assertIsArray($comments);
}

public function testError()
Expand Down

0 comments on commit 4c27a16

Please sign in to comment.