Add exception

Add exception

Авторr.kapishev
Коммитерr.kapishev
9 лет назад
Файлов изменено: 8
+28
–11
6ee3abd
Родители 88c3734 master
@@ -2,4 +2,5 @@
vendor/
composer.phar
composer.locks
.DS_Store
No newline at end of file
.DS_Store
index.php
No newline at end of file
composer.json
@@ -1,6 +1,6 @@
{
  "name":"raiym/instagram-php-scraper",
  "description":"Instagram PHP Scraper. Get account information, photo and videos without any authorization",
  "description":"Instagram PHP Scraper. Get account information, photos and videos without any authorization",
  "keywords":[
    "instagram",
    "scraper"
src/InstagramScraper.php
@@ -1,12 +1,7 @@
<?php
/**
 * Created by PhpStorm.
 * User: raiym
 * Date: 4/22/16
 * Time: 11:26 AM
 */
require_once dirname(__FILE__) . '/InstagramScraper/InstagramDataProvider.php';
require_once dirname(__FILE__) . '/InstagramScraper/InstagramScraper.php';
require_once dirname(__FILE__) . '/InstagramScraper/Account.php';
require_once dirname(__FILE__) . '/InstagramScraper/Media.php';
No newline at end of file
require_once dirname(__FILE__) . '/InstagramScraper/Media.php';
require_once dirname(__FILE__) . '/InstagramScraper/Exception.php';
No newline at end of file
src/InstagramScraper/Account.php
@@ -1,4 +1,5 @@
<?php
namespace InstagramScraper;
class Account
src/InstagramScraper/Exception.php
0 100644
@@ -0,0 +1,9 @@
<?php
namespace InstagramScraper;
class Exception extends \Exception
{
}
No newline at end of file
src/InstagramScraper/InstagramDataProvider.php
@@ -1,4 +1,5 @@
<?php
namespace InstagramScraper;
interface InstagramDataProvider
src/InstagramScraper/InstagramScraper.php
@@ -1,4 +1,5 @@
<?php
namespace InstagramScraper;
class InstagramScraper implements InstagramDataProvider
@@ -7,13 +8,21 @@
    function getAccount($username)
    {
        $response = \Unirest\Request::get(self::INSTAGRAM_URL $username);
        if ($response->code === 404) {
            throw new Exception('Account with this username does not exist.');
        }
        if ($response->code !== 200) {
            return null;
            throw new Exception('Response code is not equal 200. Something went wrong. Please report issue.');
        }
        $arr = explode('window._sharedData = '$response->body);
        $json = explode(';</script>'$arr[1])[0];
        $userArray = json_decode($jsontrue);
        if (!array_key_exists('ProfilePage'$userArray['entry_data'])) {
            throw new Exception('Account with this username does not exist');
        }
        return new Account($userArray['entry_data']['ProfilePage'][0]['user']);
    }
@@ -26,7 +35,7 @@
        while ($index < $count && $isMoreAvailable) {
            $response = \Unirest\Request::get(self::INSTAGRAM_URL $username . '/media/?max_id=' $maxId);
            if ($response->code !== 200) {
                return [];
                throw new Exception('Response code is not equal 200. Something went wrong. Please report issue.');
            }
            $arr = json_decode($response->raw_bodytrue);
src/InstagramScraper/Media.php
@@ -1,4 +1,5 @@
<?php
namespace InstagramScraper;
class Media

Cherry-pick

Команда cherry-pick позволяет выбрать отдельные коммиты из одной ветки и применить их к другой.