-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bff85ec
Showing
22 changed files
with
623 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Lasse Rafn <lasserafn@gmail.com> | ||
|
||
> Permission is hereby granted, free of charge, to any person obtaining a copy | ||
> of this software and associated documentation files (the "Software"), to deal | ||
> in the Software without restriction, including without limitation the rights | ||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
> copies of the Software, and to permit persons to whom the Software is | ||
> furnished to do so, subject to the following conditions: | ||
> | ||
> The above copyright notice and this permission notice shall be included in | ||
> all copies or substantial portions of the Software. | ||
> | ||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
> THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "lasserafn/laravel-economic", | ||
"description": "Economic REST wrapper for Laravel", | ||
"keywords": ["laravel", "wrapper", "economic", "api", "integration", "e-conomic"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Lasse Rafn", | ||
"email": "lasserafn@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"illuminate/support": "5.1.*|5.2.*|5.3.*", | ||
"guzzlehttp/guzzle": "^6.2" | ||
}, | ||
"require-dev": { | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"LasseRafn\\Economic\\": "src" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Laravel Economic REST wrapper | ||
|
||
#Installation | ||
|
||
1. Require using composer | ||
```` | ||
composer require lasserafn/laravel-economic | ||
```` | ||
|
||
2. Add the EconomicServiceProvider to your ````config/app.php```` providers array. | ||
```` | ||
'providers' => [ | ||
\LasseRafn\Economic\EconomicServiceProvider::class, | ||
] | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Utils\Model; | ||
use LasseRafn\Economic\Utils\Request; | ||
|
||
class Builder | ||
{ | ||
private $request; | ||
protected $entity; | ||
|
||
/** @var Model */ | ||
protected $model; | ||
|
||
function __construct( Request $request ) | ||
{ | ||
$this->request = $request; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return mixed|Model | ||
*/ | ||
public function find($id) | ||
{//todo test | ||
$response = $this->request->curl->get( "/{$this->entity}/{$id}" ); | ||
|
||
// todo check for errors and such | ||
|
||
$responseData = json_decode( $response->getBody()->getContents() ); | ||
|
||
return new $this->model($this->request, $responseData); | ||
} | ||
|
||
public function first() | ||
{ | ||
$response = $this->request->curl->get( "/{$this->entity}?skippages=0&pagesize=1" ); | ||
|
||
// todo check for errors and such | ||
|
||
$responseData = json_decode( $response->getBody()->getContents() ); | ||
$fetchedItems = $responseData->collection; | ||
|
||
return new $this->model($this->request, $fetchedItems[0]); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Support\Collection|Model[] | ||
*/ | ||
public function get() | ||
{ | ||
$response = $this->request->curl->get( "/{$this->entity}" ); | ||
|
||
// todo check for errors and such | ||
|
||
$responseData = json_decode( $response->getBody()->getContents() ); | ||
$fetchedItems = $responseData->collection; | ||
|
||
$items = collect( [] ); | ||
foreach ( $fetchedItems as $item ) | ||
{ | ||
/** @var Model $model */ | ||
$model = new $this->model( $this->request, $item ); | ||
|
||
$items->push( $model ); | ||
} | ||
|
||
return $items; | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Support\Collection|Model[] | ||
*/ | ||
public function all() | ||
{ | ||
$page = 0; | ||
$pagesize = 500; // Yes, we could move this to 1000, but honestly I'd rather send two requests than stall their servers. | ||
$hasMore = true; | ||
$items = collect( [] ); | ||
|
||
while($hasMore) | ||
{ | ||
$response = $this->request->curl->get( "/{$this->entity}?skippages={$page}&pagesize={$pagesize}" ); | ||
|
||
// todo check for errors and such | ||
|
||
$responseData = json_decode( $response->getBody()->getContents() ); | ||
$fetchedItems = $responseData->collection; | ||
|
||
if( count($fetchedItems) == 0) | ||
{ | ||
$hasMore = false; | ||
|
||
break; | ||
} | ||
|
||
foreach ( $fetchedItems as $item ) | ||
{ | ||
/** @var Model $model */ | ||
$model = new $this->model( $this->request, $item ); | ||
|
||
$items->push( $model ); | ||
} | ||
|
||
$page++; | ||
} | ||
|
||
return $items; | ||
} | ||
|
||
public function create( $data) | ||
{ | ||
$response = $this->request->curl->post( "/{$this->entity}", [ | ||
'json' => $data | ||
] ); | ||
|
||
$responseData = json_decode( $response->getBody()->getContents() ); | ||
|
||
return new $this->model( $this->request, $responseData ); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\Contact; | ||
use LasseRafn\Economic\Utils\Request; | ||
|
||
class ContactBuilder extends Builder | ||
{ | ||
protected $entity = 'customers/:customerNumber/contacts'; | ||
protected $model = Contact::class; | ||
|
||
public function __construct( Request $request, $customerNumber ) | ||
{ | ||
$this->entity = str_replace(':customerNumber', $customerNumber, $this->entity); | ||
|
||
parent::__construct( $request ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\Customer; | ||
|
||
class CustomerBuilder extends Builder | ||
{ | ||
protected $entity = 'customers'; | ||
protected $model = Customer::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\CustomerGroup; | ||
|
||
class CustomerGroupBuilder extends Builder | ||
{ | ||
protected $entity = 'customer-groups'; | ||
protected $model = CustomerGroup::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\Layout; | ||
|
||
class LayoutBuilder extends Builder | ||
{ | ||
protected $entity = 'layouts'; | ||
protected $model = Layout::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\PaymentTerm; | ||
|
||
class PaymentTermBuilder extends Builder | ||
{ | ||
protected $entity = 'payment-terms'; | ||
protected $model = PaymentTerm::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php namespace LasseRafn\Economic\Builders; | ||
|
||
use LasseRafn\Economic\Models\VatZone; | ||
|
||
class VatZoneBuilder extends Builder | ||
{ | ||
protected $entity = 'vat-zones'; | ||
protected $model = VatZone::class; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php namespace LasseRafn\Economic; | ||
|
||
use LasseRafn\Economic\Builders\Builder; | ||
use LasseRafn\Economic\Builders\CustomerBuilder; | ||
use LasseRafn\Economic\Builders\CustomerGroupBuilder; | ||
use LasseRafn\Economic\Builders\LayoutBuilder; | ||
use LasseRafn\Economic\Builders\PaymentTermBuilder; | ||
use LasseRafn\Economic\Builders\VatZoneBuilder; | ||
use LasseRafn\Economic\Utils\Request; | ||
|
||
class Economic | ||
{ | ||
protected $request; | ||
|
||
public function __construct($agreement = '') | ||
{ | ||
$this->request = new Request($agreement); | ||
} | ||
|
||
public function getAuthUrl() | ||
{ | ||
return config('economic.auth_endpoint') . config('economic.public_token'); | ||
} | ||
|
||
/** | ||
* @return CustomerBuilder|Builder | ||
*/ | ||
public function customers() | ||
{ | ||
return new CustomerBuilder($this->request); | ||
} | ||
|
||
/** | ||
* @return CustomerGroupBuilder|Builder | ||
*/ | ||
public function customersGroups() | ||
{ | ||
return new CustomerGroupBuilder($this->request); | ||
} | ||
|
||
/** | ||
* @return LayoutBuilder|Builder | ||
*/ | ||
public function layouts() | ||
{ | ||
return new LayoutBuilder($this->request); | ||
} | ||
|
||
/** | ||
* @return VatZoneBuilder|Builder | ||
*/ | ||
public function vatZones() | ||
{ | ||
return new VatZoneBuilder($this->request); | ||
} | ||
|
||
/** | ||
* @return VatZoneBuilder|Builder | ||
*/ | ||
public function paymentTerms() | ||
{ | ||
return new PaymentTermBuilder($this->request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php namespace LasseRafn\Economic; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class EconomicServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Boot | ||
*/ | ||
public function boot() | ||
{ | ||
$configPath = __DIR__ . '/config/economic.php'; | ||
$this->mergeConfigFrom($configPath, 'economic'); | ||
|
||
$configPath = __DIR__ . '/config/economic.php'; | ||
|
||
if (function_exists('config_path')) { | ||
$publishPath = config_path('economic.php'); | ||
} else { | ||
$publishPath = base_path('config/economic.php'); | ||
} | ||
|
||
$this->publishes([$configPath => $publishPath], 'config'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php namespace LasseRafn\Economic\Models; | ||
|
||
use LasseRafn\Economic\Utils\Model; | ||
use LasseRafn\Economic\Utils\Request; | ||
|
||
class Contact extends Model | ||
{ | ||
protected $entity = 'customers/:customerNumber/contacts'; | ||
protected $primaryKey = 'customerContactNumber'; | ||
protected $fillable = [ | ||
'customerContactNumber', | ||
'self', | ||
'email', | ||
'phone', | ||
'name', | ||
'customer', | ||
]; | ||
|
||
public $customerContactNumber; | ||
public $self; | ||
public $phone; | ||
public $email; | ||
public $name; | ||
|
||
/** @var Customer $customer */ | ||
public $customer; | ||
|
||
public function __construct( Request $request, array $data ) | ||
{ | ||
\Log::info($data['customer']); | ||
$this->entity = str_replace(':customerNumber', $data['customer']->customerNumber, $this->entity); | ||
|
||
parent::__construct( $request, $data ); | ||
} | ||
} |
Oops, something went wrong.