This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f99d8bf
Showing
5 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vendor | ||
composer.lock | ||
index.php |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Bestoon php client | ||
|
||
### Install | ||
|
||
you can install client with composer | ||
``` | ||
composer require bestoon/client | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "bestoon/client", | ||
"description": "Bestoon php client", | ||
"authors": [ | ||
{ | ||
"name": "Alireza Josheghani", | ||
"email": "josheghani.dev@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Bestoon\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"license": "MIT" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Bestoon; | ||
|
||
class Client | ||
{ | ||
use Request; | ||
|
||
/** | ||
* Base url of client | ||
* | ||
* @var string | ||
*/ | ||
protected $baseUrl = 'http://bestoon.ir'; | ||
|
||
/** | ||
* Token of client | ||
* | ||
* @var string | ||
*/ | ||
protected $token = null; | ||
|
||
/** | ||
* Client constructor. | ||
* | ||
* @param array $options | ||
*/ | ||
public function __construct(array $options) | ||
{ | ||
if(empty($options) || ! isset($options['token'])){ | ||
throw new \Exception("The token is required !"); | ||
} | ||
|
||
$this->token = $options['token']; | ||
} | ||
|
||
/** | ||
* Get stat | ||
* | ||
* @return mixed | ||
*/ | ||
public function generalStat() | ||
{ | ||
$response = $this->post($this->baseUrl . '/q/generalstat/',[ | ||
'token' => $this->token | ||
]); | ||
|
||
return json_decode($response, true); | ||
} | ||
|
||
/** | ||
* Get expense | ||
* | ||
* @param $amount | ||
* @param $text | ||
* @return mixed | ||
*/ | ||
public function expense($amount, $text) | ||
{ | ||
$response = $this->post($this->baseUrl . '/submit/expense',[ | ||
'token' => $this->token, | ||
'amount' => $amount, | ||
'text' => $text | ||
]); | ||
|
||
return json_decode($response, true); | ||
} | ||
|
||
/** | ||
* Get income | ||
* | ||
* @param $amount | ||
* @param $text | ||
* @return mixed | ||
*/ | ||
public function income($amount, $text) | ||
{ | ||
$response = $this->post($this->baseUrl . '/submit/income',[ | ||
'token' => $this->token, | ||
'amount' => $amount, | ||
'text' => $text | ||
]); | ||
|
||
return json_decode($response, true); | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Bestoon; | ||
|
||
trait Request | ||
{ | ||
|
||
public function get($url) | ||
{ | ||
$ch = curl_init(); | ||
|
||
curl_setopt($ch,CURLOPT_URL,$url); | ||
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); | ||
|
||
$response = curl_exec($ch); | ||
|
||
curl_close($ch); | ||
|
||
return $response; | ||
} | ||
|
||
public function post($uri, array $options) | ||
{ | ||
$ch = curl_init($uri); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $options); | ||
|
||
$response = curl_exec($ch); | ||
|
||
curl_close($ch); | ||
|
||
return $response; | ||
} | ||
|
||
} |