Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhall17 committed Sep 8, 2020
2 parents 4cbb069 + 68dd1d2 commit f12b734
Show file tree
Hide file tree
Showing 44 changed files with 843 additions and 816 deletions.
2 changes: 0 additions & 2 deletions src/Contracts/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

interface Entry
{

public function getNode($key);

public function getRequest() ;

public function setRequest($request);

public function newRequest();

}
3 changes: 1 addition & 2 deletions src/Contracts/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface Relation
{

}
}
7 changes: 3 additions & 4 deletions src/Dev/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

class Address extends Resource
{
protected $storeResource = 'MacsiDigital\API\Dev\Resources\StoreAddress';
protected $storeResource = 'MacsiDigital\API\Dev\Resources\StoreAddress';
protected $updateResource = 'MacsiDigital\API\Dev\Resources\UpdateAddress';

public function user()
public function user()
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class);
}

}
3 changes: 1 addition & 2 deletions src/Dev/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public function newRequest()
return Client::baseUrl(config('api.base_url'))->withOptions(config('api.options'));
}

public function setConfig()
public function setConfig()
{
// Normally you would use a proper config file but for our tests we will include it
$config = include 'config.php';
config($config);
}

}
8 changes: 3 additions & 5 deletions src/Dev/Resources/StoreAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

class StoreAddress extends PersistResource
{

protected $persistAttributes = [
'street' => 'required|string|max:255',
'town' => 'required|string|max:255',
'postcode' => 'required|string|max:10',
'street' => 'required|string|max:255',
'town' => 'required|string|max:255',
'postcode' => 'required|string|max:10',
];

}
13 changes: 6 additions & 7 deletions src/Dev/Resources/StoreUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
class StoreUser extends PersistResource
{
protected $persistAttributes = [
'name' => 'required|string|max:255',
'email' => 'required|email|string|max:255',
'password' => 'required|string|max:10',
'address.street' => 'string|max:255',
'address.town' => 'string|max:255',
'address.postcode' => 'string|max:10',
'name' => 'required|string|max:255',
'email' => 'required|email|string|max:255',
'password' => 'required|string|max:10',
'address.street' => 'string|max:255',
'address.town' => 'string|max:255',
'address.postcode' => 'string|max:10',
];

}
8 changes: 3 additions & 5 deletions src/Dev/Resources/UpdateAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

class UpdateAddress extends PersistResource
{

protected $persistAttributes = [
'street' => 'required|string|max:255',
'town' => 'required|string|max:255',
'postcode' => 'required|string|max:10',
'street' => 'required|string|max:255',
'town' => 'required|string|max:255',
'postcode' => 'required|string|max:10',
];

}
13 changes: 6 additions & 7 deletions src/Dev/Resources/UpdateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
class UpdateUser extends PersistResource
{
protected $persistAttributes = [
'name' => 'string|max:255',
'email' => 'email|string|max:255',
'password' => 'string|max:10',
'address.street' => 'string|max:255',
'address.town' => 'string|max:255',
'address.postcode' => 'string|max:10',
'name' => 'string|max:255',
'email' => 'email|string|max:255',
'password' => 'string|max:10',
'address.street' => 'string|max:255',
'address.town' => 'string|max:255',
'address.postcode' => 'string|max:10',
];

protected $relatedResource = [
// 'address' => '\MacsiDigital\API\Dev\Resources\UpdateAddress'
];

}
7 changes: 3 additions & 4 deletions src/Dev/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

class User extends Resource
{
protected $storeResource = 'MacsiDigital\API\Dev\Resources\StoreUser';
protected $storeResource = 'MacsiDigital\API\Dev\Resources\StoreUser';
protected $updateResource = 'MacsiDigital\API\Dev\Resources\UpdateUser';

public function address()
public function address()
{
return $this->hasOne(Address::class);
return $this->hasOne(Address::class);
}

}
12 changes: 6 additions & 6 deletions src/Dev/config.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

return [
'api' => [
'base_url' => 'http://playground.test/api/',
'options' => [
'api' => [
'base_url' => 'http://playground.test/api/',
'options' => [

]
]
];
],
],
];
3 changes: 1 addition & 2 deletions src/Exceptions/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class Base extends Exception
{

}
}
4 changes: 2 additions & 2 deletions src/Exceptions/CantDeleteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class CantDeleteException extends Base
{
public function __construct($class, $key)
public function __construct($class, $key)
{
parent::__construct('There was an error deleting '.$class.' with a key of '.$key);
}
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/HttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class HttpException extends Exception
{
public function __construct($code = 0, $message, \Throwable $previous = null)
{
parent::__construct('HTTP Request returned Status Code '.$code.'. '.$message);
parent::__construct('HTTP Request returned Status Code '.$code.'. '.$message);
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/IncorrectRelationshipModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

class IncorrectRelationshipModel extends Base
{
public function __construct($related, $object)
public function __construct($related, $object)
{
parent::__construct('The relation must be of class '.get_class($related).', '.get_class($object).' passed.');
}
}

2 changes: 1 addition & 1 deletion src/Exceptions/InvalidActionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
class InvalidActionException extends Exception
{
//
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/JsonEncodingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public static function forAttribute($model, $key, $message)

return new static("Unable to encode attribute [{$key}] for model [{$class}] to JSON: {$message}.");
}
}
}
10 changes: 5 additions & 5 deletions src/Exceptions/KeyNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class KeyNotFoundException extends Base
{
public function __construct($class)
{
parent::__construct('Priamry key for '.$class.' not set, so cant perform this action.');
}
}
public function __construct($class)
{
parent::__construct('Priamry key for '.$class.' not set, so cant perform this action.');
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/ModelNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ public function getIds()
{
return $this->ids;
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/NodeNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class NodeNotFoundException extends Base
{

}
}
2 changes: 1 addition & 1 deletion src/Exceptions/NotAPersistableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class NotAPersistableModel extends Base
{
public function __construct($related)
public function __construct($related)
{
parent::__construct(get_class($related).' cannot be saved directly to the API. It needs to be saved as part of its parent.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/OutOfResultSetException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class OutOfResultSetException extends Base
{
public function __construct()
public function __construct()
{
parent::__construct('You are trying to retrieve results outside of the available results.');
}
}
}
4 changes: 2 additions & 2 deletions src/Exceptions/RelationAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class RelationAlreadyExistsException extends Base
{
public function __construct($owner, $related)
public function __construct($owner, $related)
{
parent::__construct(get_class($owner).' already has a set relationship from '.get_class($related).' this is a One relationship and cna only have 1 set relation.');
}
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/RequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public function __construct(Response $response)

$this->response = $response;
}
}
}
3 changes: 1 addition & 2 deletions src/Exceptions/ValidationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

class ValidationFailedException extends Exception
{

public function __construct($error)
{
parent::__construct('You have validation errors:- '.implode(', ', $error->all()));
}
}
}
7 changes: 2 additions & 5 deletions src/Providers/APIServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace MacsiDigital\API\Providers;

use MacsiDigital\API\Dev\User;
use MacsiDigital\API\Support\Entry;
use Illuminate\Support\ServiceProvider;
use MacsiDigital\API\Support\Entry;

class APIServiceProvider extends ServiceProvider
{
public function boot()
public function boot()
{

}

/**
Expand All @@ -26,6 +24,5 @@ public function register()
// $this->app->bind(Entry::class, function ($app) {
// return new Entry();
// });

}
}
5 changes: 2 additions & 3 deletions src/Support/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@

class ApiResource extends Resource
{
use InteractsWithAPI;

}
use InteractsWithAPI;
}
4 changes: 2 additions & 2 deletions src/Support/Authentication/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public static function generateToken($token, $secret)

public static function decodeToken($jwt, $secret)
{
return FirebaseJWT::decode($jwt, $secret, array('HS256'));
return FirebaseJWT::decode($jwt, $secret, ['HS256']);
}
}
}
2 changes: 1 addition & 1 deletion src/Support/Authentication/OAuth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public static function generate($options)
{
return new GuzzleOauth1($options);
}
}
}
Loading

0 comments on commit f12b734

Please sign in to comment.