Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Added singular club retrieval method & example
Browse files Browse the repository at this point in the history
  • Loading branch information
grega committed Aug 1, 2016
1 parent 07430fd commit 8e208c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ The constants defined in your child theme's `/inc/country-config.php` are now av

### Club Retrieval

Assuming the values in `inc/country-config.php` have been correctly set (see above), it's possible to to retrieve club data very simply within any template:
Assuming the values in `inc/country-config.php` have been correctly set (see above), it's possible to to retrieve club data (from your country / community) very simply within any template:

```
<?php
Expand Down Expand Up @@ -255,6 +255,18 @@ Array

which can then be used to generate pagination links.

To retrieve a single club by its ID (in this case, `1`) simply use:

```
<?php
$ccw_api = new CCW_API();
$response = $ccw_api->getClub(1);
$club = $response['body'];
?>
```

(bear in mind that you'll need to supply an ID for a club that belongs to your country / community!)


Finally, to improve on the club retrieval examples, some error checking / handling would be useful:

Expand Down
20 changes: 20 additions & 0 deletions inc/ccw-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ public function getClubs( $state = 'active', $per_page = 50, $page = 1 ) {
return $response;
}

/**
* @param integer $id The ID of the club
* @return array $response Containing 'headers' & 'body' arrays
*/
public function getClub( $id ) {
$url = CCW_API_URL . '/clubs/' . $id;
$headers = [
'AUTHORIZATION' => 'Bearer ' . CCW_API_READONLY_TOKEN,
'Accept' => 'application/vnd.codeclubworld.v' . CCW_API_VERSION,
];

$response = wp_remote_get( $url,
array(
'timeout' => 30,
'headers' => $headers,
)
);
return $response;
}

/**
* @param json $club_json Club data (inc. venue, address, contact) in a JSON encoded array
* @return array $response Containing 'headers', 'body' & 'response' arrays
Expand Down

0 comments on commit 8e208c6

Please sign in to comment.