Last active
April 28, 2023 08:37
-
-
Save mattiasghodsian/5590e589f02048d34ed9d883da3b1a23 to your computer and use it in GitHub Desktop.
Ratsit API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example