2017 © Pedro Peláez
 

library wyszukiwarkaregon

Polish REGON Internet Database

image

freshmindpl/wyszukiwarkaregon

Polish REGON Internet Database

  • Monday, August 22, 2016
  • by krzaczek
  • Repository
  • 3 Watchers
  • 14 Stars
  • 7,390 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 11 Versions
  • 8 % Grown

The README.md

Polish REGON Internet Database BIR1

PHP bindings for the BIR1 (Baza Internetowa REGON 1) API (https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx)., (*1)

API Documentation, (*2)

Latest Stable Version Build Status Code Climate Test Coverage, (*3)

Installation

The API client can be installed via Composer., (*4)

In your composer.json file:, (*5)

{
    "require": {
        "freshmindpl/wyszukiwarkaregon": "~3.0"
    }
}

Once the composer.json file is created you can run composer install for the initial package install and composer update to update to the latest version of the API client., (*6)

Basic Usage

Remember to include the Composer autoloader in your application:, (*7)


Configure your access credentials when creating a client:, (*8)

 'aaaabbbbccccdddd' //Optional api key - required for full reports,
   'session' => 'abcdefghijklmnopqrstuvwxyz' //Session id if already logged in
]);
?>

Local Testing

Run phpunit from the project root to start all tests., (*9)

Examples

Login

login();
} catch (RegonException $e) {
    echo "There was an error.\n";
}

if(empty($session_id)) {
    // Empty session means that api key is invalid
    
    throw new \Exception('Invalid api key');
}

```

#### Logout

```php
login();
} catch (RegonException $e) {
    echo "There was an error.\n";
}

....

// Invalidate current session
$client->logout();

```

#### GetValue

See [API Documentation](https://goo.gl/zxBf2o) for list of available params (section 2.5)
```php
getValue('StatusSesji');
} catch (RegonException $e) {
    echo "There was an error.\n";
}

?>
<?php

$params = [
    'Regon' => 142396858, // 9 or 14 digits
    'Krs' => null, // 10 digits
    'Nip' => null, // 10 digits
    'Regony9zn' => null, // Multiple 9 digits Regon's seperated by any non digit char (max 100)
    'Regony14zn' => null, // Multiple 14 digits Regon's seperated by any non digit char (max 100)
    'Krsy' => null, // Multiple 10 digits Krs seperated by any non digit char (max 100)
    'Nipy' => null, // Multiple 10 digits Nip seperated by any non digit char (max 100)
];

try {
    $data = $client->search($params);

} catch (SearchException $e) {
    switch($e->getCode()) {
        case GetValue::SEARCH_ERROR_CAPTCHA: //Captcha resolve needed
            // Some code
            break;
        case GetValue::SEARCH_ERROR_INVALIDARGUMENT: //Wrong search params
            // Some code
            break;
        case GetValue::SEARCH_ERROR_NOTFOUND: //Empty result - no data found matching search params
            // Some code
            break;
        case GetValue::SEARCH_ERROR_SESSION: //Wrong session id or expired session
            // Some code
            break;
    }
} catch (RegonException $e) {
    echo "There was an error.\n";
}

Reports

See API Documentation for list of available reports (section 2.6), (*10)

<?php

$regon = '1234567890';

try {
    $report = $client->report($regon, 'PublDaneRaportFizycznaOsoba'); 

} catch (SearchException $e) {
    switch($e->getCode()) {
        case GetValue::SEARCH_ERROR_CAPTCHA: //Captcha resolve needed
            // Some code
            break;
        case GetValue::SEARCH_ERROR_INVALIDARGUMENT: //Wrong search params
            // Some code
            break;
        case GetValue::SEARCH_ERROR_NOTFOUND: //Empty result - no data found matching search params
            // Some code
            break;
        case GetValue::SEARCH_ERROR_NOTAUTHORIZED: //Not authorized for this raport
            // Some code
            break;
        case GetValue::SEARCH_ERROR_SESSION: //Wrong session id or expired session
            // Some code
            break;
    }
} catch (RegonException $e) {
    echo "There was an error.\n";
}

Full example

This is a working example on how to use GUS client to query for data, (*11)

<?php

$client = new Client([
    'key' => YOUR_API_KEY
]);

//Enable sandbox mode for development environment
if (defined('DEVELOPMENT') && DEVELOPMENT) {
    $client->sandbox();
}

//Check if we have saved session id
$session_id = $memcache->get('gus_session_id');

if (!$session_id) {
    try {
        $session_id = $client->login();
    } catch (RegonException $e) {
        echo "There was an error.\n";
        exit;
    }

    //Save session_id for later use
    $memcache->save('gus_session_id', $session_id); 
} else {

    //Set current session
    $client->setSession($session_id);
}

//Try to get data
try {

    //Get basic data
    $data = $client->search(['Nip' => '1234567890']);

    //Get full comapny report
    switch($data[0]['Typ']) {
        case 'P':
        case 'LP':
            $full = $client->report($data[0]['Regon'], 'PublDaneRaportPrawna');
        break;

        case 'F':
        case 'LF':
            $full = $client->report($data[0]['Regon'], 'PublDaneRaportDzialalnoscFizycznejCeidg');
        break;
    }
} catch (SearchException $e) {
    switch($e->getCode()) {
        case GetValue::SEARCH_ERROR_CAPTCHA: //Captcha resolve needed
            // You need to get catpcha and show it to the user
            break;
        case GetValue::SEARCH_ERROR_INVALIDARGUMENT: //Wrong search params
            // Invalid argument passed to search/report method
            break;
        case GetValue::SEARCH_ERROR_NOTFOUND: //Empty result - no data found matching search params
            // No records where found
            $data = null;
            $full = null;
            break;
        case GetValue::SEARCH_ERROR_NOTAUTHORIZED: //Not authorized for this raport
            // You are not authorized to generate this report
            break;
        case GetValue::SEARCH_ERROR_SESSION: //Wrong session id or expired session
            // Your session has expired - You need to login again
            break;
    }
} catch (RegonException $e) {
    echo "There was an error.\n";
    exit;
}

License

MIT license. See the LICENSE file for more details., (*12)

The Versions

22/08 2016

dev-master

9999999-dev https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

21/03 2016

3.0.2

3.0.2.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

02/01 2016

3.0.1

3.0.1.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

02/01 2016

dev-xml2array

dev-xml2array https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

31/12 2015

v3.0.0

3.0.0.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

30/12 2015

3.0.0-beta.1

3.0.0.0-beta1 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0
  • ext-soap *

 

The Development Requires

api regon nip gus ceidg bir1

31/08 2015

2.1.0

2.1.0.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

regon nip gus ceidg

28/05 2015

2.0.1

2.0.1.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

regon nip gus ceidg

18/05 2015

2.0.0

2.0.0.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

regon nip gus ceidg

08/05 2015

1.0.1

1.0.1.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

Polish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

regon nip gus ceidg

27/01 2015

1.0.0

1.0.0.0 https://wyszukiwarkaregon.stat.gov.pl/appBIR/index.aspx

BPolish REGON Internet Database

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

regon nip gus ceidg