Skip to content

Commit

Permalink
Enable interface to code tables
Browse files Browse the repository at this point in the history
  • Loading branch information
bdgregg authored and ctgraham committed Nov 16, 2020
1 parent 536c67f commit 4f3bb4c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Scriptotek\Alma\Conf\Jobs;
use Scriptotek\Alma\Conf\Libraries;
use Scriptotek\Alma\Conf\Library;
use Scriptotek\Alma\Conf\CodeTables;
use Scriptotek\Alma\Exception\ClientException as AlmaClientException;
use Scriptotek\Alma\Exception\InvalidApiKey;
use Scriptotek\Alma\Exception\MaxNumberOfAttemptsExhausted;
Expand Down Expand Up @@ -103,6 +104,11 @@ class Client
*/
public $jobs;

/**
* @var CodeTables
*/
public $codetables;

/**
* @var TaskLists
*/
Expand Down Expand Up @@ -152,6 +158,7 @@ public function __construct(
$this->conf = new Conf($this);
$this->libraries = $this->conf->libraries; // shortcut
$this->jobs = $this->conf->jobs; // shortcut
$this->codetables = $this->conf->codetables; // shortcut

$this->taskLists = new TaskLists($this);

Expand Down
49 changes: 49 additions & 0 deletions src/Conf/CodeTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Scriptotek\Alma\Conf;

use Scriptotek\Alma\Client;
use Scriptotek\Alma\Model\LazyResource;

/**
* A single CodeTable resource.
*/
class CodeTable extends LazyResource
{
/** @var string */
public $code;

/**
* CodeTable constructor.
*
* @param Client $client
* @param string $code
*/
public function __construct(Client $client, $code)
{
parent::__construct($client);
$this->code = $code;
}

/**
* Check if we have the full representation of our data object.
*
* @param \stdClass $data
*
* @return bool
*/
protected function isInitialized($data)
{
return isset($data->name);
}

/**
* Generate the base URL for this resource.
*
* @return string
*/
protected function urlBase()
{
return "/conf/code-tables/{$this->code}";
}
}
38 changes: 38 additions & 0 deletions src/Conf/CodeTables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Scriptotek\Alma\Conf;

use Scriptotek\Alma\Client;
use Scriptotek\Alma\Model\ReadOnlyArrayAccess;

/**
* A non-iterable collection of CodeTable resources
*/
class CodeTables implements \ArrayAccess
{
use ReadOnlyArrayAccess;

protected $client;

/**
* CodeTables constructor.
*
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}

/**
* Get a CodeTable by identifier
*
* @param $code The identifier of a CodeTable
*
* @return CodeTable
*/
public function get($code)
{
return CodeTable::make($this->client, $code);
}
}
1 change: 1 addition & 0 deletions src/Conf/Conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public function __construct(Client $client)
$this->client = $client;
$this->libraries = new Libraries($client);
$this->jobs = new Jobs($client);
$this->codetables = new CodeTables($client);
}
}

0 comments on commit 4f3bb4c

Please sign in to comment.