Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjosh committed Feb 2, 2017
0 parents commit f99d8bf
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
index.php
8 changes: 8 additions & 0 deletions README.md
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
```
20 changes: 20 additions & 0 deletions composer.json
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"
}
87 changes: 87 additions & 0 deletions src/Client.php
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);
}

}
35 changes: 35 additions & 0 deletions src/Request.php
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;
}

}

0 comments on commit f99d8bf

Please sign in to comment.