Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Countries and States Rest APIs #3782

Merged
merged 3 commits into from
Dec 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/ChurchCRM/data/Countries.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: georg
* Date: 11/12/2016
* Time: 12:00 PM.
*/

namespace ChurchCRM\data;

class Countries
Expand Down
30 changes: 30 additions & 0 deletions src/ChurchCRM/data/States.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace ChurchCRM\data;

use ChurchCRM\dto\SystemURLs;

class States
{
private $countryCode;
private $states = [];

public function __construct($countryCode)
{
$this->countryCode = $countryCode;
$stateFileName = SystemURLs::getDocumentRoot() . '/locale/states/'. $countryCode .'.json';
if( is_file($stateFileName)) {
$satesFile = file_get_contents($stateFileName);
$this->states = json_decode($satesFile, true);
}
}

public function getNames()
{
return array_values($this->states);
}

public function getAll()
{
return $this->states;
}
}
2 changes: 1 addition & 1 deletion src/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
require __DIR__.'/routes/geocoder.php';

require __DIR__.'/routes/public.php';

require __DIR__.'/routes/public-data.php';

// Run app
$app->run();
24 changes: 24 additions & 0 deletions src/api/routes/public-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Slim\Http\Request;
use Slim\Http\Response;
use ChurchCRM\Service\CalendarService;
use ChurchCRM\data\Countries;
use ChurchCRM\data\States;

$app->group('/public/data', function () {
$this->get('/countries', 'getCountries');
$this->get('/countries/', 'getCountries');
$this->get('/countries/{countryCode}/states', 'getStates');
$this->get('/countries/{countryCode}/states/', 'getStates');
});


function getCountries(Request $request, Response $response, array $args ) {
return $response->withJson(Countries::getAll());
}

function getStates(Request $request, Response $response, array $args ) {
$states = new States($args['countryCode']);
return $response->withJson($states->getAll());
}
15 changes: 15 additions & 0 deletions src/locale/states/ca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"AB": "Alberta",
"BC": "British Columbia",
"MB": "Manitoba",
"NB": "New Brunswick",
"NL": "Newfoundland and Labrador",
"NS": "Nova Scotia",
"NT": "Northwest Territories",
"NU": "Nunavut",
"ON": "Ontario",
"PE": "Prince Edward Island",
"QC": "Québec",
"SK": "Saskatchewan",
"YT": "Yukon"
}
61 changes: 61 additions & 0 deletions src/locale/states/us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
"DC": "District Of Columbia",
"FM": "Federated States Of Micronesia",
"FL": "Florida",
"GA": "Georgia",
"GU": "Guam",
"HI": "Hawaii",
"ID": "Idaho",
"IL": "Illinois",
"IN": "Indiana",
"IA": "Iowa",
"KS": "Kansas",
"KY": "Kentucky",
"LA": "Louisiana",
"ME": "Maine",
"MH": "Marshall Islands",
"MD": "Maryland",
"MA": "Massachusetts",
"MI": "Michigan",
"MN": "Minnesota",
"MS": "Mississippi",
"MO": "Missouri",
"MT": "Montana",
"NE": "Nebraska",
"NV": "Nevada",
"NH": "New Hampshire",
"NJ": "New Jersey",
"NM": "New Mexico",
"NY": "New York",
"NC": "North Carolina",
"ND": "North Dakota",
"MP": "Northern Mariana Islands",
"OH": "Ohio",
"OK": "Oklahoma",
"OR": "Oregon",
"PW": "Palau",
"PA": "Pennsylvania",
"PR": "Puerto Rico",
"RI": "Rhode Island",
"SC": "South Carolina",
"SD": "South Dakota",
"TN": "Tennessee",
"TX": "Texas",
"UT": "Utah",
"VT": "Vermont",
"VI": "Virgin Islands",
"VA": "Virginia",
"WA": "Washington",
"WV": "West Virginia",
"WI": "Wisconsin",
"WY": "Wyoming"
}