├── .gitignore
├── .travis.yml
├── README.md
├── composer.json
├── composer.lock
├── forwarderBot.php
├── info.txt
├── isIt.txt
└── vendor
├── .DS_Store
├── autoload.php
├── composer
├── ClassLoader.php
├── LICENSE
├── autoload_classmap.php
├── autoload_namespaces.php
├── autoload_psr4.php
├── autoload_real.php
├── autoload_static.php
└── installed.json
└── mashape
├── .DS_Store
└── unirest-php
├── .editorconfig
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── composer.json
├── phpunit.xml
├── src
├── Unirest.php
└── Unirest
│ ├── Exception.php
│ ├── Method.php
│ ├── Request.php
│ ├── Request
│ └── Body.php
│ └── Response.php
└── tests
├── Unirest
├── BodyTest.php
├── RequestTest.php
└── ResponseTest.php
├── bootstrap.php
└── fixtures
└── upload.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | # folders and files to be ignored by git
2 |
3 | ############
4 | ## OSes
5 | ############
6 |
7 | [Tt]humbs.db
8 | [Dd]esktop.ini
9 | *.DS_store
10 | .DS_store?
11 |
12 | ############
13 | ## Misc
14 | ############
15 |
16 | bin/
17 | tmp/
18 | *.tmp
19 | *.bak
20 | *.log
21 | *.[Cc]ache
22 | *.cpr
23 | *.orig
24 | *.php.in
25 | .idea/
26 | temp/
27 | ._*
28 | .Trashes
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 7.1
5 | - 7.2
6 |
7 | script:
8 | - composer update
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simple Forwarder Telegram Bot
2 | [](https://travis-ci.org/Masoud/Simple-Forwarder-Telegram-Bot)
3 |
4 | This Telegram Bot can send any message you want to your own User ID.
5 |
6 | Also It includes inline-keyboard-button and saves their data and it sends it to Admin User ID
7 |
8 | # Installation
9 | To have latest updates with ease, use this command on terminal to get a clone:
10 |
11 | ```bash
12 | git clone https://github.com/Masoud/Simple-Forwarder-Telegram-Bot
13 | ```
14 | #### After Clone
15 | 1- First you need to create a bot with [botFather](https://telegram.me/BotFather) and remember your Token.
16 |
17 | 2- Then, replace your Token in the forwarderBot.php file.
18 |
19 | 3- Obtain your admin ID (intended to send users messages) via the [@get_id_bot](https://telegram.me/get_id_bot) and replace it in the forwarderBot.php.
20 |
21 | 4- Enable your Webhook. (How to enable [Webhook?](https://core.telegram.org/bots/api#setwebhook))
22 |
23 | 5- You can now use your bot.
24 |
25 | # Usage
26 | Just read inline help to find what each function does.
27 |
28 | ```php
29 | sendToTelegram($text); // Send any text to your bot
30 |
31 | // Sample
32 | $adminChatID = 'xxxx';
33 | $current= 'Some Text';
34 | $textToAdmin = [
35 | 'chat_id' => $adminChatID,
36 | 'text' => $current,
37 | 'parse_mode' => 'html',
38 | ];
39 | sendToTelegram($textToAdmin);
40 | ```
41 | ```php
42 | messageToUser($user_id, $month); // Send any message to any user
43 |
44 | // Sample
45 | $UserId = $json['callback_query']['from']['id'];
46 | $month = "1 Month";
47 | messageToUser($UserId, $month);
48 | ```
49 | ```php
50 | saveData($user_id, $user_name, $month); // Save user's information
51 | usernamePassword(); // Save username and password "specific on this project"
52 | ```
53 | # License
54 | > MIT
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "masoud/macneed-telegram-bot",
3 | "description": "Macneed Telegram Bot",
4 | "type": "project",
5 | "homepage": "https://github.com/Masoud/Macneed-Telegram-Bot",
6 | "license": "MIT",
7 | "minimum-stability": "stable",
8 | "authors": [
9 | {
10 | "name": "Masoud",
11 | "email": "masoudnikoomanesh@gmail.com"
12 | }
13 | ],
14 | "require": {
15 | "mashape/unirest-php": "^3.0"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "00641d23035a7f90617039faccff5bdd",
8 | "packages": [
9 | {
10 | "name": "imangazaliev/didom",
11 | "version": "1.10.2",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/Imangazaliev/DiDOM.git",
15 | "reference": "a00fe0216da520275bfa2137e98d39882044d3fb"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/a00fe0216da520275bfa2137e98d39882044d3fb",
20 | "reference": "a00fe0216da520275bfa2137e98d39882044d3fb",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": ">=5.4"
25 | },
26 | "require-dev": {
27 | "phpunit/phpunit": "^4.8"
28 | },
29 | "type": "library",
30 | "autoload": {
31 | "psr-4": {
32 | "DiDom\\": "src/DiDom/"
33 | }
34 | },
35 | "notification-url": "https://packagist.org/downloads/",
36 | "license": [
37 | "MIT"
38 | ],
39 | "authors": [
40 | {
41 | "name": "Imangazaliev Muhammad",
42 | "email": "imangazalievm@gmail.com"
43 | }
44 | ],
45 | "description": "Simple and fast HTML parser",
46 | "homepage": "https://github.com/Imangazaliev/DiDOM",
47 | "keywords": [
48 | "didom",
49 | "html",
50 | "parser",
51 | "xml"
52 | ],
53 | "time": "2017-05-15T11:17:07+00:00"
54 | },
55 | {
56 | "name": "mashape/unirest-php",
57 | "version": "v3.0.4",
58 | "source": {
59 | "type": "git",
60 | "url": "https://github.com/Mashape/unirest-php.git",
61 | "reference": "842c0f242dfaaf85f16b72e217bf7f7c19ab12cb"
62 | },
63 | "dist": {
64 | "type": "zip",
65 | "url": "https://api.github.com/repos/Mashape/unirest-php/zipball/842c0f242dfaaf85f16b72e217bf7f7c19ab12cb",
66 | "reference": "842c0f242dfaaf85f16b72e217bf7f7c19ab12cb",
67 | "shasum": ""
68 | },
69 | "require": {
70 | "ext-curl": "*",
71 | "php": ">=5.4.0"
72 | },
73 | "require-dev": {
74 | "codeclimate/php-test-reporter": "0.1.*",
75 | "phpunit/phpunit": "~4.4"
76 | },
77 | "suggest": {
78 | "ext-json": "Allows using JSON Bodies for sending and parsing requests"
79 | },
80 | "type": "library",
81 | "autoload": {
82 | "psr-0": {
83 | "Unirest\\": "src/"
84 | }
85 | },
86 | "notification-url": "https://packagist.org/downloads/",
87 | "license": [
88 | "MIT"
89 | ],
90 | "description": "Unirest PHP",
91 | "homepage": "https://github.com/Mashape/unirest-php",
92 | "keywords": [
93 | "client",
94 | "curl",
95 | "http",
96 | "https",
97 | "rest"
98 | ],
99 | "time": "2016-08-11T17:49:21+00:00"
100 | }
101 | ],
102 | "packages-dev": [],
103 | "aliases": [],
104 | "minimum-stability": "stable",
105 | "stability-flags": [],
106 | "prefer-stable": false,
107 | "prefer-lowest": false,
108 | "platform": [],
109 | "platform-dev": []
110 | }
111 |
--------------------------------------------------------------------------------
/forwarderBot.php:
--------------------------------------------------------------------------------
1 | 'application/json'];
14 |
15 | // Get Data
16 | $id = $json['message']['from']['id'];
17 | $username = $json['message']['from']['username'];
18 | $text = $json['message']['text'];
19 | $MID = $json['message']['message_id'];
20 | $callback = $json['callback_query']['data'];
21 |
22 | // Your Bot Token
23 | $botToken = '625923840:AAG0wtKxxxxxU4VC9I_hQsleCcM';
24 |
25 | function sendToTelegram($text)
26 | {
27 | Unirest\Request::post('https://api.telegram.org/bot' . $GLOBALS['botToken'] . '/sendMessage', $GLOBALS['headers'], $text);
28 | }
29 |
30 | function messageToUser($user_id, $month)
31 | {
32 | $text2 = [
33 | 'chat_id' => $user_id,
34 | 'text' => "شما «خرید ویپیان " . $month . "» را انتخاب کردهاید.",
35 | 'parse_mode' => 'html',
36 | ];
37 | sendToTelegram($text2);
38 | $message = '
39 | برای انتخاب نام کاربری دلخواه بر روی متن زیر کلیک کنید:
40 | /Username
41 | ';
42 | $SendUserName = [
43 | 'chat_id' => $user_id,
44 | 'text' => $message,
45 | 'parse_mode' => 'html',
46 | ];
47 | sendToTelegram($SendUserName);
48 | }
49 |
50 | function messageToUserForPlan($user_id)
51 | {
52 | $message = "- یک ماهه: ۲۰.۰۰۰ تومان
53 |
54 | - سه ماهه: ۵۰.۰۰۰ تومان
55 |
56 | - شش ماهه: ۸۰.۰۰۰ تومان
57 |
58 | - یک ساله: ۱۳۰.۰۰۰ تومان";
59 | $text = [
60 | 'chat_id' => $user_id,
61 | 'text' => $message,
62 | 'parse_mode' => 'html',
63 | ];
64 | sendToTelegram($text);
65 | }
66 |
67 | function saveData($user_id, $user_name, $month)
68 | {
69 | $current = file_get_contents("info.txt");
70 | $message = "
71 | 🆔: " . $user_id . "
72 |
73 | 👤 با یوزرنیم: @" . $user_name . "
74 | 🔒 ویپیان: " . $month . "
75 | ";
76 | $current = file_get_contents("info.txt");
77 | $data_to_write .= $current . " " . $message . "\n";
78 | file_put_contents('info.txt', $data_to_write);
79 | }
80 |
81 | function usernamePassword()
82 | {
83 | $current = file_get_contents("info.txt");
84 | $adminChatID = 'xxxx';
85 | $textToAdmin = [
86 | 'chat_id' => $adminChatID,
87 | 'text' => $current,
88 | 'parse_mode' => 'html',
89 | ];
90 | sendToTelegram($textToAdmin);
91 | $info = fopen("info.txt", "w");
92 | fwrite($info, null);
93 | fclose($info);
94 | }
95 |
96 | // Start
97 | if ($text == '/start') {
98 | $text = [
99 | 'chat_id' => $id,
100 | 'text' => 'قصد خرید کدام پلن را دارید؟',
101 | 'parse_mode' => 'html',
102 | 'reply_markup' => json_encode([
103 | 'inline_keyboard' => [
104 | [
105 | [
106 | 'text' => 'ویپیان ۱ ماهه',
107 | 'callback_data' => 1
108 | ],
109 | [
110 | 'text' => 'ویپیان ۳ ماهه',
111 | 'callback_data' => 3
112 | ],
113 | ], [
114 | [
115 | 'text' => 'ویپیان ۶ ماهه',
116 | 'callback_data' => 6
117 | ],
118 | [
119 | 'text' => 'ویپیان ۱۲ ماهه',
120 | 'callback_data' => 12
121 | ]
122 | ],
123 | [
124 | [
125 | 'text' => 'اطلاع از قیمتها',
126 | 'callback_data' => 13
127 | ],
128 | ]
129 | ]
130 | ])
131 | ];
132 | sendToTelegram($text);
133 | } else if ($text == '/Username') { // Get Username
134 | $myfile = fopen("isIt.txt", "w");
135 | $nextNumber = 1;
136 | fwrite($myfile, $nextNumber);
137 | fclose($myfile);
138 | $sendUser = [
139 | 'chat_id' => $id,
140 | 'text' => 'یوزرنیم خودتون رو انتخاب کنید',
141 | 'parse_mode' => 'html',
142 | ];
143 | sendToTelegram($sendUser);
144 | } else if ($text == '/Password') { // Get Password
145 | $myfile = fopen("isIt.txt", "w");
146 | $nextNumber = 2;
147 | fwrite($myfile, $nextNumber);
148 | fclose($myfile);
149 | $sendUser = [
150 | 'chat_id' => $id,
151 | 'text' => 'پسورد خودتون رو انتخاب کنید',
152 | 'parse_mode' => 'html',
153 | ];
154 | sendToTelegram($sendUser);
155 | } else {
156 | $file = 'isIt.txt';
157 | $f = fopen($file, 'r');
158 | $number = fgets($f);
159 | $number = (int)$number;
160 | if ($number == 1) {
161 | $username = $text;
162 | $current = file_get_contents("info.txt");
163 | $data_to_write .=
164 | $current . "
165 | 〽️ یوزرنیم: " . $username . "";
166 | file_put_contents('info.txt', $data_to_write);
167 |
168 | $submitUsername = "
169 | نام کاربری شما با عنوان " . $text . " ثبت شد.
170 | ";
171 | $textToSubMit = [
172 | 'chat_id' => $id,
173 | 'text' => $submitUsername,
174 | 'parse_mode' => 'html',
175 | ];
176 | sendToTelegram($textToSubMit);
177 | $message = '
178 | برای انتخاب پسورد دلخواه بر روی متن زیر کلیک کنید:
179 | /Password
180 | ';
181 | $SendUserName = [
182 | 'chat_id' => $id,
183 | 'text' => $message,
184 | 'parse_mode' => 'html',
185 | ];
186 | sendToTelegram($SendUserName);
187 | } else if ($number == 2) {
188 | $password = $text;
189 | $current = file_get_contents("info.txt");
190 | $data_to_write .=
191 | $current . "
192 | 🔱 پسورد: " . $password . "
193 | ";
194 | file_put_contents('info.txt', $data_to_write);
195 | $submitPassword = "
196 | پسورد شما با عنوان " . $text . " ثبت شد.
197 | ";
198 | $textToSubMit = [
199 | 'chat_id' => $id,
200 | 'text' => $submitPassword,
201 | 'parse_mode' => 'html',
202 | ];
203 | sendToTelegram($textToSubMit);
204 | $ThanksText = [
205 | 'chat_id' => $id,
206 | 'text' => "با تشکر از ارتباط شما، به زودی با شما در تماس خواهیم بود. 🙏",
207 | 'parse_mode' => 'html',
208 | ];
209 | sendToTelegram($ThanksText);
210 |
211 | // Send Data for Admin
212 | usernamePassword();
213 | }
214 | fclose($f);
215 | $myfile = fopen("isIt.txt", "w");
216 | $nextNumber = 0;
217 | fwrite($myfile, $nextNumber);
218 | fclose($myfile);
219 | }
220 |
221 | if (isset($callback)) {
222 | $UserId = $json['callback_query']['from']['id'];
223 | $UserName = $json['callback_query']['from']['username'];
224 | if ($callback == '1') {
225 | $month = "۱ ماهه";
226 | messageToUser($UserId, $month);
227 | saveData($UserId, $UserName, $month);
228 | } else if ($callback == '3') {
229 | $month = "۳ ماهه";
230 | messageToUser($UserId, $month);
231 | saveData($UserId, $UserName, $month);
232 | } else if ($callback == '6') {
233 | $month = "۶ ماهه";
234 | messageToUser($UserId, $month);
235 | saveData($UserId, $UserName, $month);
236 | } else if ($callback == '12') {
237 | $month = "۱۲ ماهه";
238 | messageToUser($UserId, $month);
239 | saveData($UserId, $UserName, $month);
240 | } else if ($callback == '13') {
241 | messageToUserForPlan($UserId);
242 | }
243 | }
--------------------------------------------------------------------------------
/info.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Masoud/Simple-Forwarder-Telegram-Bot/19fd1280885bf0e6a142365e9c18c5c3f4cdee1a/info.txt
--------------------------------------------------------------------------------
/isIt.txt:
--------------------------------------------------------------------------------
1 | 1
--------------------------------------------------------------------------------
/vendor/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Masoud/Simple-Forwarder-Telegram-Bot/19fd1280885bf0e6a142365e9c18c5c3f4cdee1a/vendor/.DS_Store
--------------------------------------------------------------------------------
/vendor/autoload.php:
--------------------------------------------------------------------------------
1 |
7 | * Jordi Boggiano
8 | *
9 | * For the full copyright and license information, please view the LICENSE
10 | * file that was distributed with this source code.
11 | */
12 |
13 | namespace Composer\Autoload;
14 |
15 | /**
16 | * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
17 | *
18 | * $loader = new \Composer\Autoload\ClassLoader();
19 | *
20 | * // register classes with namespaces
21 | * $loader->add('Symfony\Component', __DIR__.'/component');
22 | * $loader->add('Symfony', __DIR__.'/framework');
23 | *
24 | * // activate the autoloader
25 | * $loader->register();
26 | *
27 | * // to enable searching the include path (eg. for PEAR packages)
28 | * $loader->setUseIncludePath(true);
29 | *
30 | * In this example, if you try to use a class in the Symfony\Component
31 | * namespace or one of its children (Symfony\Component\Console for instance),
32 | * the autoloader will first look for the class under the component/
33 | * directory, and it will then fallback to the framework/ directory if not
34 | * found before giving up.
35 | *
36 | * This class is loosely based on the Symfony UniversalClassLoader.
37 | *
38 | * @author Fabien Potencier
39 | * @author Jordi Boggiano
40 | * @see http://www.php-fig.org/psr/psr-0/
41 | * @see http://www.php-fig.org/psr/psr-4/
42 | */
43 | class ClassLoader
44 | {
45 | // PSR-4
46 | private $prefixLengthsPsr4 = array();
47 | private $prefixDirsPsr4 = array();
48 | private $fallbackDirsPsr4 = array();
49 |
50 | // PSR-0
51 | private $prefixesPsr0 = array();
52 | private $fallbackDirsPsr0 = array();
53 |
54 | private $useIncludePath = false;
55 | private $classMap = array();
56 | private $classMapAuthoritative = false;
57 | private $missingClasses = array();
58 | private $apcuPrefix;
59 |
60 | public function getPrefixes()
61 | {
62 | if (!empty($this->prefixesPsr0)) {
63 | return call_user_func_array('array_merge', $this->prefixesPsr0);
64 | }
65 |
66 | return array();
67 | }
68 |
69 | public function getPrefixesPsr4()
70 | {
71 | return $this->prefixDirsPsr4;
72 | }
73 |
74 | public function getFallbackDirs()
75 | {
76 | return $this->fallbackDirsPsr0;
77 | }
78 |
79 | public function getFallbackDirsPsr4()
80 | {
81 | return $this->fallbackDirsPsr4;
82 | }
83 |
84 | public function getClassMap()
85 | {
86 | return $this->classMap;
87 | }
88 |
89 | /**
90 | * @param array $classMap Class to filename map
91 | */
92 | public function addClassMap(array $classMap)
93 | {
94 | if ($this->classMap) {
95 | $this->classMap = array_merge($this->classMap, $classMap);
96 | } else {
97 | $this->classMap = $classMap;
98 | }
99 | }
100 |
101 | /**
102 | * Registers a set of PSR-0 directories for a given prefix, either
103 | * appending or prepending to the ones previously set for this prefix.
104 | *
105 | * @param string $prefix The prefix
106 | * @param array|string $paths The PSR-0 root directories
107 | * @param bool $prepend Whether to prepend the directories
108 | */
109 | public function add($prefix, $paths, $prepend = false)
110 | {
111 | if (!$prefix) {
112 | if ($prepend) {
113 | $this->fallbackDirsPsr0 = array_merge(
114 | (array) $paths,
115 | $this->fallbackDirsPsr0
116 | );
117 | } else {
118 | $this->fallbackDirsPsr0 = array_merge(
119 | $this->fallbackDirsPsr0,
120 | (array) $paths
121 | );
122 | }
123 |
124 | return;
125 | }
126 |
127 | $first = $prefix[0];
128 | if (!isset($this->prefixesPsr0[$first][$prefix])) {
129 | $this->prefixesPsr0[$first][$prefix] = (array) $paths;
130 |
131 | return;
132 | }
133 | if ($prepend) {
134 | $this->prefixesPsr0[$first][$prefix] = array_merge(
135 | (array) $paths,
136 | $this->prefixesPsr0[$first][$prefix]
137 | );
138 | } else {
139 | $this->prefixesPsr0[$first][$prefix] = array_merge(
140 | $this->prefixesPsr0[$first][$prefix],
141 | (array) $paths
142 | );
143 | }
144 | }
145 |
146 | /**
147 | * Registers a set of PSR-4 directories for a given namespace, either
148 | * appending or prepending to the ones previously set for this namespace.
149 | *
150 | * @param string $prefix The prefix/namespace, with trailing '\\'
151 | * @param array|string $paths The PSR-4 base directories
152 | * @param bool $prepend Whether to prepend the directories
153 | *
154 | * @throws \InvalidArgumentException
155 | */
156 | public function addPsr4($prefix, $paths, $prepend = false)
157 | {
158 | if (!$prefix) {
159 | // Register directories for the root namespace.
160 | if ($prepend) {
161 | $this->fallbackDirsPsr4 = array_merge(
162 | (array) $paths,
163 | $this->fallbackDirsPsr4
164 | );
165 | } else {
166 | $this->fallbackDirsPsr4 = array_merge(
167 | $this->fallbackDirsPsr4,
168 | (array) $paths
169 | );
170 | }
171 | } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172 | // Register directories for a new namespace.
173 | $length = strlen($prefix);
174 | if ('\\' !== $prefix[$length - 1]) {
175 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176 | }
177 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
178 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
179 | } elseif ($prepend) {
180 | // Prepend directories for an already registered namespace.
181 | $this->prefixDirsPsr4[$prefix] = array_merge(
182 | (array) $paths,
183 | $this->prefixDirsPsr4[$prefix]
184 | );
185 | } else {
186 | // Append directories for an already registered namespace.
187 | $this->prefixDirsPsr4[$prefix] = array_merge(
188 | $this->prefixDirsPsr4[$prefix],
189 | (array) $paths
190 | );
191 | }
192 | }
193 |
194 | /**
195 | * Registers a set of PSR-0 directories for a given prefix,
196 | * replacing any others previously set for this prefix.
197 | *
198 | * @param string $prefix The prefix
199 | * @param array|string $paths The PSR-0 base directories
200 | */
201 | public function set($prefix, $paths)
202 | {
203 | if (!$prefix) {
204 | $this->fallbackDirsPsr0 = (array) $paths;
205 | } else {
206 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
207 | }
208 | }
209 |
210 | /**
211 | * Registers a set of PSR-4 directories for a given namespace,
212 | * replacing any others previously set for this namespace.
213 | *
214 | * @param string $prefix The prefix/namespace, with trailing '\\'
215 | * @param array|string $paths The PSR-4 base directories
216 | *
217 | * @throws \InvalidArgumentException
218 | */
219 | public function setPsr4($prefix, $paths)
220 | {
221 | if (!$prefix) {
222 | $this->fallbackDirsPsr4 = (array) $paths;
223 | } else {
224 | $length = strlen($prefix);
225 | if ('\\' !== $prefix[$length - 1]) {
226 | throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227 | }
228 | $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
229 | $this->prefixDirsPsr4[$prefix] = (array) $paths;
230 | }
231 | }
232 |
233 | /**
234 | * Turns on searching the include path for class files.
235 | *
236 | * @param bool $useIncludePath
237 | */
238 | public function setUseIncludePath($useIncludePath)
239 | {
240 | $this->useIncludePath = $useIncludePath;
241 | }
242 |
243 | /**
244 | * Can be used to check if the autoloader uses the include path to check
245 | * for classes.
246 | *
247 | * @return bool
248 | */
249 | public function getUseIncludePath()
250 | {
251 | return $this->useIncludePath;
252 | }
253 |
254 | /**
255 | * Turns off searching the prefix and fallback directories for classes
256 | * that have not been registered with the class map.
257 | *
258 | * @param bool $classMapAuthoritative
259 | */
260 | public function setClassMapAuthoritative($classMapAuthoritative)
261 | {
262 | $this->classMapAuthoritative = $classMapAuthoritative;
263 | }
264 |
265 | /**
266 | * Should class lookup fail if not found in the current class map?
267 | *
268 | * @return bool
269 | */
270 | public function isClassMapAuthoritative()
271 | {
272 | return $this->classMapAuthoritative;
273 | }
274 |
275 | /**
276 | * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
277 | *
278 | * @param string|null $apcuPrefix
279 | */
280 | public function setApcuPrefix($apcuPrefix)
281 | {
282 | $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
283 | }
284 |
285 | /**
286 | * The APCu prefix in use, or null if APCu caching is not enabled.
287 | *
288 | * @return string|null
289 | */
290 | public function getApcuPrefix()
291 | {
292 | return $this->apcuPrefix;
293 | }
294 |
295 | /**
296 | * Registers this instance as an autoloader.
297 | *
298 | * @param bool $prepend Whether to prepend the autoloader or not
299 | */
300 | public function register($prepend = false)
301 | {
302 | spl_autoload_register(array($this, 'loadClass'), true, $prepend);
303 | }
304 |
305 | /**
306 | * Unregisters this instance as an autoloader.
307 | */
308 | public function unregister()
309 | {
310 | spl_autoload_unregister(array($this, 'loadClass'));
311 | }
312 |
313 | /**
314 | * Loads the given class or interface.
315 | *
316 | * @param string $class The name of the class
317 | * @return bool|null True if loaded, null otherwise
318 | */
319 | public function loadClass($class)
320 | {
321 | if ($file = $this->findFile($class)) {
322 | includeFile($file);
323 |
324 | return true;
325 | }
326 | }
327 |
328 | /**
329 | * Finds the path to the file where the class is defined.
330 | *
331 | * @param string $class The name of the class
332 | *
333 | * @return string|false The path if found, false otherwise
334 | */
335 | public function findFile($class)
336 | {
337 | // class map lookup
338 | if (isset($this->classMap[$class])) {
339 | return $this->classMap[$class];
340 | }
341 | if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
342 | return false;
343 | }
344 | if (null !== $this->apcuPrefix) {
345 | $file = apcu_fetch($this->apcuPrefix.$class, $hit);
346 | if ($hit) {
347 | return $file;
348 | }
349 | }
350 |
351 | $file = $this->findFileWithExtension($class, '.php');
352 |
353 | // Search for Hack files if we are running on HHVM
354 | if (false === $file && defined('HHVM_VERSION')) {
355 | $file = $this->findFileWithExtension($class, '.hh');
356 | }
357 |
358 | if (null !== $this->apcuPrefix) {
359 | apcu_add($this->apcuPrefix.$class, $file);
360 | }
361 |
362 | if (false === $file) {
363 | // Remember that this class does not exist.
364 | $this->missingClasses[$class] = true;
365 | }
366 |
367 | return $file;
368 | }
369 |
370 | private function findFileWithExtension($class, $ext)
371 | {
372 | // PSR-4 lookup
373 | $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374 |
375 | $first = $class[0];
376 | if (isset($this->prefixLengthsPsr4[$first])) {
377 | $subPath = $class;
378 | while (false !== $lastPos = strrpos($subPath, '\\')) {
379 | $subPath = substr($subPath, 0, $lastPos);
380 | $search = $subPath.'\\';
381 | if (isset($this->prefixDirsPsr4[$search])) {
382 | foreach ($this->prefixDirsPsr4[$search] as $dir) {
383 | $length = $this->prefixLengthsPsr4[$first][$search];
384 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
385 | return $file;
386 | }
387 | }
388 | }
389 | }
390 | }
391 |
392 | // PSR-4 fallback dirs
393 | foreach ($this->fallbackDirsPsr4 as $dir) {
394 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
395 | return $file;
396 | }
397 | }
398 |
399 | // PSR-0 lookup
400 | if (false !== $pos = strrpos($class, '\\')) {
401 | // namespaced class name
402 | $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
404 | } else {
405 | // PEAR-like class name
406 | $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
407 | }
408 |
409 | if (isset($this->prefixesPsr0[$first])) {
410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
411 | if (0 === strpos($class, $prefix)) {
412 | foreach ($dirs as $dir) {
413 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
414 | return $file;
415 | }
416 | }
417 | }
418 | }
419 | }
420 |
421 | // PSR-0 fallback dirs
422 | foreach ($this->fallbackDirsPsr0 as $dir) {
423 | if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
424 | return $file;
425 | }
426 | }
427 |
428 | // PSR-0 include paths.
429 | if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
430 | return $file;
431 | }
432 |
433 | return false;
434 | }
435 | }
436 |
437 | /**
438 | * Scope isolated include.
439 | *
440 | * Prevents access to $this/self from included files.
441 | */
442 | function includeFile($file)
443 | {
444 | include $file;
445 | }
446 |
--------------------------------------------------------------------------------
/vendor/composer/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) Nils Adermann, Jordi Boggiano
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is furnished
9 | to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | THE SOFTWARE.
21 |
22 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_classmap.php:
--------------------------------------------------------------------------------
1 | array($vendorDir . '/mashape/unirest-php/src'),
10 | );
11 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_psr4.php:
--------------------------------------------------------------------------------
1 | array($vendorDir . '/imangazaliev/didom/src/DiDom'),
10 | );
11 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_real.php:
--------------------------------------------------------------------------------
1 | = 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27 | if ($useStaticLoader) {
28 | require_once __DIR__ . '/autoload_static.php';
29 |
30 | call_user_func(\Composer\Autoload\ComposerStaticInit15163c3fc63a6a3c923e6291ef6d1c60::getInitializer($loader));
31 | } else {
32 | $map = require __DIR__ . '/autoload_namespaces.php';
33 | foreach ($map as $namespace => $path) {
34 | $loader->set($namespace, $path);
35 | }
36 |
37 | $map = require __DIR__ . '/autoload_psr4.php';
38 | foreach ($map as $namespace => $path) {
39 | $loader->setPsr4($namespace, $path);
40 | }
41 |
42 | $classMap = require __DIR__ . '/autoload_classmap.php';
43 | if ($classMap) {
44 | $loader->addClassMap($classMap);
45 | }
46 | }
47 |
48 | $loader->register(true);
49 |
50 | return $loader;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vendor/composer/autoload_static.php:
--------------------------------------------------------------------------------
1 |
11 | array (
12 | 'DiDom\\' => 6,
13 | ),
14 | );
15 |
16 | public static $prefixDirsPsr4 = array (
17 | 'DiDom\\' =>
18 | array (
19 | 0 => __DIR__ . '/..' . '/imangazaliev/didom/src/DiDom',
20 | ),
21 | );
22 |
23 | public static $prefixesPsr0 = array (
24 | 'U' =>
25 | array (
26 | 'Unirest\\' =>
27 | array (
28 | 0 => __DIR__ . '/..' . '/mashape/unirest-php/src',
29 | ),
30 | ),
31 | );
32 |
33 | public static function getInitializer(ClassLoader $loader)
34 | {
35 | return \Closure::bind(function () use ($loader) {
36 | $loader->prefixLengthsPsr4 = ComposerStaticInit15163c3fc63a6a3c923e6291ef6d1c60::$prefixLengthsPsr4;
37 | $loader->prefixDirsPsr4 = ComposerStaticInit15163c3fc63a6a3c923e6291ef6d1c60::$prefixDirsPsr4;
38 | $loader->prefixesPsr0 = ComposerStaticInit15163c3fc63a6a3c923e6291ef6d1c60::$prefixesPsr0;
39 |
40 | }, null, ClassLoader::class);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/vendor/composer/installed.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "mashape/unirest-php",
4 | "version": "v3.0.4",
5 | "version_normalized": "3.0.4.0",
6 | "source": {
7 | "type": "git",
8 | "url": "https://github.com/Mashape/unirest-php.git",
9 | "reference": "842c0f242dfaaf85f16b72e217bf7f7c19ab12cb"
10 | },
11 | "dist": {
12 | "type": "zip",
13 | "url": "https://api.github.com/repos/Mashape/unirest-php/zipball/842c0f242dfaaf85f16b72e217bf7f7c19ab12cb",
14 | "reference": "842c0f242dfaaf85f16b72e217bf7f7c19ab12cb",
15 | "shasum": ""
16 | },
17 | "require": {
18 | "ext-curl": "*",
19 | "php": ">=5.4.0"
20 | },
21 | "require-dev": {
22 | "codeclimate/php-test-reporter": "0.1.*",
23 | "phpunit/phpunit": "~4.4"
24 | },
25 | "suggest": {
26 | "ext-json": "Allows using JSON Bodies for sending and parsing requests"
27 | },
28 | "time": "2016-08-11T17:49:21+00:00",
29 | "type": "library",
30 | "installation-source": "dist",
31 | "autoload": {
32 | "psr-0": {
33 | "Unirest\\": "src/"
34 | }
35 | },
36 | "notification-url": "https://packagist.org/downloads/",
37 | "license": [
38 | "MIT"
39 | ],
40 | "description": "Unirest PHP",
41 | "homepage": "https://github.com/Mashape/unirest-php",
42 | "keywords": [
43 | "client",
44 | "curl",
45 | "http",
46 | "https",
47 | "rest"
48 | ]
49 | },
50 | {
51 | "name": "imangazaliev/didom",
52 | "version": "1.10.2",
53 | "version_normalized": "1.10.2.0",
54 | "source": {
55 | "type": "git",
56 | "url": "https://github.com/Imangazaliev/DiDOM.git",
57 | "reference": "a00fe0216da520275bfa2137e98d39882044d3fb"
58 | },
59 | "dist": {
60 | "type": "zip",
61 | "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/a00fe0216da520275bfa2137e98d39882044d3fb",
62 | "reference": "a00fe0216da520275bfa2137e98d39882044d3fb",
63 | "shasum": ""
64 | },
65 | "require": {
66 | "php": ">=5.4"
67 | },
68 | "require-dev": {
69 | "phpunit/phpunit": "^4.8"
70 | },
71 | "time": "2017-05-15T11:17:07+00:00",
72 | "type": "library",
73 | "installation-source": "dist",
74 | "autoload": {
75 | "psr-4": {
76 | "DiDom\\": "src/DiDom/"
77 | }
78 | },
79 | "notification-url": "https://packagist.org/downloads/",
80 | "license": [
81 | "MIT"
82 | ],
83 | "authors": [
84 | {
85 | "name": "Imangazaliev Muhammad",
86 | "email": "imangazalievm@gmail.com"
87 | }
88 | ],
89 | "description": "Simple and fast HTML parser",
90 | "homepage": "https://github.com/Imangazaliev/DiDOM",
91 | "keywords": [
92 | "didom",
93 | "html",
94 | "parser",
95 | "xml"
96 | ]
97 | }
98 | ]
99 |
--------------------------------------------------------------------------------
/vendor/mashape/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Masoud/Simple-Forwarder-Telegram-Bot/19fd1280885bf0e6a142365e9c18c5c3f4cdee1a/vendor/mashape/.DS_Store
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/.editorconfig:
--------------------------------------------------------------------------------
1 | # http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 4
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
11 |
12 | [*.{json,xml,yml}]
13 | indent_size = 2
14 |
15 | [*.{md,yml}]
16 | trim_trailing_whitespace = false
17 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .idea
3 | build
4 | composer.lock
5 | composer.phar
6 | coverage
7 | vendor
8 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 |
3 | language: php
4 |
5 | php:
6 | - '5.4'
7 | - '5.5'
8 | - '5.6'
9 | - '7.0'
10 | - hhvm
11 |
12 | before_script:
13 | - composer selfupdate
14 | - composer install
15 |
16 | after_script:
17 | - vendor/bin/test-reporter --stdout > codeclimate.json
18 | - "curl -X POST -d @codeclimate.json -H 'Content-Type: application/json' -H 'User-Agent: Code Climate (PHP Test Reporter v0.1.1)' https://codeclimate.com/test_reports"
19 |
20 | notifications:
21 | webhooks:
22 | urls:
23 | - https://webhooks.gitter.im/e/802f417bb6e3e1e8b20d
24 | on_success: always
25 | on_failure: always
26 | on_start: false
27 |
28 | matrix:
29 | fast_finish: true
30 | allow_failures:
31 | - php: hhvm
32 |
33 | notifications:
34 | webhooks:
35 | urls:
36 | - https://webhooks.gitter.im/e/d4319553d0aecfd5b9ac
37 | on_success: always
38 | on_failure: always
39 | on_start: false
40 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2013-2015 Mashape (https://www.mashape.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/README.md:
--------------------------------------------------------------------------------
1 | # Unirest for PHP [![Build Status][travis-image]][travis-url] [![version][packagist-version]][packagist-url]
2 |
3 | [![Downloads][packagist-downloads]][packagist-url]
4 | [![Code Climate][codeclimate-quality]][codeclimate-url]
5 | [![Coverage Status][codeclimate-coverage]][codeclimate-url]
6 | [![Dependencies][versioneye-image]][versioneye-url]
7 | [![Gitter][gitter-image]][gitter-url]
8 | [![License][packagist-license]][license-url]
9 |
10 | ![][unirest-logo]
11 |
12 |
13 | [Unirest](http://unirest.io) is a set of lightweight HTTP libraries available in multiple languages, built and maintained by [Mashape](https://github.com/Mashape), who also maintain the open-source API Gateway [Kong](https://github.com/Mashape/kong).
14 |
15 |
16 | ## Features
17 |
18 | * Utility methods to call `GET`, `HEAD`, `POST`, `PUT`, `DELETE`, `CONNECT`, `OPTIONS`, `TRACE`, `PATCH` requests
19 | * Supports form parameters, file uploads and custom body entities
20 | * Supports gzip
21 | * Supports Basic, Digest, Negotiate, NTLM Authentication natively
22 | * Customizable timeout
23 | * Customizable default headers for every request (DRY)
24 | * Automatic JSON parsing into a native object for JSON responses
25 |
26 | ## Requirements
27 |
28 | - [cURL](http://php.net/manual/en/book.curl.php)
29 | - PHP 5.4+
30 |
31 | ## Installation
32 |
33 | ### Using [Composer](https://getcomposer.org)
34 |
35 | To install unirest-php with Composer, just add the following to your `composer.json` file:
36 |
37 | ```json
38 | {
39 | "require-dev": {
40 | "mashape/unirest-php": "3.*"
41 | }
42 | }
43 | ```
44 |
45 | or by running the following command:
46 |
47 | ```shell
48 | composer require mashape/unirest-php
49 | ```
50 |
51 | This will get you the latest version of the reporter and install it. If you do want the master, untagged, version you may use the command below:
52 |
53 | ```shell
54 | composer require mashape/php-test-reporter dev-master
55 | ```
56 |
57 | Composer installs autoloader at `./vendor/autoloader.php`. to include the library in your script, add:
58 |
59 | ```php
60 | require_once 'vendor/autoload.php';
61 | ```
62 |
63 | If you use Symfony2, autoloader has to be detected automatically.
64 |
65 | *You can see this library on [Packagist](https://packagist.org/packages/mashape/unirest-php).*
66 |
67 | ### Install from source
68 |
69 | Download the PHP library from Github, then include `Unirest.php` in your script:
70 |
71 | ```shell
72 | git clone git@github.com:Mashape/unirest-php.git
73 | ```
74 |
75 | ```php
76 | require_once '/path/to/unirest-php/src/Unirest.php';
77 | ```
78 |
79 | ## Usage
80 |
81 | ### Creating a Request
82 |
83 | So you're probably wondering how using Unirest makes creating requests in PHP easier, let's look at a working example:
84 |
85 | ```php
86 | $headers = array('Accept' => 'application/json');
87 | $query = array('foo' => 'hello', 'bar' => 'world');
88 |
89 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $query);
90 |
91 | $response->code; // HTTP Status code
92 | $response->headers; // Headers
93 | $response->body; // Parsed body
94 | $response->raw_body; // Unparsed body
95 | ```
96 |
97 | ### JSON Requests *(`application/json`)*
98 |
99 | A JSON Request can be constructed using the `Unirest\Request\Body::Json` helper:
100 |
101 | ```php
102 | $headers = array('Accept' => 'application/json');
103 | $data = array('name' => 'ahmad', 'company' => 'mashape');
104 |
105 | $body = Unirest\Request\Body::json($data);
106 |
107 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
108 | ```
109 |
110 | **Notes:**
111 | - `Content-Type` headers will be automatically set to `application/json`
112 | - the data variable will be processed through [`json_encode`](http://php.net/manual/en/function.json-encode.php) with default values for arguments.
113 | - an error will be thrown if the [JSON Extension](http://php.net/manual/en/book.json.php) is not available.
114 |
115 | ### Form Requests *(`application/x-www-form-urlencoded`)*
116 |
117 | A typical Form Request can be constructed using the `Unirest\Request\Body::Form` helper:
118 |
119 | ```php
120 | $headers = array('Accept' => 'application/json');
121 | $data = array('name' => 'ahmad', 'company' => 'mashape');
122 |
123 | $body = Unirest\Request\Body::form($data);
124 |
125 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
126 | ```
127 |
128 | **Notes:**
129 | - `Content-Type` headers will be automatically set to `application/x-www-form-urlencoded`
130 | - the final data array will be processed through [`http_build_query`](http://php.net/manual/en/function.http-build-query.php) with default values for arguments.
131 |
132 | ### Multipart Requests *(`multipart/form-data`)*
133 |
134 | A Multipart Request can be constructed using the `Unirest\Request\Body::Multipart` helper:
135 |
136 | ```php
137 | $headers = array('Accept' => 'application/json');
138 | $data = array('name' => 'ahmad', 'company' => 'mashape');
139 |
140 | $body = Unirest\Request\Body::multipart($data);
141 |
142 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
143 | ```
144 |
145 | **Notes:**
146 |
147 | - `Content-Type` headers will be automatically set to `multipart/form-data`.
148 | - an auto-generated `--boundary` will be set.
149 |
150 | ### Multipart File Upload
151 |
152 | simply add an array of files as the second argument to to the `Multipart` helper:
153 |
154 | ```php
155 | $headers = array('Accept' => 'application/json');
156 | $data = array('name' => 'ahmad', 'company' => 'mashape');
157 | $files = array('bio' => '/path/to/bio.txt', 'avatar' => '/path/to/avatar.jpg');
158 |
159 | $body = Unirest\Request\Body::multipart($data, $files);
160 |
161 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
162 | ```
163 |
164 | If you wish to further customize the properties of files uploaded you can do so with the `Unirest\Request\Body::File` helper:
165 |
166 | ```php
167 | $headers = array('Accept' => 'application/json');
168 | $body = array(
169 | 'name' => 'ahmad',
170 | 'company' => 'mashape'
171 | 'bio' => Unirest\Request\Body::file('/path/to/bio.txt', 'text/plain'),
172 | 'avatar' => Unirest\Request\Body::file('/path/to/my_avatar.jpg', 'text/plain', 'avatar.jpg')
173 | );
174 |
175 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
176 | ```
177 |
178 | **Note**: we did not use the `Unirest\Request\Body::multipart` helper in this example, it is not needed when manually adding files.
179 |
180 | ### Custom Body
181 |
182 | Sending a custom body such rather than using the `Unirest\Request\Body` helpers is also possible, for example, using a [`serialize`](http://php.net/manual/en/function.serialize.php) body string with a custom `Content-Type`:
183 |
184 | ```php
185 | $headers = array('Accept' => 'application/json', 'Content-Type' => 'application/x-php-serialized');
186 | $body = serialize((array('foo' => 'hello', 'bar' => 'world'));
187 |
188 | $response = Unirest\Request::post('http://mockbin.com/request', $headers, $body);
189 | ```
190 |
191 | ### Authentication
192 |
193 | First, if you are using [Mashape][mashape-url]:
194 | ```php
195 | // Mashape auth
196 | Unirest\Request::setMashapeKey('');
197 | ```
198 |
199 | Otherwise, passing a username, password *(optional)*, defaults to Basic Authentication:
200 |
201 | ```php
202 | // basic auth
203 | Unirest\Request::auth('username', 'password');
204 | ```
205 |
206 | The third parameter, which is a bitmask, will Unirest which HTTP authentication method(s) you want it to use for your proxy authentication.
207 |
208 | If more than one bit is set, Unirest *(at PHP's libcurl level)* will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. *For some methods, this will induce an extra network round-trip.*
209 |
210 | **Supported Methods**
211 |
212 | | Method | Description |
213 | | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
214 | | `CURLAUTH_BASIC` | HTTP Basic authentication. This is the default choice |
215 | | `CURLAUTH_DIGEST` | HTTP Digest authentication. as defined in [RFC 2617](http://www.ietf.org/rfc/rfc2617.txt) |
216 | | `CURLAUTH_DIGEST_IE` | HTTP Digest authentication with an IE flavor. *The IE flavor is simply that libcurl will use a special "quirk" that IE is known to have used before version 7 and that some servers require the client to use.* |
217 | | `CURLAUTH_NEGOTIATE` | HTTP Negotiate (SPNEGO) authentication. as defined in [RFC 4559](http://www.ietf.org/rfc/rfc4559.txt) |
218 | | `CURLAUTH_NTLM` | HTTP NTLM authentication. A proprietary protocol invented and used by Microsoft. |
219 | | `CURLAUTH_NTLM_WB` | NTLM delegating to winbind helper. Authentication is performed by a separate binary application. *see [libcurl docs](http://curl.haxx.se/libcurl/c/CURLOPT_HTTPAUTH.html) for more info* |
220 | | `CURLAUTH_ANY` | This is a convenience macro that sets all bits and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure. |
221 | | `CURLAUTH_ANYSAFE` | This is a convenience macro that sets all bits except Basic and thus makes libcurl pick any it finds suitable. libcurl will automatically select the one it finds most secure. |
222 | | `CURLAUTH_ONLY` | This is a meta symbol. OR this value together with a single specific auth value to force libcurl to probe for un-restricted auth and if not, only that single auth algorithm is acceptable. |
223 |
224 | ```php
225 | // custom auth method
226 | Unirest\Request::proxyAuth('username', 'password', CURLAUTH_DIGEST);
227 | ```
228 |
229 | Previous versions of **Unirest** support *Basic Authentication* by providing the `username` and `password` arguments:
230 |
231 | ```php
232 | $response = Unirest\Request::get('http://mockbin.com/request', null, null, 'username', 'password');
233 | ```
234 |
235 | **This has been deprecated, and will be completely removed in `v.3.0.0` please use the `Unirest\Request::auth()` method instead**
236 |
237 | ### Cookies
238 |
239 | Set a cookie string to specify the contents of a cookie header. Multiple cookies are separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")
240 |
241 | ```php
242 | Unirest\Request::cookie($cookie)
243 | ```
244 |
245 | Set a cookie file path for enabling cookie reading and storing cookies across multiple sequence of requests.
246 |
247 | ```php
248 | Unirest\Request::cookieFile($cookieFile)
249 | ```
250 |
251 | `$cookieFile` must be a correct path with write permission.
252 |
253 | ### Request Object
254 |
255 | ```php
256 | Unirest\Request::get($url, $headers = array(), $parameters = null)
257 | Unirest\Request::post($url, $headers = array(), $body = null)
258 | Unirest\Request::put($url, $headers = array(), $body = null)
259 | Unirest\Request::patch($url, $headers = array(), $body = null)
260 | Unirest\Request::delete($url, $headers = array(), $body = null)
261 | ```
262 |
263 | - `url` - Endpoint, address, or uri to be acted upon and requested information from.
264 | - `headers` - Request Headers as associative array or object
265 | - `body` - Request Body as associative array or object
266 |
267 | You can send a request with any [standard](http://www.iana.org/assignments/http-methods/http-methods.xhtml) or custom HTTP Method:
268 |
269 | ```php
270 | Unirest\Request::send(Unirest\Method::LINK, $url, $headers = array(), $body);
271 |
272 | Unirest\Request::send('CHECKOUT', $url, $headers = array(), $body);
273 | ```
274 |
275 | ### Response Object
276 |
277 | Upon recieving a response Unirest returns the result in the form of an Object, this object should always have the same keys for each language regarding to the response details.
278 |
279 | - `code` - HTTP Response Status Code (Example `200`)
280 | - `headers` - HTTP Response Headers
281 | - `body` - Parsed response body where applicable, for example JSON responses are parsed to Objects / Associative Arrays.
282 | - `raw_body` - Un-parsed response body
283 |
284 | ### Advanced Configuration
285 |
286 | You can set some advanced configuration to tune Unirest-PHP:
287 |
288 | #### Custom JSON Decode Flags
289 |
290 | Unirest uses PHP's [JSON Extension](http://php.net/manual/en/book.json.php) for automatically decoding JSON responses.
291 | sometime you may want to return associative arrays, limit the depth of recursion, or use any of the [customization flags](http://php.net/manual/en/json.constants.php).
292 |
293 | To do so, simply set the desired options using the `jsonOpts` request method:
294 |
295 | ```php
296 | Unirest\Request::jsonOpts(true, 512, JSON_NUMERIC_CHECK & JSON_FORCE_OBJECT & JSON_UNESCAPED_SLASHES);
297 | ```
298 |
299 | #### Timeout
300 |
301 | You can set a custom timeout value (in **seconds**):
302 |
303 | ```php
304 | Unirest\Request::timeout(5); // 5s timeout
305 | ```
306 |
307 | #### Proxy
308 |
309 | Set the proxy to use for the upcoming request.
310 |
311 | you can also set the proxy type to be one of `CURLPROXY_HTTP`, `CURLPROXY_HTTP_1_0`, `CURLPROXY_SOCKS4`, `CURLPROXY_SOCKS5`, `CURLPROXY_SOCKS4A`, and `CURLPROXY_SOCKS5_HOSTNAME`.
312 |
313 | *check the [cURL docs](http://curl.haxx.se/libcurl/c/CURLOPT_PROXYTYPE.html) for more info*.
314 |
315 | ```php
316 | // quick setup with default port: 1080
317 | Unirest\Request::proxy('10.10.10.1');
318 |
319 | // custom port and proxy type
320 | Unirest\Request::proxy('10.10.10.1', 8080, CURLPROXY_HTTP);
321 |
322 | // enable tunneling
323 | Unirest\Request::proxy('10.10.10.1', 8080, CURLPROXY_HTTP, true);
324 | ```
325 |
326 | ##### Proxy Authenticaton
327 |
328 | Passing a username, password *(optional)*, defaults to Basic Authentication:
329 |
330 | ```php
331 | // basic auth
332 | Unirest\Request::proxyAuth('username', 'password');
333 | ```
334 |
335 | The third parameter, which is a bitmask, will Unirest which HTTP authentication method(s) you want it to use for your proxy authentication.
336 |
337 | If more than one bit is set, Unirest *(at PHP's libcurl level)* will first query the site to see what authentication methods it supports and then pick the best one you allow it to use. *For some methods, this will induce an extra network round-trip.*
338 |
339 | See [Authentication](#authentication) for more details on methods supported.
340 |
341 | ```php
342 | // basic auth
343 | Unirest\Request::proxyAuth('username', 'password', CURLAUTH_DIGEST);
344 | ```
345 |
346 | #### Default Request Headers
347 |
348 | You can set default headers that will be sent on every request:
349 |
350 | ```php
351 | Unirest\Request::defaultHeader('Header1', 'Value1');
352 | Unirest\Request::defaultHeader('Header2', 'Value2');
353 | ```
354 |
355 | You can set default headers in bulk by passing an array:
356 |
357 | ```php
358 | Unirest\Request::defaultHeaders(array(
359 | 'Header1' => 'Value1',
360 | 'Header2' => 'Value2'
361 | ));
362 | ```
363 |
364 | You can clear the default headers anytime with:
365 |
366 | ```php
367 | Unirest\Request::clearDefaultHeaders();
368 | ```
369 |
370 | #### Default cURL Options
371 |
372 | You can set default [cURL options](http://php.net/manual/en/function.curl-setopt.php) that will be sent on every request:
373 |
374 | ```php
375 | Unirest\Request::curlOpt(CURLOPT_COOKIE, 'foo=bar');
376 | ```
377 |
378 | You can set options bulk by passing an array:
379 |
380 | ```php
381 | Unirest\Request::curlOpts(array(
382 | CURLOPT_COOKIE => 'foo=bar'
383 | ));
384 | ```
385 |
386 | You can clear the default options anytime with:
387 |
388 | ```php
389 | Unirest\Request::clearCurlOpts();
390 | ```
391 |
392 | #### SSL validation
393 |
394 | You can explicitly enable or disable SSL certificate validation when consuming an SSL protected endpoint:
395 |
396 | ```php
397 | Unirest\Request::verifyPeer(false); // Disables SSL cert validation
398 | ```
399 |
400 | By default is `true`.
401 |
402 | #### Utility Methods
403 |
404 | ```php
405 | // alias for `curl_getinfo`
406 | Unirest\Request::getInfo()
407 |
408 | // returns internal cURL handle
409 | Unirest\Request::getCurlHandle()
410 | ```
411 |
412 | ----
413 |
414 | Made with ♥ from the [Mashape][mashape-url] team
415 |
416 | [unirest-logo]: http://cl.ly/image/2P373Y090s2O/Image%202015-10-12%20at%209.48.06%20PM.png
417 |
418 |
419 | [mashape-url]: https://www.mashape.com/
420 |
421 | [license-url]: https://github.com/Mashape/unirest-php/blob/master/LICENSE
422 |
423 | [gitter-url]: https://gitter.im/Mashape/unirest-php
424 | [gitter-image]: https://img.shields.io/badge/Gitter-Join%20Chat-blue.svg?style=flat
425 |
426 | [travis-url]: https://travis-ci.org/Mashape/unirest-php
427 | [travis-image]: https://img.shields.io/travis/Mashape/unirest-php.svg?style=flat
428 |
429 | [packagist-url]: https://packagist.org/packages/Mashape/unirest-php
430 | [packagist-license]: https://img.shields.io/packagist/l/Mashape/unirest-php.svg?style=flat
431 | [packagist-version]: https://img.shields.io/packagist/v/Mashape/unirest-php.svg?style=flat
432 | [packagist-downloads]: https://img.shields.io/packagist/dm/Mashape/unirest-php.svg?style=flat
433 |
434 | [codeclimate-url]: https://codeclimate.com/github/Mashape/unirest-php
435 | [codeclimate-quality]: https://img.shields.io/codeclimate/github/Mashape/unirest-php.svg?style=flat
436 | [codeclimate-coverage]: https://img.shields.io/codeclimate/coverage/github/Mashape/unirest-php.svg?style=flat
437 |
438 | [versioneye-url]: https://www.versioneye.com/user/projects/54b82450050646ca5c0001f3
439 | [versioneye-image]: https://img.shields.io/versioneye/d/php/mashape:unirest-php.svg?style=flat
440 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mashape/unirest-php",
3 | "description": "Unirest PHP",
4 | "keywords": ["rest", "curl", "http", "https", "client"],
5 | "type": "library",
6 | "homepage": "https://github.com/Mashape/unirest-php",
7 | "license": "MIT",
8 | "author": "Mashape (https://www.mashape.com)",
9 | "require": {
10 | "php": ">=5.4.0",
11 | "ext-curl": "*"
12 | },
13 | "suggest": {
14 | "ext-json": "Allows using JSON Bodies for sending and parsing requests"
15 | },
16 | "require-dev": {
17 | "phpunit/phpunit": "~4.4",
18 | "codeclimate/php-test-reporter": "0.1.*"
19 | },
20 | "autoload": {
21 | "psr-0": {
22 | "Unirest\\": "src/"
23 | }
24 | },
25 | "support": {
26 | "email": "opensource@mashape.com"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | ./tests
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/src/Unirest.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'pass' => '',
20 | 'method' => CURLAUTH_BASIC
21 | );
22 |
23 | private static $proxy = array(
24 | 'port' => false,
25 | 'tunnel' => false,
26 | 'address' => false,
27 | 'type' => CURLPROXY_HTTP,
28 | 'auth' => array (
29 | 'user' => '',
30 | 'pass' => '',
31 | 'method' => CURLAUTH_BASIC
32 | )
33 | );
34 |
35 | /**
36 | * Set JSON decode mode
37 | *
38 | * @param bool $assoc When TRUE, returned objects will be converted into associative arrays.
39 | * @param integer $depth User specified recursion depth.
40 | * @param integer $options Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
41 | * @return array
42 | */
43 | public static function jsonOpts($assoc = false, $depth = 512, $options = 0)
44 | {
45 | return self::$jsonOpts = array($assoc, $depth, $options);
46 | }
47 |
48 | /**
49 | * Verify SSL peer
50 | *
51 | * @param bool $enabled enable SSL verification, by default is true
52 | * @return bool
53 | */
54 | public static function verifyPeer($enabled)
55 | {
56 | return self::$verifyPeer = $enabled;
57 | }
58 |
59 | /**
60 | * Verify SSL host
61 | *
62 | * @param bool $enabled enable SSL host verification, by default is true
63 | * @return bool
64 | */
65 | public static function verifyHost($enabled)
66 | {
67 | return self::$verifyHost = $enabled;
68 | }
69 |
70 | /**
71 | * Set a timeout
72 | *
73 | * @param integer $seconds timeout value in seconds
74 | * @return integer
75 | */
76 | public static function timeout($seconds)
77 | {
78 | return self::$socketTimeout = $seconds;
79 | }
80 |
81 | /**
82 | * Set default headers to send on every request
83 | *
84 | * @param array $headers headers array
85 | * @return array
86 | */
87 | public static function defaultHeaders($headers)
88 | {
89 | return self::$defaultHeaders = array_merge(self::$defaultHeaders, $headers);
90 | }
91 |
92 | /**
93 | * Set a new default header to send on every request
94 | *
95 | * @param string $name header name
96 | * @param string $value header value
97 | * @return string
98 | */
99 | public static function defaultHeader($name, $value)
100 | {
101 | return self::$defaultHeaders[$name] = $value;
102 | }
103 |
104 | /**
105 | * Clear all the default headers
106 | */
107 | public static function clearDefaultHeaders()
108 | {
109 | return self::$defaultHeaders = array();
110 | }
111 |
112 | /**
113 | * Set curl options to send on every request
114 | *
115 | * @param array $options options array
116 | * @return array
117 | */
118 | public static function curlOpts($options)
119 | {
120 | return self::mergeCurlOptions(self::$curlOpts, $options);
121 | }
122 |
123 | /**
124 | * Set a new default header to send on every request
125 | *
126 | * @param string $name header name
127 | * @param string $value header value
128 | * @return string
129 | */
130 | public static function curlOpt($name, $value)
131 | {
132 | return self::$curlOpts[$name] = $value;
133 | }
134 |
135 | /**
136 | * Clear all the default headers
137 | */
138 | public static function clearCurlOpts()
139 | {
140 | return self::$curlOpts = array();
141 | }
142 |
143 | /**
144 | * Set a Mashape key to send on every request as a header
145 | * Obtain your Mashape key by browsing one of your Mashape applications on https://www.mashape.com
146 | *
147 | * Note: Mashape provides 2 keys for each application: a 'Testing' and a 'Production' one.
148 | * Be aware of which key you are using and do not share your Production key.
149 | *
150 | * @param string $key Mashape key
151 | * @return string
152 | */
153 | public static function setMashapeKey($key)
154 | {
155 | return self::defaultHeader('X-Mashape-Key', $key);
156 | }
157 |
158 | /**
159 | * Set a cookie string for enabling cookie handling
160 | *
161 | * @param string $cookie
162 | */
163 | public static function cookie($cookie)
164 | {
165 | self::$cookie = $cookie;
166 | }
167 |
168 | /**
169 | * Set a cookie file path for enabling cookie handling
170 | *
171 | * $cookieFile must be a correct path with write permission
172 | *
173 | * @param string $cookieFile - path to file for saving cookie
174 | */
175 | public static function cookieFile($cookieFile)
176 | {
177 | self::$cookieFile = $cookieFile;
178 | }
179 |
180 | /**
181 | * Set authentication method to use
182 | *
183 | * @param string $username authentication username
184 | * @param string $password authentication password
185 | * @param integer $method authentication method
186 | */
187 | public static function auth($username = '', $password = '', $method = CURLAUTH_BASIC)
188 | {
189 | self::$auth['user'] = $username;
190 | self::$auth['pass'] = $password;
191 | self::$auth['method'] = $method;
192 | }
193 |
194 | /**
195 | * Set proxy to use
196 | *
197 | * @param string $address proxy address
198 | * @param integer $port proxy port
199 | * @param integer $type (Available options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4, CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5_HOSTNAME)
200 | * @param bool $tunnel enable/disable tunneling
201 | */
202 | public static function proxy($address, $port = 1080, $type = CURLPROXY_HTTP, $tunnel = false)
203 | {
204 | self::$proxy['type'] = $type;
205 | self::$proxy['port'] = $port;
206 | self::$proxy['tunnel'] = $tunnel;
207 | self::$proxy['address'] = $address;
208 | }
209 |
210 | /**
211 | * Set proxy authentication method to use
212 | *
213 | * @param string $username authentication username
214 | * @param string $password authentication password
215 | * @param integer $method authentication method
216 | */
217 | public static function proxyAuth($username = '', $password = '', $method = CURLAUTH_BASIC)
218 | {
219 | self::$proxy['auth']['user'] = $username;
220 | self::$proxy['auth']['pass'] = $password;
221 | self::$proxy['auth']['method'] = $method;
222 | }
223 |
224 | /**
225 | * Send a GET request to a URL
226 | *
227 | * @param string $url URL to send the GET request to
228 | * @param array $headers additional headers to send
229 | * @param mixed $parameters parameters to send in the querystring
230 | * @param string $username Authentication username (deprecated)
231 | * @param string $password Authentication password (deprecated)
232 | * @return Response
233 | */
234 | public static function get($url, $headers = array(), $parameters = null, $username = null, $password = null)
235 | {
236 | return self::send(Method::GET, $url, $parameters, $headers, $username, $password);
237 | }
238 |
239 | /**
240 | * Send a HEAD request to a URL
241 | * @param string $url URL to send the HEAD request to
242 | * @param array $headers additional headers to send
243 | * @param mixed $parameters parameters to send in the querystring
244 | * @param string $username Basic Authentication username (deprecated)
245 | * @param string $password Basic Authentication password (deprecated)
246 | * @return Response
247 | */
248 | public static function head($url, $headers = array(), $parameters = null, $username = null, $password = null)
249 | {
250 | return self::send(Method::HEAD, $url, $parameters, $headers, $username, $password);
251 | }
252 |
253 | /**
254 | * Send a OPTIONS request to a URL
255 | * @param string $url URL to send the OPTIONS request to
256 | * @param array $headers additional headers to send
257 | * @param mixed $parameters parameters to send in the querystring
258 | * @param string $username Basic Authentication username
259 | * @param string $password Basic Authentication password
260 | * @return Response
261 | */
262 | public static function options($url, $headers = array(), $parameters = null, $username = null, $password = null)
263 | {
264 | return self::send(Method::OPTIONS, $url, $parameters, $headers, $username, $password);
265 | }
266 |
267 | /**
268 | * Send a CONNECT request to a URL
269 | * @param string $url URL to send the CONNECT request to
270 | * @param array $headers additional headers to send
271 | * @param mixed $parameters parameters to send in the querystring
272 | * @param string $username Basic Authentication username (deprecated)
273 | * @param string $password Basic Authentication password (deprecated)
274 | * @return Response
275 | */
276 | public static function connect($url, $headers = array(), $parameters = null, $username = null, $password = null)
277 | {
278 | return self::send(Method::CONNECT, $url, $parameters, $headers, $username, $password);
279 | }
280 |
281 | /**
282 | * Send POST request to a URL
283 | * @param string $url URL to send the POST request to
284 | * @param array $headers additional headers to send
285 | * @param mixed $body POST body data
286 | * @param string $username Basic Authentication username (deprecated)
287 | * @param string $password Basic Authentication password (deprecated)
288 | * @return Response response
289 | */
290 | public static function post($url, $headers = array(), $body = null, $username = null, $password = null)
291 | {
292 | return self::send(Method::POST, $url, $body, $headers, $username, $password);
293 | }
294 |
295 | /**
296 | * Send DELETE request to a URL
297 | * @param string $url URL to send the DELETE request to
298 | * @param array $headers additional headers to send
299 | * @param mixed $body DELETE body data
300 | * @param string $username Basic Authentication username (deprecated)
301 | * @param string $password Basic Authentication password (deprecated)
302 | * @return Response
303 | */
304 | public static function delete($url, $headers = array(), $body = null, $username = null, $password = null)
305 | {
306 | return self::send(Method::DELETE, $url, $body, $headers, $username, $password);
307 | }
308 |
309 | /**
310 | * Send PUT request to a URL
311 | * @param string $url URL to send the PUT request to
312 | * @param array $headers additional headers to send
313 | * @param mixed $body PUT body data
314 | * @param string $username Basic Authentication username (deprecated)
315 | * @param string $password Basic Authentication password (deprecated)
316 | * @return Response
317 | */
318 | public static function put($url, $headers = array(), $body = null, $username = null, $password = null)
319 | {
320 | return self::send(Method::PUT, $url, $body, $headers, $username, $password);
321 | }
322 |
323 | /**
324 | * Send PATCH request to a URL
325 | * @param string $url URL to send the PATCH request to
326 | * @param array $headers additional headers to send
327 | * @param mixed $body PATCH body data
328 | * @param string $username Basic Authentication username (deprecated)
329 | * @param string $password Basic Authentication password (deprecated)
330 | * @return Response
331 | */
332 | public static function patch($url, $headers = array(), $body = null, $username = null, $password = null)
333 | {
334 | return self::send(Method::PATCH, $url, $body, $headers, $username, $password);
335 | }
336 |
337 | /**
338 | * Send TRACE request to a URL
339 | * @param string $url URL to send the TRACE request to
340 | * @param array $headers additional headers to send
341 | * @param mixed $body TRACE body data
342 | * @param string $username Basic Authentication username (deprecated)
343 | * @param string $password Basic Authentication password (deprecated)
344 | * @return Response
345 | */
346 | public static function trace($url, $headers = array(), $body = null, $username = null, $password = null)
347 | {
348 | return self::send(Method::TRACE, $url, $body, $headers, $username, $password);
349 | }
350 |
351 | /**
352 | * This function is useful for serializing multidimensional arrays, and avoid getting
353 | * the 'Array to string conversion' notice
354 | * @param array|object $data array to flatten.
355 | * @param bool|string $parent parent key or false if no parent
356 | * @return array
357 | */
358 | public static function buildHTTPCurlQuery($data, $parent = false)
359 | {
360 | $result = array();
361 |
362 | if (is_object($data)) {
363 | $data = get_object_vars($data);
364 | }
365 |
366 | foreach ($data as $key => $value) {
367 | if ($parent) {
368 | $new_key = sprintf('%s[%s]', $parent, $key);
369 | } else {
370 | $new_key = $key;
371 | }
372 |
373 | if (!$value instanceof \CURLFile and (is_array($value) or is_object($value))) {
374 | $result = array_merge($result, self::buildHTTPCurlQuery($value, $new_key));
375 | } else {
376 | $result[$new_key] = $value;
377 | }
378 | }
379 |
380 | return $result;
381 | }
382 |
383 | /**
384 | * Send a cURL request
385 | * @param \Unirest\Method|string $method HTTP method to use
386 | * @param string $url URL to send the request to
387 | * @param mixed $body request body
388 | * @param array $headers additional headers to send
389 | * @param string $username Authentication username (deprecated)
390 | * @param string $password Authentication password (deprecated)
391 | * @throws \Unirest\Exception if a cURL error occurs
392 | * @return Response
393 | */
394 | public static function send($method, $url, $body = null, $headers = array(), $username = null, $password = null)
395 | {
396 | self::$handle = curl_init();
397 |
398 | if ($method !== Method::GET) {
399 | if ($method === Method::POST) {
400 | curl_setopt(self::$handle, CURLOPT_POST, true);
401 | } else {
402 | curl_setopt(self::$handle, CURLOPT_CUSTOMREQUEST, $method);
403 | }
404 |
405 | curl_setopt(self::$handle, CURLOPT_POSTFIELDS, $body);
406 | } elseif (is_array($body)) {
407 | if (strpos($url, '?') !== false) {
408 | $url .= '&';
409 | } else {
410 | $url .= '?';
411 | }
412 |
413 | $url .= urldecode(http_build_query(self::buildHTTPCurlQuery($body)));
414 | }
415 |
416 | $curl_base_options = [
417 | CURLOPT_URL => self::encodeUrl($url),
418 | CURLOPT_RETURNTRANSFER => true,
419 | CURLOPT_FOLLOWLOCATION => true,
420 | CURLOPT_MAXREDIRS => 10,
421 | CURLOPT_HTTPHEADER => self::getFormattedHeaders($headers),
422 | CURLOPT_HEADER => true,
423 | CURLOPT_SSL_VERIFYPEER => self::$verifyPeer,
424 | //CURLOPT_SSL_VERIFYHOST accepts only 0 (false) or 2 (true). Future versions of libcurl will treat values 1 and 2 as equals
425 | CURLOPT_SSL_VERIFYHOST => self::$verifyHost === false ? 0 : 2,
426 | // If an empty string, '', is set, a header containing all supported encoding types is sent
427 | CURLOPT_ENCODING => ''
428 | ];
429 |
430 | curl_setopt_array(self::$handle, self::mergeCurlOptions($curl_base_options, self::$curlOpts));
431 |
432 | if (self::$socketTimeout !== null) {
433 | curl_setopt(self::$handle, CURLOPT_TIMEOUT, self::$socketTimeout);
434 | }
435 |
436 | if (self::$cookie) {
437 | curl_setopt(self::$handle, CURLOPT_COOKIE, self::$cookie);
438 | }
439 |
440 | if (self::$cookieFile) {
441 | curl_setopt(self::$handle, CURLOPT_COOKIEFILE, self::$cookieFile);
442 | curl_setopt(self::$handle, CURLOPT_COOKIEJAR, self::$cookieFile);
443 | }
444 |
445 | // supporting deprecated http auth method
446 | if (!empty($username)) {
447 | curl_setopt_array(self::$handle, array(
448 | CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
449 | CURLOPT_USERPWD => $username . ':' . $password
450 | ));
451 | }
452 |
453 | if (!empty(self::$auth['user'])) {
454 | curl_setopt_array(self::$handle, array(
455 | CURLOPT_HTTPAUTH => self::$auth['method'],
456 | CURLOPT_USERPWD => self::$auth['user'] . ':' . self::$auth['pass']
457 | ));
458 | }
459 |
460 | if (self::$proxy['address'] !== false) {
461 | curl_setopt_array(self::$handle, array(
462 | CURLOPT_PROXYTYPE => self::$proxy['type'],
463 | CURLOPT_PROXY => self::$proxy['address'],
464 | CURLOPT_PROXYPORT => self::$proxy['port'],
465 | CURLOPT_HTTPPROXYTUNNEL => self::$proxy['tunnel'],
466 | CURLOPT_PROXYAUTH => self::$proxy['auth']['method'],
467 | CURLOPT_PROXYUSERPWD => self::$proxy['auth']['user'] . ':' . self::$proxy['auth']['pass']
468 | ));
469 | }
470 |
471 | $response = curl_exec(self::$handle);
472 | $error = curl_error(self::$handle);
473 | $info = self::getInfo();
474 |
475 | if ($error) {
476 | throw new Exception($error);
477 | }
478 |
479 | // Split the full response in its headers and body
480 | $header_size = $info['header_size'];
481 | $header = substr($response, 0, $header_size);
482 | $body = substr($response, $header_size);
483 | $httpCode = $info['http_code'];
484 |
485 | return new Response($httpCode, $body, $header, self::$jsonOpts);
486 | }
487 |
488 | public static function getInfo($opt = false)
489 | {
490 | if ($opt) {
491 | $info = curl_getinfo(self::$handle, $opt);
492 | } else {
493 | $info = curl_getinfo(self::$handle);
494 | }
495 |
496 | return $info;
497 | }
498 |
499 | public static function getCurlHandle()
500 | {
501 | return self::$handle;
502 | }
503 |
504 | public static function getFormattedHeaders($headers)
505 | {
506 | $formattedHeaders = array();
507 |
508 | $combinedHeaders = array_change_key_case(array_merge(self::$defaultHeaders, (array) $headers));
509 |
510 | foreach ($combinedHeaders as $key => $val) {
511 | $formattedHeaders[] = self::getHeaderString($key, $val);
512 | }
513 |
514 | if (!array_key_exists('user-agent', $combinedHeaders)) {
515 | $formattedHeaders[] = 'user-agent: unirest-php/2.0';
516 | }
517 |
518 | if (!array_key_exists('expect', $combinedHeaders)) {
519 | $formattedHeaders[] = 'expect:';
520 | }
521 |
522 | return $formattedHeaders;
523 | }
524 |
525 | private static function getArrayFromQuerystring($query)
526 | {
527 | $query = preg_replace_callback('/(?:^|(?<=&))[^=[]+/', function ($match) {
528 | return bin2hex(urldecode($match[0]));
529 | }, $query);
530 |
531 | parse_str($query, $values);
532 |
533 | return array_combine(array_map('hex2bin', array_keys($values)), $values);
534 | }
535 |
536 | /**
537 | * Ensure that a URL is encoded and safe to use with cURL
538 | * @param string $url URL to encode
539 | * @return string
540 | */
541 | private static function encodeUrl($url)
542 | {
543 | $url_parsed = parse_url($url);
544 |
545 | $scheme = $url_parsed['scheme'] . '://';
546 | $host = $url_parsed['host'];
547 | $port = (isset($url_parsed['port']) ? $url_parsed['port'] : null);
548 | $path = (isset($url_parsed['path']) ? $url_parsed['path'] : null);
549 | $query = (isset($url_parsed['query']) ? $url_parsed['query'] : null);
550 |
551 | if ($query !== null) {
552 | $query = '?' . http_build_query(self::getArrayFromQuerystring($query));
553 | }
554 |
555 | if ($port && $port[0] !== ':') {
556 | $port = ':' . $port;
557 | }
558 |
559 | $result = $scheme . $host . $port . $path . $query;
560 | return $result;
561 | }
562 |
563 | private static function getHeaderString($key, $val)
564 | {
565 | $key = trim(strtolower($key));
566 | return $key . ': ' . $val;
567 | }
568 |
569 | /**
570 | * @param array $existing_options
571 | * @param array $new_options
572 | * @return array
573 | */
574 | private static function mergeCurlOptions(&$existing_options, $new_options)
575 | {
576 | $existing_options = $new_options + $existing_options;
577 | return $existing_options;
578 | }
579 | }
580 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/src/Unirest/Request/Body.php:
--------------------------------------------------------------------------------
1 | $file) {
60 | $data[$name] = call_user_func(array(__CLASS__, 'File'), $file);
61 | }
62 | }
63 |
64 | return $data;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/src/Unirest/Response.php:
--------------------------------------------------------------------------------
1 | code = $code;
21 | $this->headers = $this->parseHeaders($headers);
22 | $this->raw_body = $raw_body;
23 | $this->body = $raw_body;
24 |
25 | // make sure raw_body is the first argument
26 | array_unshift($json_args, $raw_body);
27 |
28 | if (function_exists('json_decode')) {
29 | $json = call_user_func_array('json_decode', $json_args);
30 |
31 | if (json_last_error() === JSON_ERROR_NONE) {
32 | $this->body = $json;
33 | }
34 | }
35 | }
36 |
37 | /**
38 | * if PECL_HTTP is not available use a fall back function
39 | *
40 | * thanks to ricardovermeltfoort@gmail.com
41 | * http://php.net/manual/en/function.http-parse-headers.php#112986
42 | * @param string $raw_headers raw headers
43 | * @return array
44 | */
45 | private function parseHeaders($raw_headers)
46 | {
47 | if (function_exists('http_parse_headers')) {
48 | return http_parse_headers($raw_headers);
49 | } else {
50 | $key = '';
51 | $headers = array();
52 |
53 | foreach (explode("\n", $raw_headers) as $i => $h) {
54 | $h = explode(':', $h, 2);
55 |
56 | if (isset($h[1])) {
57 | if (!isset($headers[$h[0]])) {
58 | $headers[$h[0]] = trim($h[1]);
59 | } elseif (is_array($headers[$h[0]])) {
60 | $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
61 | } else {
62 | $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
63 | }
64 |
65 | $key = $h[0];
66 | } else {
67 | if (substr($h[0], 0, 1) == "\t") {
68 | $headers[$key] .= "\r\n\t".trim($h[0]);
69 | } elseif (!$key) {
70 | $headers[0] = trim($h[0]);
71 | }
72 | }
73 | }
74 |
75 | return $headers;
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/tests/Unirest/BodyTest.php:
--------------------------------------------------------------------------------
1 | assertEquals($file, sprintf('@%s;filename=%s;type=', $fixture, basename($fixture)));
20 | } else {
21 | $this->assertTrue($file instanceof \CURLFile);
22 | }
23 | }
24 |
25 | public function testHttpBuildQueryWithCurlFile()
26 | {
27 | $fixture = __DIR__ . '/fixtures/upload.txt';
28 |
29 | $file = Body::File($fixture);
30 | $body = array(
31 | 'to' => 'mail@mailinator.com',
32 | 'from' => 'mail@mailinator.com',
33 | 'file' => $file
34 | );
35 |
36 | $result = Request::buildHTTPCurlQuery($body);
37 | $this->assertEquals($result['file'], $file);
38 | }
39 |
40 | public function testJson()
41 | {
42 | $body = Body::Json(array('foo', 'bar'));
43 |
44 | $this->assertEquals($body, '["foo","bar"]');
45 | }
46 |
47 | public function testForm()
48 | {
49 | $body = Body::Form(array('foo' => 'bar', 'bar' => 'baz'));
50 |
51 | $this->assertEquals($body, 'foo=bar&bar=baz');
52 |
53 | // try again with a string
54 | $body = Body::Form($body);
55 |
56 | $this->assertEquals($body, 'foo=bar&bar=baz');
57 | }
58 |
59 | public function testMultipart()
60 | {
61 | $arr = array('foo' => 'bar', 'bar' => 'baz');
62 |
63 | $body = Body::Multipart((object) $arr);
64 |
65 | $this->assertEquals($body, $arr);
66 |
67 | $body = Body::Multipart('flat');
68 |
69 | $this->assertEquals($body, array('flat'));
70 | }
71 |
72 | public function testMultipartFiles()
73 | {
74 | $fixture = __DIR__ . '/fixtures/upload.txt';
75 |
76 | $data = array('foo' => 'bar', 'bar' => 'baz');
77 | $files = array('test' => $fixture);
78 |
79 | $body = Body::Multipart($data, $files);
80 |
81 | // echo $body;
82 |
83 | $this->assertEquals($body, array(
84 | 'foo' => 'bar',
85 | 'bar' => 'baz',
86 | 'test' => Body::File($fixture)
87 | ));
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/tests/Unirest/RequestTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(property_exists($response->body->cookies, 'foo'));
19 |
20 | Request::clearCurlOpts();
21 | }
22 |
23 | /**
24 | * @expectedException \Unirest\Exception
25 | */
26 | public function testTimeoutFail()
27 | {
28 | Request::timeout(1);
29 |
30 | Request::get('http://mockbin.com/delay/1000');
31 |
32 | Request::timeout(null); // Cleaning timeout for the other tests
33 | }
34 |
35 | public function testDefaultHeaders()
36 | {
37 | $defaultHeaders = array(
38 | 'header1' => 'Hello',
39 | 'header2' => 'world'
40 | );
41 | Request::defaultHeaders($defaultHeaders);
42 |
43 | $response = Request::get('http://mockbin.com/request');
44 |
45 | $this->assertEquals(200, $response->code);
46 | $this->assertObjectHasAttribute('header1', $response->body->headers);
47 | $this->assertEquals('Hello', $response->body->headers->header1);
48 | $this->assertObjectHasAttribute('header2', $response->body->headers);
49 | $this->assertEquals('world', $response->body->headers->header2);
50 |
51 | $response = Request::get('http://mockbin.com/request', ['header1' => 'Custom value']);
52 |
53 | $this->assertEquals(200, $response->code);
54 | $this->assertObjectHasAttribute('header1', $response->body->headers);
55 | $this->assertEquals('Custom value', $response->body->headers->header1);
56 |
57 | Request::clearDefaultHeaders();
58 |
59 | $response = Request::get('http://mockbin.com/request');
60 |
61 | $this->assertEquals(200, $response->code);
62 | $this->assertObjectNotHasAttribute('header1', $response->body->headers);
63 | $this->assertObjectNotHasAttribute('header2', $response->body->headers);
64 | }
65 |
66 | public function testDefaultHeader()
67 | {
68 | Request::defaultHeader('Hello', 'custom');
69 |
70 | $response = Request::get('http://mockbin.com/request');
71 |
72 | $this->assertEquals(200, $response->code);
73 | $this->assertTrue(property_exists($response->body->headers, 'hello'));
74 | $this->assertEquals('custom', $response->body->headers->hello);
75 |
76 | Request::clearDefaultHeaders();
77 |
78 | $response = Request::get('http://mockbin.com/request');
79 |
80 | $this->assertEquals(200, $response->code);
81 | $this->assertFalse(property_exists($response->body->headers, 'hello'));
82 | }
83 |
84 | public function testSetMashapeKey()
85 | {
86 | Request::setMashapeKey('abcd');
87 |
88 | $response = Request::get('http://mockbin.com/request');
89 |
90 | $this->assertEquals(200, $response->code);
91 | $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key'));
92 | $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'});
93 |
94 | // send another request
95 | $response = Request::get('http://mockbin.com/request');
96 |
97 | $this->assertEquals(200, $response->code);
98 | $this->assertTrue(property_exists($response->body->headers, 'x-mashape-key'));
99 | $this->assertEquals('abcd', $response->body->headers->{'x-mashape-key'});
100 |
101 | Request::clearDefaultHeaders();
102 |
103 | $response = Request::get('http://mockbin.com/request');
104 |
105 | $this->assertEquals(200, $response->code);
106 | $this->assertFalse(property_exists($response->body->headers, 'x-mashape-key'));
107 | }
108 |
109 | public function testGzip()
110 | {
111 | $response = Request::get('http://mockbin.com/gzip/request');
112 |
113 | $this->assertEquals('gzip', $response->headers['Content-Encoding']);
114 | }
115 |
116 | public function testBasicAuthenticationDeprecated()
117 | {
118 | $response = Request::get('http://mockbin.com/request', array(), array(), 'user', 'password');
119 |
120 | $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $response->body->headers->authorization);
121 | }
122 |
123 | public function testBasicAuthentication()
124 | {
125 | Request::auth('user', 'password');
126 |
127 | $response = Request::get('http://mockbin.com/request');
128 |
129 | $this->assertEquals('Basic dXNlcjpwYXNzd29yZA==', $response->body->headers->authorization);
130 | }
131 |
132 | public function testCustomHeaders()
133 | {
134 | $response = Request::get('http://mockbin.com/request', array(
135 | 'user-agent' => 'unirest-php',
136 | ));
137 |
138 | $this->assertEquals(200, $response->code);
139 | $this->assertEquals('unirest-php', $response->body->headers->{'user-agent'});
140 | }
141 |
142 | // GET
143 | public function testGet()
144 | {
145 | $response = Request::get('http://mockbin.com/request?name=Mark', array(
146 | 'Accept' => 'application/json'
147 | ), array(
148 | 'nick' => 'thefosk'
149 | ));
150 |
151 | $this->assertEquals(200, $response->code);
152 | $this->assertEquals('GET', $response->body->method);
153 | $this->assertEquals('Mark', $response->body->queryString->name);
154 | $this->assertEquals('thefosk', $response->body->queryString->nick);
155 | }
156 |
157 | public function testGetMultidimensionalArray()
158 | {
159 | $response = Request::get('http://mockbin.com/request', array(
160 | 'Accept' => 'application/json'
161 | ), array(
162 | 'key' => 'value',
163 | 'items' => array(
164 | 'item1',
165 | 'item2'
166 | )
167 | ));
168 |
169 | $this->assertEquals(200, $response->code);
170 | $this->assertEquals('GET', $response->body->method);
171 | $this->assertEquals('value', $response->body->queryString->key);
172 | $this->assertEquals('item1', $response->body->queryString->items[0]);
173 | $this->assertEquals('item2', $response->body->queryString->items[1]);
174 | }
175 |
176 | public function testGetWithDots()
177 | {
178 | $response = Request::get('http://mockbin.com/request', array(
179 | 'Accept' => 'application/json'
180 | ), array(
181 | 'user.name' => 'Mark',
182 | 'nick' => 'thefosk'
183 | ));
184 |
185 | $this->assertEquals(200, $response->code);
186 | $this->assertEquals('GET', $response->body->method);
187 | $this->assertEquals('Mark', $response->body->queryString->{'user.name'});
188 | $this->assertEquals('thefosk', $response->body->queryString->nick);
189 | }
190 |
191 | public function testGetWithDotsAlt()
192 | {
193 | $response = Request::get('http://mockbin.com/request', array(
194 | 'Accept' => 'application/json'
195 | ), array(
196 | 'user.name' => 'Mark Bond',
197 | 'nick' => 'thefosk'
198 | ));
199 |
200 | $this->assertEquals(200, $response->code);
201 | $this->assertEquals('GET', $response->body->method);
202 | $this->assertEquals('Mark Bond', $response->body->queryString->{'user.name'});
203 | $this->assertEquals('thefosk', $response->body->queryString->nick);
204 | }
205 | public function testGetWithEqualSign()
206 | {
207 | $response = Request::get('http://mockbin.com/request', array(
208 | 'Accept' => 'application/json'
209 | ), array(
210 | 'name' => 'Mark=Hello'
211 | ));
212 |
213 | $this->assertEquals(200, $response->code);
214 | $this->assertEquals('GET', $response->body->method);
215 | $this->assertEquals('Mark=Hello', $response->body->queryString->name);
216 | }
217 |
218 | public function testGetWithEqualSignAlt()
219 | {
220 | $response = Request::get('http://mockbin.com/request', array(
221 | 'Accept' => 'application/json'
222 | ), array(
223 | 'name' => 'Mark=Hello=John'
224 | ));
225 |
226 | $this->assertEquals(200, $response->code);
227 | $this->assertEquals('GET', $response->body->method);
228 | $this->assertEquals('Mark=Hello=John', $response->body->queryString->name);
229 | }
230 |
231 | public function testGetWithComplexQuery()
232 | {
233 | $response = Request::get('http://mockbin.com/request?query=[{"type":"/music/album","name":null,"artist":{"id":"/en/bob_dylan"},"limit":3}]&cursor');
234 |
235 | $this->assertEquals(200, $response->code);
236 | $this->assertEquals('GET', $response->body->method);
237 | $this->assertEquals('', $response->body->queryString->cursor);
238 | $this->assertEquals('[{"type":"/music/album","name":null,"artist":{"id":"/en/bob_dylan"},"limit":3}]', $response->body->queryString->query);
239 | }
240 |
241 | public function testGetArray()
242 | {
243 | $response = Request::get('http://mockbin.com/request', array(), array(
244 | 'name[0]' => 'Mark',
245 | 'name[1]' => 'John'
246 | ));
247 |
248 | $this->assertEquals(200, $response->code);
249 | $this->assertEquals('GET', $response->body->method);
250 | $this->assertEquals('Mark', $response->body->queryString->name[0]);
251 | $this->assertEquals('John', $response->body->queryString->name[1]);
252 | }
253 |
254 | // POST
255 | public function testPost()
256 | {
257 | $response = Request::post('http://mockbin.com/request', array(
258 | 'Accept' => 'application/json'
259 | ), array(
260 | 'name' => 'Mark',
261 | 'nick' => 'thefosk'
262 | ));
263 |
264 | $this->assertEquals(200, $response->code);
265 | $this->assertEquals('POST', $response->body->method);
266 | $this->assertEquals('Mark', $response->body->postData->params->name);
267 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
268 | }
269 |
270 | public function testPostForm()
271 | {
272 | $body = Request\Body::Form(array(
273 | 'name' => 'Mark',
274 | 'nick' => 'thefosk'
275 | ));
276 |
277 | $response = Request::post('http://mockbin.com/request', array(
278 | 'Accept' => 'application/json'
279 | ), $body);
280 |
281 | $this->assertEquals('POST', $response->body->method);
282 | $this->assertEquals('application/x-www-form-urlencoded', $response->body->headers->{'content-type'});
283 | $this->assertEquals('application/x-www-form-urlencoded', $response->body->postData->mimeType);
284 | $this->assertEquals('Mark', $response->body->postData->params->name);
285 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
286 | }
287 |
288 | public function testPostMultipart()
289 | {
290 | $body = Request\Body::Multipart(array(
291 | 'name' => 'Mark',
292 | 'nick' => 'thefosk'
293 | ));
294 |
295 | $response = Request::post('http://mockbin.com/request', (object) array(
296 | 'Accept' => 'application/json',
297 | ), $body);
298 |
299 | $this->assertEquals('POST', $response->body->method);
300 | $this->assertEquals('multipart/form-data', explode(';', $response->body->headers->{'content-type'})[0]);
301 | $this->assertEquals('multipart/form-data', $response->body->postData->mimeType);
302 | $this->assertEquals('Mark', $response->body->postData->params->name);
303 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
304 | }
305 |
306 | public function testPostWithEqualSign()
307 | {
308 | $body = Request\Body::Form(array(
309 | 'name' => 'Mark=Hello'
310 | ));
311 |
312 | $response = Request::post('http://mockbin.com/request', array(
313 | 'Accept' => 'application/json'
314 | ), $body);
315 |
316 | $this->assertEquals(200, $response->code);
317 | $this->assertEquals('POST', $response->body->method);
318 | $this->assertEquals('Mark=Hello', $response->body->postData->params->name);
319 | }
320 |
321 | public function testPostArray()
322 | {
323 | $response = Request::post('http://mockbin.com/request', array(
324 | 'Accept' => 'application/json'
325 | ), array(
326 | 'name[0]' => 'Mark',
327 | 'name[1]' => 'John'
328 | ));
329 |
330 | $this->assertEquals(200, $response->code);
331 | $this->assertEquals('POST', $response->body->method);
332 | $this->assertEquals('Mark', $response->body->postData->params->{'name[0]'});
333 | $this->assertEquals('John', $response->body->postData->params->{'name[1]'});
334 | }
335 |
336 | public function testPostWithDots()
337 | {
338 | $response = Request::post('http://mockbin.com/request', array(
339 | 'Accept' => 'application/json'
340 | ), array(
341 | 'user.name' => 'Mark',
342 | 'nick' => 'thefosk'
343 | ));
344 |
345 | $this->assertEquals(200, $response->code);
346 | $this->assertEquals('POST', $response->body->method);
347 | $this->assertEquals('Mark', $response->body->postData->params->{'user.name'});
348 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
349 | }
350 |
351 | public function testRawPost()
352 | {
353 | $response = Request::post('http://mockbin.com/request', array(
354 | 'Accept' => 'application/json',
355 | 'Content-Type' => 'application/json'
356 | ), json_encode(array(
357 | 'author' => 'Sam Sullivan'
358 | )));
359 |
360 | $this->assertEquals(200, $response->code);
361 | $this->assertEquals('POST', $response->body->method);
362 | $this->assertEquals('Sam Sullivan', json_decode($response->body->postData->text)->author);
363 | }
364 |
365 | public function testPostMultidimensionalArray()
366 | {
367 | $body = Request\Body::Form(array(
368 | 'key' => 'value',
369 | 'items' => array(
370 | 'item1',
371 | 'item2'
372 | )
373 | ));
374 |
375 | $response = Request::post('http://mockbin.com/request', array(
376 | 'Accept' => 'application/json'
377 | ), $body);
378 |
379 | $this->assertEquals(200, $response->code);
380 | $this->assertEquals('POST', $response->body->method);
381 | $this->assertEquals('value', $response->body->postData->params->key);
382 | $this->assertEquals('item1', $response->body->postData->params->{'items[0]'});
383 | $this->assertEquals('item2', $response->body->postData->params->{'items[1]'});
384 | }
385 |
386 | // PUT
387 | public function testPut()
388 | {
389 | $response = Request::put('http://mockbin.com/request', array(
390 | 'Accept' => 'application/json'
391 | ), array(
392 | 'name' => 'Mark',
393 | 'nick' => 'thefosk'
394 | ));
395 |
396 | $this->assertEquals(200, $response->code);
397 | $this->assertEquals('PUT', $response->body->method);
398 | $this->assertEquals('Mark', $response->body->postData->params->name);
399 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
400 | }
401 |
402 | // PATCH
403 | public function testPatch()
404 | {
405 | $response = Request::patch('http://mockbin.com/request', array(
406 | 'Accept' => 'application/json'
407 | ), array(
408 | 'name' => 'Mark',
409 | 'nick' => 'thefosk'
410 | ));
411 |
412 | $this->assertEquals(200, $response->code);
413 | $this->assertEquals('PATCH', $response->body->method);
414 | $this->assertEquals('Mark', $response->body->postData->params->name);
415 | $this->assertEquals('thefosk', $response->body->postData->params->nick);
416 | }
417 |
418 | // DELETE
419 | public function testDelete()
420 | {
421 | $response = Request::delete('http://mockbin.com/request', array(
422 | 'Accept' => 'application/json',
423 | 'Content-Type' => 'application/x-www-form-urlencoded'
424 | ), array(
425 | 'name' => 'Mark',
426 | 'nick' => 'thefosk'
427 | ));
428 |
429 | $this->assertEquals(200, $response->code);
430 | $this->assertEquals('DELETE', $response->body->method);
431 | }
432 |
433 | // Upload
434 | public function testUpload()
435 | {
436 | $fixture = __DIR__ . '/../fixtures/upload.txt';
437 |
438 | $headers = array('Accept' => 'application/json');
439 | $files = array('file' => $fixture);
440 | $data = array('name' => 'ahmad');
441 |
442 | $body = Request\Body::Multipart($data, $files);
443 |
444 | $response = Request::post('http://mockbin.com/request', $headers, $body);
445 |
446 | $this->assertEquals(200, $response->code);
447 | $this->assertEquals('POST', $response->body->method);
448 | $this->assertEquals('ahmad', $response->body->postData->params->name);
449 | $this->assertEquals('This is a test', $response->body->postData->params->file);
450 | }
451 |
452 | public function testUploadWithoutHelper()
453 | {
454 | $fixture = __DIR__ . '/../fixtures/upload.txt';
455 |
456 | $response = Request::post('http://mockbin.com/request', array(
457 | 'Accept' => 'application/json'
458 | ), array(
459 | 'name' => 'Mark',
460 | 'file' => Request\Body::File($fixture)
461 | ));
462 |
463 | $this->assertEquals(200, $response->code);
464 | $this->assertEquals('POST', $response->body->method);
465 | $this->assertEquals('Mark', $response->body->postData->params->name);
466 | $this->assertEquals('This is a test', $response->body->postData->params->file);
467 | }
468 |
469 | public function testUploadIfFilePartOfData()
470 | {
471 | $fixture = __DIR__ . '/../fixtures/upload.txt';
472 |
473 | $response = Request::post('http://mockbin.com/request', array(
474 | 'Accept' => 'application/json'
475 | ), array(
476 | 'name' => 'Mark',
477 | 'files[owl.gif]' => Request\Body::File($fixture)
478 | ));
479 |
480 | $this->assertEquals(200, $response->code);
481 | $this->assertEquals('POST', $response->body->method);
482 | $this->assertEquals('Mark', $response->body->postData->params->name);
483 | $this->assertEquals('This is a test', $response->body->postData->params->{'files[owl.gif]'});
484 | }
485 | }
486 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/tests/Unirest/ResponseTest.php:
--------------------------------------------------------------------------------
1 | assertEquals($response->body['a'], 1);
18 | }
19 |
20 | public function testJSONAObjects()
21 | {
22 | $opts = Request::jsonOpts(false);
23 | $response = new Response(200, '{"a":1,"b":2,"c":3,"d":4,"e":5}', '', $opts);
24 |
25 | $this->assertEquals($response->body->a, 1);
26 | }
27 |
28 | public function testJSONOpts()
29 | {
30 | $opts = Request::jsonOpts(false, 512, JSON_NUMERIC_CHECK);
31 | $response = new Response(200, '{"number": 1234567890}', '', $opts);
32 |
33 | $this->assertSame($response->body->number, 1234567890);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/vendor/mashape/unirest-php/tests/fixtures/upload.txt:
--------------------------------------------------------------------------------
1 | This is a test
--------------------------------------------------------------------------------