Quick and dirty

This commit is contained in:
Josh Sherman 2016-08-10 22:47:31 -05:00
parent f93880b054
commit 1e22fd8fbe
2 changed files with 74 additions and 0 deletions

23
composer.json Normal file
View file

@ -0,0 +1,23 @@
{
"name": "joshtronic/php-holidayapi",
"description": "Official PHP library for Holiday API",
"version": "1.0.0",
"type": "library",
"keywords": [ "holiday", "holidays", "holidayapi" ],
"homepage": "https://github.com/joshtronic/php-holidayapi",
"license": "MIT",
"authors": [{
"name": "Josh Sherman",
"email": "hello@holidayapi.com",
"homepage": "https://holidayapi.com,"
}],
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"satooshi/php-coveralls": "~1.0"
},
"autoload": {
"psr-4": { "HolidayAPI\\": "src/" }
}
}

51
src/HolidayAPIv1.php Normal file
View file

@ -0,0 +1,51 @@
<?php
namespace HolidayAPI;
class v1
{
private $parameters = array();
public function __set($variable, $value)
{
$this->parameters[$variable] = $value;
}
public function __construct($key = null)
{
if ($key) {
$this->key = $key;
}
}
public function holidays($parameters = array())
{
$parameters = array_merge($this->parameters, $parameters);
$parameters = http_build_query($parameters);
$url = 'https://holidayapi.com/v1/holidays?' . $parameters;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_RETURNTRANSFER => true,
));
$response = curl_exec($curl);
if ($error = curl_error($curl)) {
return false;
}
curl_close($curl);
$response = json_decode($response, true);
if (!$response) {
return false;
}
return $response;
}
}