Skip to content

Commit 2f310dc

Browse files
authored
Add Jobs and JobInstances (#19)
1 parent 8a6c4e9 commit 2f310dc

13 files changed

+584
-0
lines changed

spec/Conf/JobInstanceSpec.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Conf;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Scriptotek\Alma\Client as AlmaClient;
7+
use Scriptotek\Alma\Conf\Job;
8+
use Scriptotek\Alma\Conf\JobInstance;
9+
10+
class JobInstanceSpec extends ObjectBehavior
11+
{
12+
public function let(AlmaClient $client, Job $job)
13+
{
14+
$instanceId = '1108569450000121';
15+
$this->beConstructedWith($client, $job, $instanceId);
16+
}
17+
18+
public function it_is_initializable()
19+
{
20+
$this->shouldHaveType(JobInstance::class);
21+
}
22+
23+
public function it_should_belong_to_a_job()
24+
{
25+
$this->job->shouldBeAnInstanceOf(Job::class);
26+
}
27+
}

spec/Conf/JobInstancesSpec.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Conf;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Scriptotek\Alma\Client as AlmaClient;
7+
use Scriptotek\Alma\Conf\Job;
8+
use Scriptotek\Alma\Conf\JobInstance;
9+
use spec\Scriptotek\Alma\SpecHelper;
10+
11+
class JobInstancesSpec extends ObjectBehavior
12+
{
13+
public function let(AlmaClient $client, Job $job)
14+
{
15+
$job->job_id = '1108569450000121';
16+
$this->beConstructedWith($client, $job);
17+
}
18+
19+
public function it_provides_a_lazy_interface_to_jobinstance_objects(AlmaClient $client)
20+
{
21+
SpecHelper::expectNoRequests($client);
22+
23+
$jobId = '1108569450000121';
24+
$instanceId = '1108569450000121';
25+
$jobInstance = $this->get($jobId, $instanceId);
26+
$jobInstance->shouldBeAnInstanceOf(JobInstance::class);
27+
}
28+
29+
public function it_provides_jobintances(AlmaClient $client)
30+
{
31+
$jobId = '1108569450000121';
32+
$client->getJSON("/conf/jobs/{$jobId}/instances")
33+
->shouldBeCalled()
34+
->willReturn(SpecHelper::getDummyData('jobinstances_response.json'));
35+
36+
$this->all()->shouldBeArray();
37+
$this->all()[0]->shouldBeAnInstanceOf(JobInstance::class);
38+
}
39+
}

spec/Conf/JobSpec.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Conf;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Scriptotek\Alma\Client as AlmaClient;
7+
use Scriptotek\Alma\Conf\Job;
8+
use spec\Scriptotek\Alma\SpecHelper;
9+
10+
class JobSpec extends ObjectBehavior
11+
{
12+
public function let(AlmaClient $client)
13+
{
14+
$this->beConstructedWith($client, 'M26714670000011');
15+
16+
$client->getJSON('/conf/jobs/M26714670000011')
17+
->willReturn(SpecHelper::getDummyData('job_response.json'));
18+
$client->postJSON('/conf/jobs/M26714670000011?op=run')
19+
->willReturn(SpecHelper::getDummyData('job_response.json'));
20+
}
21+
22+
public function it_is_initializable()
23+
{
24+
$this->shouldHaveType(Job::class);
25+
}
26+
}

spec/Conf/JobsSpec.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace spec\Scriptotek\Alma\Conf;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Scriptotek\Alma\Client as AlmaClient;
7+
use Scriptotek\Alma\Conf\Job;
8+
use spec\Scriptotek\Alma\SpecHelper;
9+
10+
class JobsSpec extends ObjectBehavior
11+
{
12+
public function let(AlmaClient $client)
13+
{
14+
$this->beConstructedWith($client);
15+
$client->getJSON('/conf/jobs')
16+
->willReturn(SpecHelper::getDummyData('jobs_response.json'));
17+
}
18+
19+
public function it_provides_a_lazy_interface_to_job_objects(AlmaClient $client)
20+
{
21+
SpecHelper::expectNoRequests($client);
22+
23+
$job_id = 'M26714670000011';
24+
$job = $this->get($job_id);
25+
26+
$job->shouldBeAnInstanceOf(Job::class);
27+
$job->job_id->shouldBe($job_id);
28+
}
29+
30+
public function it_provides_jobs()
31+
{
32+
$this->all()->shouldBeArray();
33+
$this->all()[0]->shouldBeAnInstanceOf(Job::class);
34+
}
35+
}

spec/data/job_response.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"link": "string",
3+
"id": "M26714670000011",
4+
"name": "Export Physical Items",
5+
"description": "Export Physical Items",
6+
"type": {
7+
"desc": "Manual",
8+
"value": "MANUAL"
9+
},
10+
"category": {
11+
"desc": "Normalization",
12+
"value": "NORMALIZATION"
13+
},
14+
"content": {
15+
"desc": "All Titles",
16+
"value": "BIB_MMS"
17+
},
18+
"schedule": {
19+
"desc": "Not scheduled",
20+
"value": "NOT_SCHEDULED"
21+
},
22+
"creator": "string",
23+
"next_run": "2024-05-30T09:30:10Z",
24+
"parameter": [
25+
{
26+
"name": {
27+
"desc": "string",
28+
"value": "string"
29+
},
30+
"value": "string"
31+
}
32+
],
33+
"related_profile": {
34+
"link": "string",
35+
"value": "ID123"
36+
},
37+
"additional_info": {
38+
"link": "string",
39+
"value": "string"
40+
}
41+
}

spec/data/jobinstance_response.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"link": "string",
3+
"id": "1108569450000121",
4+
"external_id": "1108569450000121",
5+
"name": "Export Physical Items - war and love - 04/15/2015 16:07",
6+
"submitted_by": {
7+
"desc": "string",
8+
"value": "exl_impl"
9+
},
10+
"submit_time": "2015-04-15T13:07:40.800Z",
11+
"start_time": "2015-04-15T13:07:40.868Z",
12+
"end_time": "2015-04-15T13:07:44.359Z",
13+
"progress": 100,
14+
"status": {
15+
"desc": "string",
16+
"value": "QUEUED"
17+
},
18+
"status_date": "2015-07-20",
19+
"alert": [
20+
{
21+
"desc": "string",
22+
"value": "alert_general_success"
23+
}
24+
],
25+
"counter": [
26+
{
27+
"type": {
28+
"desc": "string",
29+
"value": "4"
30+
},
31+
"value": "string"
32+
}
33+
],
34+
"action": [
35+
"string"
36+
],
37+
"job_info": {
38+
"link": "string",
39+
"id": "1108569450000121",
40+
"name": "Export Physical Items - war and love - 04/15/2015 16:07",
41+
"description": "string",
42+
"type": {
43+
"desc": "string",
44+
"value": "CREATE_SET"
45+
},
46+
"category": {
47+
"desc": "string",
48+
"value": "NORMALIZATION"
49+
}
50+
}
51+
}

spec/data/jobinstances_response.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"total_record_count": 1,
3+
"job_instance": [
4+
{
5+
"link": "string",
6+
"id": "1108569450000121",
7+
"external_id": "1108569450000121",
8+
"name": "Export Physical Items - war and love - 04/15/2015 16:07",
9+
"submitted_by": {
10+
"desc": "string",
11+
"value": "exl_impl"
12+
},
13+
"submit_time": "2015-04-15T13:07:40.800Z",
14+
"start_time": "2015-04-15T13:07:40.868Z",
15+
"end_time": "2015-04-15T13:07:44.359Z",
16+
"progress": 100,
17+
"status": {
18+
"desc": "string",
19+
"value": "QUEUED"
20+
},
21+
"status_date": "2015-07-20",
22+
"alert": [
23+
{
24+
"desc": "string",
25+
"value": "alert_general_success"
26+
}
27+
],
28+
"counter": [
29+
{
30+
"type": {
31+
"desc": "string",
32+
"value": "4"
33+
},
34+
"value": "string"
35+
}
36+
],
37+
"action": [
38+
{
39+
"link": "string",
40+
"type": {
41+
"desc": "string",
42+
"value": "CREATE_SET"
43+
},
44+
"population": {
45+
"desc": "string",
46+
"value": "string"
47+
},
48+
"members": 0
49+
}
50+
],
51+
"job_info": {
52+
"link": "string",
53+
"id": "1108569450000121",
54+
"name": "Export Physical Items - war and love - 04/15/2015 16:07",
55+
"description": "string",
56+
"type": {
57+
"desc": "string",
58+
"value": "CREATE_SET"
59+
},
60+
"category": {
61+
"desc": "string",
62+
"value": "NORMALIZATION"
63+
}
64+
}
65+
}
66+
]
67+
}

spec/data/jobs_response.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"total_record_count": 1,
3+
"job": [
4+
{
5+
"link": "string",
6+
"id": "M26714670000011",
7+
"name": "Export Physical Items",
8+
"description": "Export Physical Items",
9+
"type": {
10+
"desc": "Manual",
11+
"value": "MANUAL"
12+
},
13+
"category": {
14+
"desc": "Normalization",
15+
"value": "NORMALIZATION"
16+
},
17+
"content": {
18+
"desc": "All Titles",
19+
"value": "BIB_MMS"
20+
},
21+
"schedule": {
22+
"desc": "Not scheduled",
23+
"value": "NOT_SCHEDULED"
24+
},
25+
"creator": "string",
26+
"next_run": "2024-05-30T09:30:10Z",
27+
"parameter": [
28+
{
29+
"name": {
30+
"desc": "string",
31+
"value": "string"
32+
},
33+
"value": "string"
34+
}
35+
],
36+
"related_profile": {
37+
"link": "string",
38+
"value": "ID123"
39+
},
40+
"additional_info": {
41+
"link": "string",
42+
"value": "string"
43+
}
44+
}
45+
]
46+
}

src/Conf/Conf.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
namespace Scriptotek\Alma\Conf;
44

55
use Scriptotek\Alma\Client;
6+
use Scriptotek\Alma\Conf\Jobs;
67

78
class Conf
89
{
910
public function __construct(Client $client)
1011
{
1112
$this->client = $client;
1213
$this->libraries = new Libraries($client);
14+
$this->jobs = new Jobs($client);
1315
}
1416
}

0 commit comments

Comments
 (0)