Skip to content

Commit 4ef0e56

Browse files
Merge pull request #2 from tombabolewski/develop
Develop
2 parents 7103fc3 + 4e5be8c commit 4ef0e56

18 files changed

Lines changed: 320 additions & 86 deletions

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
11
# openiai
2+
3+
*Version:* `0.1.3`
4+
5+
This library is yet unfinished. Use it only at your own risk.
6+
Feel free to contribute.
7+
8+
9+
## Summary
10+
211
Open IAI API PHP wrapper library.
12+
13+
This is a Laravel library that lets you easily connect to IdoSell Shop API
14+
and make requests. It aims to cover the whole API (all gates and methods,
15+
which are automatically looked for).
16+
17+
18+
## Requirements
19+
* PHP 7.2
20+
* Laravel 5.8
21+
* ext-json
22+
* ext-soap
23+
24+
## Installation
25+
26+
Simply use Composer to install this package, either by executing CLI command
27+
in your project directory:
28+
29+
```bash
30+
composer require tombabolewski/openiai
31+
```
32+
33+
or by adding the following line to your `composer.json` file in `require`
34+
section:
35+
36+
```json
37+
"require" : {
38+
"tombabolewski/openiai" : "^0.1.3"
39+
}
40+
```
41+
42+
Next, you should add the Service Provider to your `config/app.php` file.
43+
Just add the following line to the `providers` array, preferably at the end:
44+
45+
```php
46+
'providers' => [
47+
// (...)
48+
Tombabolewski/Openiai/OpeniaiServiceProvider::class,
49+
],
50+
```
51+
52+
If you would like, you can also add an alias to the `aliases` array like that:
53+
```php
54+
'aliases' => [
55+
// (...)
56+
'Openiai' => Tombabolewski/Openiai/Client::class
57+
],
58+
```
59+
60+
61+
## Usage
62+
63+
Section under construction ;]
64+
65+
Example:
66+
```php
67+
//Create openiai client instance
68+
$client = app()->make('Openiai');
69+
70+
//Get all products
71+
$products = $client->Products->get();
72+
```

composer.json

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
{
2-
"name": "tombabolewski/openiai",
3-
"description": "Open IAI API PHP wrapper library",
4-
"type": "library",
5-
"support": {
6-
"source": "https://github.com/tombabolewski/openiai",
7-
"issues": "https://github.com/ltombabolewski/openiai/issues"
8-
},
9-
"require": {
10-
"php": ">=7.1",
11-
"ext-json": "*",
12-
"laravel/laravel": "5.8",
13-
"league/csv": "^9.3",
14-
"guzzle/http": "^3.9"
15-
},
16-
"license": "MIT",
17-
"authors": [
18-
{
19-
"name": "Thomas Lucifer Babolewski",
20-
"email": "spootek@gmail.com"
21-
}
22-
],
23-
"autoload": {
24-
"psr-4": {
25-
"Tombabolewski\\Openiai\\": "src/"
26-
}
27-
},
28-
"extra": {
29-
"laravel" : {
30-
"providers": [
31-
"Tomabolewski\\Openiai\\Providers\\openiaiServiceProvider"
32-
]
33-
}
2+
"name": "tombabolewski/openiai",
3+
"description": "Open IAI API PHP wrapper library",
4+
"type": "library",
5+
"support": {
6+
"source": "https://github.com/tombabolewski/openiai",
7+
"issues": "https://github.com/tombabolewski/openiai/issues"
8+
},
9+
"require": {
10+
"php": ">=7.2",
11+
"ext-json": "*",
12+
"laravel/laravel": "5.8",
13+
"league/csv": "^9.3",
14+
"guzzle/http": "^3.9"
15+
},
16+
"license": "MIT",
17+
"authors": [
18+
{
19+
"name": "Tomasz Babolewski",
20+
"email": "spootek@gmail.com"
3421
}
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"Tombabolewski\\Openiai\\": "src/"
26+
}
27+
},
28+
"extra": {
29+
"laravel": {
30+
"providers": [
31+
"Tombabolewski\\Openiai\\OpeniaiServiceProvider"
32+
],
33+
"aliases": {
34+
"OpenIAI": "Tombabolewski\\Openiai\\Facade"
35+
}
36+
}
37+
}
3538
}

src/ApiGate.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/ApiMethod.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/ApiVersion.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Client.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@
33

44
namespace Tombabolewski\Openiai;
55

6-
use Guzzle\Http\Client as HttpClient;
6+
use Tombabolewski\Openiai\Structure\ApiVersion;
77

88
class Client
99
{
10-
public function __construct()
10+
protected $version;
11+
12+
public function __construct($version = 0)
1113
{
14+
if (!$version) {
15+
$version = config('API_DEFAULT_VERSION');
16+
}
17+
$this->setVersion($version);
18+
}
1219

20+
public function setVersion($versionSignature)
21+
{
22+
$this->version = new ApiVersion($versionSignature);
1323
}
1424
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33

4-
namespace Tombabolewski\Openiai;
4+
namespace Tombabolewski\Openiai\Exception;
55
use Exception;
66

77
class ApiException extends Exception

src/Facade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class Facade extends BaseFacade
1010
{
1111
public static function getFacadeAccessor()
1212
{
13-
return 'IAI';
13+
return 'openiai';
1414
}
1515
}

src/OpeniaiServiceProvider.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace App\Providers;
44

55
use Illuminate\Support\ServiceProvider;
6+
use Tombabolewski\Openiai\Client;
67

7-
class openiaiServiceProvider extends ServiceProvider
8+
class OpeniaiServiceProvider extends ServiceProvider
89
{
910
/**
1011
* Register services.
@@ -13,7 +14,7 @@ class openiaiServiceProvider extends ServiceProvider
1314
*/
1415
public function register()
1516
{
16-
//
17+
$this->mergeConfigFrom(__DIR__ . '/config/openiai.php', 'openiai');
1718
}
1819

1920
/**
@@ -23,6 +24,11 @@ public function register()
2324
*/
2425
public function boot()
2526
{
26-
//
27+
$this->publishes([
28+
__DIR__ . '/config/openiai.php' => config_path('openiai.php'),
29+
]);
30+
$this->app->bind('openiai', function ($app) {
31+
return new Client();
32+
});
2733
}
2834
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33

4-
namespace Tombabolewski\Openiai;
4+
namespace Tombabolewski\Openiai\Response;
55

66

77
use Exception;
@@ -53,7 +53,7 @@ public function offsetGet($offset)
5353
if (!$this->offsetExists($offset)) {
5454
throw new Exception('Offset does not exist');
5555
}
56-
if ($this->current()->getPage() === $offset) {
56+
if ($this->current()->getPage() !== $offset) {
5757
$this->currentPage = $this->getParentMethod()->exec($offset, $this->requestParams);
5858
}
5959
return $this->current();
@@ -114,8 +114,9 @@ public function current()
114114
public function next()
115115
{
116116
$nextPage = $this->getParentMethod()->getPage() + 1;
117-
if (!$this->offsetExists($nextPage))
118-
$this->currentPage = $this->getParentMethod()->exec($nextPage, $this->requestParams);
117+
if (!$this->offsetExists($nextPage)){
118+
$this->currentPage = $this->getParentMethod()->exec($nextPage, $this->requestParams);
119+
}
119120
}
120121

121122
/**
@@ -138,7 +139,8 @@ public function key()
138139
*/
139140
public function valid()
140141
{
141-
return isset($this->currentPage) && !is_null($this->currentPage);
142+
return isset($this->currentPage)
143+
&& !is_null($this->currentPage);
142144
}
143145

144146
/**

0 commit comments

Comments
 (0)