Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:37
Show Gist options
  • Select an option

  • Save mattiasghodsian/5590e589f02048d34ed9d883da3b1a23 to your computer and use it in GitHub Desktop.

Select an option

Save mattiasghodsian/5590e589f02048d34ed9d883da3b1a23 to your computer and use it in GitHub Desktop.
Ratsit API
<?php
/**
* Title: Ratsit
* Author: Mattias Ghodsian
* Docs: https://api.ratsit.se/swagger/ui/index.html#/
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
**/
class RATSIT
{
/**
* Vars
*/
private $action = "";
private $method = "";
private $baseURI = "https://api.ratsit.se/api/v1/";
private $authorization = "";
private $packages = "";
private $fields = "";
/**
* __construct
*
* @param string $authorization base64
* @param string $packages personadress
*
* return null
*/
function __construct($authorization, $packages)
{
$this->authorization = $authorization;
$this->packages = $packages;
}
/**
* SetAction
*
* @param fields $fields ['SSN' => 194103222222]
*
* return null
*/
public function setFields($fields = [])
{
$this->fields = http_build_query($fields);
}
/**
* SetAction
*
* @param string $string personinformation
*
* return null
*/
public function setAction($string)
{
$this->action = $string.'?';
}
/**
* setMethod
*
* @param string $method POST/GET/
*
* return null
*/
public function setMethod($method = "GET")
{
$this->method = $method;
}
/**
* Response
*
* return array
*/
public function response()
{
return $this->curl();
}
/**
* CURL
*
* return array
*/
private function curl()
{
$url = $this->baseURI.$this->action.$this->fields;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Basic $this->authorization",
"Package: $this->packages")
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result,true);
return array_merge(['query' => $url], $data);
}
}
?>
@mattiasghodsian
Copy link
Author

mattiasghodsian commented Apr 4, 2018

Example

$api = New RATSIT('key','key');
$api->setAction('personinformation');
$api->setMethod('GET');
$api->setFields(['SSN' => '194103222222']);
$api->response();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment