Skip to content

Commit 466e4bd

Browse files
authored
Merge pull request #125 from MegaChriz/has-api-access
Pass implementation of MailchimpApiUser::hasApiAccess() to the api_access object
2 parents 91e35b2 + cbc7ce0 commit 466e4bd

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/Mailchimp.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,13 @@ public function request($method, $path, $tokens = NULL, $parameters = [], $batch
214214
return $this->client->handleRequest($method, $this->endpoint . $path, $options, $parameters, $returnAssoc);
215215
}
216216

217+
/**
218+
* {@inheritdoc}
219+
*/
220+
public function hasApiAccess() {
221+
return isset($this->api_key);
222+
}
223+
217224
/**
218225
* Gets the ID of the data center associated with an API key.
219226
*

src/Mailchimp2.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ public function request($method, $path, $tokens = NULL, $parameters = [], $batch
211211
return $this->client->handleRequest($method, $this->endpoint . $path, $options, $parameters, $returnAssoc);
212212
}
213213

214+
/**
215+
* {@inheritdoc}
216+
*/
217+
public function hasApiAccess() {
218+
return isset($this->access_token);
219+
}
220+
214221
/**
215222
* Instantiates a default HTTP client based on the local environment.
216223
*

src/MailchimpApiInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,12 @@ interface MailchimpApiInterface {
3434
*/
3535
public function request($method, $path, $tokens = NULL, $parameters = [], $batch = FALSE, $returnAssoc = FALSE);
3636

37+
/**
38+
* Checks if key or token is in place.
39+
*
40+
* @return bool
41+
* If the access_token or api_key is set.
42+
*/
43+
public function hasApiAccess();
3744

3845
}

src/MailchimpApiUser.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,7 @@ public function processBatchOperations() {
120120
* If the access_token or api_key is set.
121121
*/
122122
public function hasApiAccess() {
123-
switch (get_class($this->api_class)) {
124-
case 'Mailchimp\Mailchimp':
125-
return isset($this->api_class->api_key);
126-
break;
127-
case 'Mailchimp\Mailchimp2':
128-
return isset($this->api_class->access_token);
129-
break;
130-
}
123+
return $this->api_class->hasApiAccess();
131124
}
132125

133126
/**

0 commit comments

Comments
 (0)