Skip to content

Commit

Permalink
Added addStackItemBySlugToStack
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Lehtinen committed May 14, 2024
1 parent a3df6df commit 30cfc6c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ composer require lasselehtinen/issuu
| Delete a Stack by ID | Yes |
| Update Stack data by ID | No |
| Get Stack Items slug | Yes |
| Add Stack Item by slug to stack | No |
| Add Stack Item by slug to stack | Yes |
| Delete Stack Item by slug from stack | No |

# Stats
Expand Down
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ grumphp:
stop_on_failure: false
ignore_unstaged_changes: false
hide_circumvention_tip: false
process_timeout: 60
process_timeout: 120
ascii:
failed: ~
succeeded: ~
Expand Down
12 changes: 12 additions & 0 deletions src/Stacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,16 @@ public function getStackItemsSlug(string $id, bool $includeUnlisted = true, int
{
return $this->issuu->getResponse(method: 'GET', endpoint: 'stacks/'.$id.'/items');
}

/**
* Add Stack Item by slug to stack
* @see https://api.issuu.com/v2/reference/#post-/stacks/-stackId-/items
* @param string $id The unique identifier of the stack to add the document to.
* @param array<mixed> $body Stack data to create.
* @return stdClass
*/
public function addStackItemBySlugToStack(string $id, array $body = []): stdClass
{
return $this->issuu->getResponse(method: 'POST', endpoint: 'stacks/'.$id.'/items', body: $body);
}
}
66 changes: 66 additions & 0 deletions tests/StacksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Exception;
use Tests\TestCase;
use lasselehtinen\Issuu\Issuu;
use lasselehtinen\Issuu\Drafts;
use lasselehtinen\Issuu\Stacks;

class StacksTest extends TestCase
Expand Down Expand Up @@ -157,4 +158,69 @@ public function testGettingStackItems()
$this->assertIsObject($stackItems);
$this->assertIsArray($stackItems->results);
}

/**
* Test adding Publications to Stack by slug
*
* @return void
*/
public function testAddingPublicationsToStackBySlug()
{
// Create Draft and publish it as Publication
$drafts = new Drafts($this->issuu);

$body = [
'confirmCopyright' => true,
'fileUrl' => 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
'info' => [
'file' => 0,
'access' => 'PUBLIC',
'title' => 'Test document',
'description' => 'Description',
'preview' => false,
'type' => 'editorial',
'showDetectedLinks' => false,
'downloadable' => false,
'originalPublishDate' => '1970-01-01T00:00:00.000Z',
],
];

$createDraft = $drafts->create($body);

// Try few times until the file is converted
for ($i=0; $i < 10; $i++) {
$draft = $drafts->getDraftBySlug($createDraft->slug);
$conversionStatus = $draft->fileInfo->conversionStatus;

if ($conversionStatus === 'DONE') {
break;
}

sleep(2);
}

$publishDraftBySlug = $drafts->publishDraftBySlug($createDraft->slug, ['desiredName' => 'foobar']);

// Create Stack
$stacks = new Stacks($this->issuu);
$stackCreate = $stacks->create(['accessType' => 'UNLISTED', 'description' => 'Test stack', 'title' => 'Test stack']);

// Add slug to Stack
$stacks->addStackItemBySlugToStack($stackCreate->content, ['slug' => $createDraft->slug]);

// Try few times until publication is added to the Stack
for ($i=0; $i < 10; $i++) {
$stackItems = $stacks->getStackItemsSlug($stackCreate->content);

if (count($stackItems->results) > 0) {
break;
}

sleep(5);
}

$this->assertIsObject($stackItems);
$this->assertIsArray($stackItems->results);
$this->assertCount(1, $stackItems->results);
}
}

0 comments on commit 30cfc6c

Please sign in to comment.