Skip to content

Commit

Permalink
Merge pull request #2 from keesschepers/master
Browse files Browse the repository at this point in the history
Be able to fetch the contents of the PDF label.
  • Loading branch information
stephangroen committed Feb 15, 2016
2 parents f51c9c6 + 09f06c2 commit 17d01ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Picqer/Carriers/SendCloud/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,22 @@ public function setEnvironment($environment)
$this->environment = $environment;
}

/**
* Download a resource.
*
* @param string $url
*
* @return string
*/
public function download($url)
{
try {
$result = $this->client()->get($url);
} catch (RequestException $e) {
throw new SendCloudApiException('SendCloud error: (no error message provided)' . $e->getResponse());
}

return $result->getBody()->getContents();
}
}

13 changes: 12 additions & 1 deletion src/Picqer/Carriers/SendCloud/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ class Label extends Model {
'plural' => 'labels'
];

}
/**
* Returns the label content (PDF) in A6 format.
*
* @return string
*/
public function labelPrinterContent()
{
$url = str_replace($this->connection->apiUrl(), '', $this->label_printer);

return $this->connection->download($url);
}
}

0 comments on commit 17d01ef

Please sign in to comment.