Skip to content

Commit

Permalink
Added methods to retrieve campaign reports
Browse files Browse the repository at this point in the history
  • Loading branch information
x1s committed Jun 30, 2016
1 parent 1c7a8cf commit f15d39b
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This file is a manually maintained list of changes for each release. Feel free to add your
changes here when sending pull requests. Also send corrections if you spot any mistakes.

## v2.1.0 (2016-06-02) - x1s
* Features:
- Added methods to retrieve campaign reports

## v2.0.1 (2016-06-02) - x1s
* Features:
- Added missing methods for detailing campaigns
Expand Down
93 changes: 66 additions & 27 deletions examples/form-demo/campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@
$campaign = $api->getCouponInfo($campaign_id);
$passes = $api->listCouponPasses($campaign_id);

// Getting a daily report
// $report_params = array("start_date" => '2010-10-10', "end_date" => '2016-06-30');
// $daily_report = $api->getCouponDailyReport($campaign_id, $report_params);

$total_report = $api->getCouponTotalReport($campaign_id);

$report_data = get_object_vars($total_report->report);

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Testing Creation Passes</title>
<link rel="stylesheet" href="">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>

form label {
Expand All @@ -33,36 +43,65 @@
Email
<input type="email" name="email" placeholder="What is your email?">
</label>
<input type="submit" value="Generate">
<input type="submit" value="Generate" class="btn btn-primary" />
</form>

<?php if (sizeof($passes) > 0) { ?>
<section>
<h2>Existing passes</h2>
<table>
<thead>
<tr>
<th>Pass ID</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($passes as $key => $value) { ?>
<tr>
<td><?= $value->id ?></td>
<td><?= $value->created_at ?></td>
<td>
<a href="<?= $value->page_url ?>" title="">Page</a>
<a href="<?= $value->pkpass_url ?>" title="">Download</a>
<a href="<?= $value->page_url ?>.qrcode" title="">QR Code</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</section>
<div class="row">
<div class="col-md-6">
<section>
<h2>Existing passes</h2>
<table class="table">
<thead>
<tr>
<th>Pass ID</th>
<th>Created</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($passes as $key => $value) { ?>
<tr>
<td><?= $value->id ?></td>
<td><?= $value->created_at ?></td>
<td>
<a href="<?= $value->page_url ?>" title="">Page</a>
<a href="<?= $value->pkpass_url ?>" title="">Download</a>
<a href="<?= $value->page_url ?>.qrcode" title="">QR Code</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</section>
</div>
</div>
<?php } ?>

<?php if (sizeof($report_data) > 0) { ?>
<div class="row">
<div class="col-md-4">

<h2>Reports</h2>
<table class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php foreach ($report_data as $key => $value) { ?>
<tr>
<td><?= $key ?></td>
<td><?= $value ?></td>
</tr>
<?php } ?>
</tbody>
</table>

</div>
</div>
<?php } ?>
</body>
</html>
86 changes: 85 additions & 1 deletion src/Passworks/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Client extends Request {

const VERSION = '2.0.1';
const VERSION = '2.1.0';

private $api_app_id = null;
private $api_app_key = null;
Expand Down Expand Up @@ -104,6 +104,22 @@ public function listCouponPasses($campaign_id, $page = 1, $per_page = null) {
));
}

public function getCouponDailyReport($campaign_id, array $options = array()) {
$arguments = array();
if (isset($options['start_date'])) {
$arguments['start_date'] = $options['start_date'];
}
if (isset($options['end_date'])) {
$arguments['end_date'] = $options['end_date'];
}

$arguments = http_build_query($arguments);
return $this->request('get', "/coupons/{$campaign_id}/reports?{$arguments}" );
}

public function getCouponTotalReport($campaign_id) {
return $this->request('get', "/coupons/{$campaign_id}/reports/totals");
}

// =================
// Certificates
Expand Down Expand Up @@ -228,6 +244,23 @@ public function listStoreCardPasses($campaign_id, $page = 1, $per_page = null) {
));
}

public function getStoreCardDailyReport($campaign_id, array $options = array()) {
$arguments = array();
if (isset($options['start_date'])) {
$arguments['start_date'] = $options['start_date'];
}
if (isset($options['end_date'])) {
$arguments['end_date'] = $options['end_date'];
}

$arguments = http_build_query($arguments);
return $this->request('get', "/store_cards/{$campaign_id}/reports?{$arguments}" );
}

public function getStoreCardTotalReport($campaign_id) {
return $this->request('get', "/store_cards/{$campaign_id}/reports/totals");
}

// =================
// Event Tickets
//
Expand Down Expand Up @@ -285,6 +318,23 @@ public function listEventTicketPasses($campaign_id, $page = 1, $per_page = null)
));
}

public function getEventTicketDailyReport($campaign_id, array $options = array()) {
$arguments = array();
if (isset($options['start_date'])) {
$arguments['start_date'] = $options['start_date'];
}
if (isset($options['end_date'])) {
$arguments['end_date'] = $options['end_date'];
}

$arguments = http_build_query($arguments);
return $this->request('get', "/event_tickets/{$campaign_id}/reports?{$arguments}" );
}

public function getEventTicketTotalReport($campaign_id) {
return $this->request('get', "/event_tickets/{$campaign_id}/reports/totals");
}

// =================
// Boarding Pass
//
Expand Down Expand Up @@ -342,6 +392,23 @@ public function listBoardingPassPasses($campaign_id, $page = 1, $per_page = null
));
}

public function getBoardingPassDailyReport($campaign_id, array $options = array()) {
$arguments = array();
if (isset($options['start_date'])) {
$arguments['start_date'] = $options['start_date'];
}
if (isset($options['end_date'])) {
$arguments['end_date'] = $options['end_date'];
}

$arguments = http_build_query($arguments);
return $this->request('get', "/boarding_passes/{$campaign_id}/reports?{$arguments}" );
}

public function getBoardingPassTotalReport($campaign_id) {
return $this->request('get', "/boarding_passes/{$campaign_id}/reports/totals");
}

// =================
// Generic
//
Expand Down Expand Up @@ -399,4 +466,21 @@ public function listGenericCampaign($campaign_id, $page = 1, $per_page = null) {
));
}

public function getGenericCampaignDailyReport($campaign_id, array $options = array()) {
$arguments = array();
if (isset($options['start_date'])) {
$arguments['start_date'] = $options['start_date'];
}
if (isset($options['end_date'])) {
$arguments['end_date'] = $options['end_date'];
}

$arguments = http_build_query($arguments);
return $this->request('get', "/generics/{$campaign_id}/reports?{$arguments}" );
}

public function getGenericCampaignTotalReport($campaign_id) {
return $this->request('get', "/generics/{$campaign_id}/reports/totals");
}

}

0 comments on commit f15d39b

Please sign in to comment.