Skip to content

Commit c09b868

Browse files
committed
Merge pull request #2 from bryceadams/master
Add fetch_campaign method & close issue #1
2 parents 376f921 + 1b79eb2 commit c09b868

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Drip_API.class.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,44 @@ public function get_campaigns($params) {
7777
return $campaigns;
7878
}
7979

80+
/**
81+
* Fetch a campaign for the given account based on it's ID.
82+
* @param array (account_id, campaign_id)
83+
* @return array
84+
*/
85+
public function fetch_campaign($params) {
86+
if (empty($params['account_id'])) {
87+
throw new Exception("Account ID not specified");
88+
}
89+
90+
$account_id = $params['account_id'];
91+
unset($params['account_id']); // clear it from the params
92+
93+
if (!empty($params['campaign_id'])) {
94+
$campaign_id = $params['campaign_id'];
95+
unset($params['campaign_id']); // clear it from the params
96+
} else {
97+
throw new Exception("Campaign ID was not specified. You must specify a Campaign ID");
98+
}
99+
100+
$url = $this->api_end_point . "$account_id/campaigns/$campaign_id";
101+
$res = $this->make_request($url, $params);
102+
103+
if (!empty($res['buffer'])) {
104+
$raw_json = json_decode($res['buffer'], true);
105+
}
106+
107+
// here we distinguish errors from no campaign
108+
// when there's no json that's an error
109+
$campaigns = empty($raw_json)
110+
? false
111+
: empty($raw_json['campaigns'])
112+
? array()
113+
: $raw_json['campaigns'];
114+
115+
return $campaigns;
116+
}
117+
80118
/**
81119
* Requests the accounts for the given account.
82120
* Parses the response JSON and returns an array which contains: id, name, created_at etc

0 commit comments

Comments
 (0)