Skip to content

Commit

Permalink
Merge pull request #11 from vivait/v2-mailmerge-support
Browse files Browse the repository at this point in the history
Add v2 mail merge support
  • Loading branch information
Brunty authored May 31, 2018
2 parents 81ff8a1 + 33107c7 commit e68c82a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion spec/Vivait/DocBuild/DocBuildSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function it_can_convert_a_doc_to_pdf(HttpAdapter $httpAdapter, Cache $cache)
->shouldReturn($expected);
}

function it_can_mail_merge_a_document(HttpAdapter $httpAdapter, Cache $cache)
function it_can_mail_merge_a_document(HttpAdapter $httpAdapter)
{
$expected = [];

Expand All @@ -284,6 +284,23 @@ function it_can_mail_merge_a_document(HttpAdapter $httpAdapter, Cache $cache)
->shouldReturn($expected);
}

function it_can_mail_merge_a_v2_document(HttpAdapter $httpAdapter)
{
$expected = [];

$request = [
'source' => 'a1ec0371-966d-11e4-baee-08002730eb8a',
'fields' => ['firstName' => 'Milly', 'lastName' => 'Merged'],
'callback' => 'http://localhost/test/callback?id=a1ec0371-966d-11e4-baee-08002730eb8a',
'access_token' => 'myapitoken',
];

$httpAdapter->post('v2/mailmerge', $request, [], HttpAdapter::RETURN_TYPE_JSON)->willReturn($expected);

$this->v2MailMergeDocument('a1ec0371-966d-11e4-baee-08002730eb8a', ['firstName' => 'Milly', 'lastName' => 'Merged'], 'http://localhost/test/callback?id=a1ec0371-966d-11e4-baee-08002730eb8a')
->shouldReturn($expected);
}

function it_errors_with_invalid_credentials(HttpAdapter $httpAdapter, Cache $cache)
{
$this->setClientSecret('anincorrectsecret');
Expand Down
9 changes: 9 additions & 0 deletions src/Vivait/DocBuild/DocBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ public function mailMergeDocument($source, Array $fields, $callback = null)
]);
}

public function v2MailMergeDocument($source, Array $fields, $callback = null)
{
return $this->post('v2/mailmerge', [
'source' => $source,
'fields' => $fields,
'callback' => $callback,
]);
}

public function getHttpAdapter()
{
return $this->http;
Expand Down

0 comments on commit e68c82a

Please sign in to comment.