diff --git a/src/Api.php b/src/Api.php index 598db63..b078d2a 100644 --- a/src/Api.php +++ b/src/Api.php @@ -9,6 +9,7 @@ use App\Nami\Exceptions\TooManyLoginAttemptsException; use Illuminate\Support\Facades\Http; use Illuminate\Support\Collection; use Zoomyboy\LaravelNami\Backend\Backend; +use Zoomyboy\LaravelNami\Concerns\IsNamiMember; class Api { @@ -64,13 +65,9 @@ class Api { return collect($this->http()->get(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist')->json()['data']); } - public function putMember(Member $member) { - $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, [ - 'vorname' => $member->firstname, - 'nachname' => $member->lastname, - 'spitzname' => $member->nickname ?: '', - 'geschlechtId' => $member->gender_id ?: Gender::getNullValue(), - ]); + public function putMember(array $attributes) { + $member = Member::fromAttributes($attributes); + $this->http()->put(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->group_id.'/'.$member->id, $member->toNami()); } public function membershipsOf($memberId): Collection { diff --git a/src/Member.php b/src/Member.php index de74a92..636e2f8 100644 --- a/src/Member.php +++ b/src/Member.php @@ -64,6 +64,19 @@ class Member extends Model { return (new self($item)); } + public static function fromAttributes($attributes) { + return new self($attributes); + } + + public function toNami() { + return [ + 'vorname' => $this->firstname, + 'nachname' => $this->lastname, + 'spitzname' => $this->nickname ?: '', + 'geschlechtId' => $this->gender_id ?: Gender::getNullValue(), + ]; + } + public function __construct($member) { parent::__construct($member); } @@ -110,8 +123,4 @@ class Member extends Model { return Membership::fromNami(Nami::membership($this->id, $id)); } - public function store() { - app('nami.api')->putMember($this); - } - } diff --git a/tests/Unit/PushMemberTest.php b/tests/Unit/PushMemberTest.php index 84bdef3..4dc82d6 100644 --- a/tests/Unit/PushMemberTest.php +++ b/tests/Unit/PushMemberTest.php @@ -10,6 +10,7 @@ use Zoomyboy\LaravelNami\NamiServiceProvider; use Zoomyboy\LaravelNami\LoginException; use Zoomyboy\LaravelNami\Group; use Zoomyboy\LaravelNami\Member; +use Illuminate\Database\Eloquent\Model; class PushMemberTest extends TestCase { @@ -74,11 +75,8 @@ class PushMemberTest extends TestCase $this->setCredentials(); Nami::login(); - $member1 = new Member($this->attributes[0]); - $member2 = new Member($this->attributes[1]); - - $member1->store(); - $member2->store(); + Nami::putMember($this->attributes[0]); + Nami::putMember($this->attributes[1]); Http::assertSent(function($request) use ($key, $values) { return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16'