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

Commit

Permalink
Added TelegramHelper file, removed 1 dependence.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasss93 committed Aug 12, 2017
1 parent 40052ec commit 277b901
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Framework for Telegram Bot API",
"license": "MIT",
"type": "project",
"version": "1.4.2",
"version": "1.4.3",
"authors": [
{
"name": "Luca Patera",
Expand All @@ -13,8 +13,7 @@
],
"require": {
"php": ">=5.6",
"netresearch/jsonmapper": ">=v1.1.0",
"lukasss93/aurax-php": ">=1.3.1"
"netresearch/jsonmapper": ">=v1.1.0"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 1 addition & 16 deletions src/TelegramBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace TelegramBot;

use AuraX\Tools;
use Exception;
use JsonMapper;
use TelegramBot\Types\Chat;
Expand Down Expand Up @@ -1295,7 +1294,7 @@ private function endpoint($api, array $content, $isPost = true)
throw new TelegramException("CURL request failed.\n" + $error);
}

if (!Tools::isJSON($body)) {
if (!is_json($body)) {
throw new TelegramException('The response cannot be parsed to json.');
}

Expand Down Expand Up @@ -1367,18 +1366,4 @@ private function encodeFile($file)
}

//endregion
}

/** Helper for Uploading file using CURL */
if (!function_exists('curl_file_create')) {
function curl_file_create($filename, $mimetype = '', $postname = '')
{
return "@$filename;filename=" . ($postname ?: basename($filename)) . ($mimetype ? ";type=$mimetype" : '');
}
}

/** Helper for Uploading file using CURL with auto mime */
function curl_file_create_auto_mime($filename, $postname = '')
{
return curl_file_create($filename, '', $postname);
}
28 changes: 28 additions & 0 deletions src/TelegramHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/** Helper for Uploading file using CURL */
if (!function_exists('curl_file_create')) {
function curl_file_create($filename, $mimetype = '', $postname = '')
{
return "@$filename;filename=" . ($postname ?: basename($filename)) . ($mimetype ? ";type=$mimetype" : '');
}
}

/** Helper for Uploading file using CURL with auto mime
* @param string $path Full path file
* @param string $postname
* @return string
*/
function curl_file_create_auto_mime($path, $postname = '')
{
return curl_file_create($path, '', $postname);
}

/** Check if a string is a json
* @param string $string
* @return bool
*/
function is_json($string)
{
return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE) ? true : false;
}

0 comments on commit 277b901

Please sign in to comment.