Skip to content

Commit ea95ecb

Browse files
authored
CUR-4097: Implement the Smithsonian Images API's. (#1332)
* CUR-4097: Implement the Smithsonian Images API. * CUR-4097 update config file. * Update the requested changes. * Updat suggested changes.
1 parent efef039 commit ea95ecb

File tree

12 files changed

+379
-0
lines changed

12 files changed

+379
-0
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,7 @@ ASSIGNMENT_DUE_DATE_DAYS=
156156

157157
#true for only vivensity
158158
GCR_ENV_PERMISSION_VIV=true
159+
160+
#Smithsonian Open Access API
161+
SMITHSONIAN_API_BASE_URL=
162+
SMITHSONIAN_API_KEY=
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Institution Open Access API end points
5+
* ClassName Client
6+
*/
7+
namespace App\CurrikiGo\Smithsonian;
8+
9+
use App\CurrikiGo\Smithsonian\Contracts\Command;
10+
11+
class Client
12+
{
13+
/**
14+
* Client constructor.
15+
*/
16+
public function __construct()
17+
{
18+
}
19+
20+
/**
21+
* Run a Smithsonian Institution Open Access API command
22+
* @param \App\CurrikiGo\Smithsonian\Contracts\Command $command
23+
* @return null|Response
24+
*/
25+
public function run(Command $command)
26+
{
27+
return $command->execute();
28+
}
29+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Content Detail
5+
* ClassName GetContentDetailCommand
6+
*/
7+
namespace App\CurrikiGo\Smithsonian\Commands\Contents;
8+
9+
use App\CurrikiGo\Smithsonian\Contracts\Command;
10+
use Illuminate\Support\Facades\Http;
11+
12+
class GetContentDetailCommand implements Command
13+
{
14+
/**
15+
* Smithsonian Institution Open Access API query param
16+
* @var array
17+
*/
18+
private $getParam;
19+
20+
/**
21+
* GetContentDetailCommand constructor.
22+
* @param array $getParam
23+
* @return array
24+
*/
25+
public function __construct($getParam)
26+
{
27+
$this->getParam = $getParam;
28+
}
29+
30+
/**
31+
* Execute an API request to return Smithsonian content detail
32+
* @return json object $response
33+
*/
34+
public function execute()
35+
{
36+
$apiUrl = config('smithsonian.api_base_url') . '/content/'.$this->getParam['id'].'?api_key='.config('smithsonian.api_key');
37+
$response = Http::get($apiUrl);
38+
return $response->json();
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Content List
5+
* ClassName GetContentListCommand
6+
*/
7+
namespace App\CurrikiGo\Smithsonian\Commands\Contents;
8+
9+
use App\CurrikiGo\Smithsonian\Contracts\Command;
10+
use Illuminate\Support\Facades\Http;
11+
12+
class GetContentListCommand implements Command
13+
{
14+
15+
/**
16+
* Smithsonian Institution Open Access API query param
17+
* @var array
18+
*/
19+
private $getParam;
20+
21+
/**
22+
* GetContentListCommand constructor.
23+
* @param array $getParam
24+
* @return array
25+
*/
26+
public function __construct($getParam)
27+
{
28+
$this->getParam = $getParam;
29+
}
30+
31+
/**
32+
* Execute an API request to return Smithsonian content list
33+
* @return json object $response
34+
*/
35+
public function execute()
36+
{
37+
$apiUrl = config('smithsonian.api_base_url') . '/search?api_key='.config('smithsonian.api_key').'&q=online_visual_material:true&' . http_build_query($this->getParam);
38+
$response = Http::get($apiUrl);
39+
return $response->json();
40+
}
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Institution Open Access get content details API end point
5+
* ClassName GetContentDetail
6+
*/
7+
namespace App\CurrikiGo\Smithsonian\Contents;
8+
9+
use App\Exceptions\GeneralException;
10+
use App\CurrikiGo\Smithsonian\Commands\Contents\GetContentDetailCommand;
11+
12+
class GetContentDetail
13+
{
14+
/**
15+
* Smithsonian content detail instance
16+
* @var \App\CurrikiGo\Smithsonian\Client
17+
*/
18+
private $smithsonianClient;
19+
20+
/**
21+
* GetContentDetail constructor.
22+
* Create a new smithsonianClient instance.
23+
* @param object $client
24+
* @return object
25+
*/
26+
public function __construct($client)
27+
{
28+
$this->smithsonianClient = $client;
29+
}
30+
31+
/**
32+
* Fetch Smithsonian content detail
33+
* @param array $getParam
34+
* @return json object $response
35+
* @throws GeneralException
36+
*/
37+
public function fetch($getParam)
38+
{
39+
$response = $this->smithsonianClient->run(new GetContentDetailCommand($getParam));
40+
if ( $response ) {
41+
return $response;
42+
} else {
43+
throw new GeneralException('No Record Found!');
44+
}
45+
}
46+
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Institution Open Access Get Content List API end point
5+
* ClassName GetContentList
6+
*/
7+
namespace App\CurrikiGo\Smithsonian\Contents;
8+
9+
use App\Exceptions\GeneralException;
10+
use App\CurrikiGo\Smithsonian\Commands\Contents\GetContentListCommand;
11+
12+
class GetContentList
13+
{
14+
/**
15+
* Smithsonian content list instance
16+
* @var \App\CurrikiGo\Smithsonian\Client
17+
*/
18+
private $smithsonianClient;
19+
20+
/**
21+
* GetContentList constructor.
22+
* Create a new smithsonianClient instance.
23+
* @param object $client
24+
* @return object
25+
*/
26+
public function __construct($client)
27+
{
28+
$this->smithsonianClient = $client;
29+
}
30+
31+
/**
32+
* Fetch Smithsonian contents list
33+
* @param array $getParam
34+
* @return json object $response
35+
* @throws GeneralException
36+
*/
37+
public function fetch($getParam)
38+
{
39+
$response = $this->smithsonianClient->run(new GetContentListCommand($getParam));
40+
if ( $response ) {
41+
return $response;
42+
} else {
43+
throw new GeneralException('No Record Found!');
44+
}
45+
}
46+
47+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Interface Command
5+
*/
6+
namespace App\CurrikiGo\Smithsonian\Contracts;
7+
8+
interface Command
9+
{
10+
/**
11+
* Execute a command
12+
*/
13+
public function execute();
14+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* @Author Asim Sarwar
4+
* Description Handle Smithsonian Institution Open Access API's Client
5+
* ClassName SmithsonianIOAAPIClientController
6+
*/
7+
namespace App\Http\Controllers\Api\V1\Integration;
8+
9+
use App\Http\Controllers\Controller;
10+
use Illuminate\Http\Request;
11+
use App\CurrikiGo\Smithsonian\Client;
12+
use App\CurrikiGo\Smithsonian\Contents\GetContentList;
13+
use App\CurrikiGo\Smithsonian\Contents\GetContentDetail;
14+
use App\Exceptions\GeneralException;
15+
16+
class SmithsonianIOAAPIClientController extends Controller
17+
{
18+
protected $client;
19+
/**
20+
* SmithsonianIOAAPIClientController constructor.
21+
* Create a new Client instance.
22+
* @return object $client
23+
*/
24+
public function __construct()
25+
{
26+
$this->client = new Client();
27+
}
28+
29+
/**
30+
* Get Smithsonian Contents List
31+
* @param Request $request
32+
* @bodyParam start int like page number Example: 1
33+
* @bodyParam rows int like page size or number of record per page Example: 10
34+
* @bodyParam sort string Sort list by id, newest, updated and random field
35+
* @bodyParam type string get list by type = edanmdm or ead_collection or ead_component or all
36+
* @bodyParam row_group string The designated set of row types you are filtering it may be objects, archives
37+
* @return object $response
38+
* @throws GeneralException
39+
*/
40+
public function getContentList(Request $request)
41+
{
42+
$getParam = $request->only([
43+
'start',
44+
'rows',
45+
'sort',
46+
'type',
47+
'row_group'
48+
]);
49+
$auth = \Auth::user();
50+
if ( $auth && $auth->id ) {
51+
$instance = new GetContentList($this->client);
52+
$response = $instance->fetch($getParam);
53+
return $response;
54+
}
55+
throw new GeneralException('Unauthorized!');
56+
}
57+
58+
/**
59+
* Get Smithsonian Content Detail
60+
* @param Request $request
61+
* @bodyParam id string Example: con-1620124231687-1620150333404-0
62+
* @return object $response
63+
* @throws GeneralException
64+
*/
65+
public function getContentDetail(Request $request)
66+
{
67+
$getParam = $request->only([
68+
'id'
69+
]);
70+
$auth = \Auth::user();
71+
if ( $auth && $auth->id && isset($getParam['id']) && $getParam['id'] != '') {
72+
$instance = new GetContentDetail($this->client);
73+
$response = $instance->fetch($getParam);
74+
return $response;
75+
}
76+
throw new GeneralException('Please check you payload data. id field is require!');
77+
}
78+
}

config/smithsonian.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Smithsonian API Base Url
7+
|--------------------------------------------------------------------------
8+
*/
9+
'api_base_url' => env('SMITHSONIAN_API_BASE_URL', 'https://api.si.edu/openaccess/api/v1.0'),
10+
11+
/*
12+
|--------------------------------------------------------------------------
13+
| Smithsonian API Key
14+
|--------------------------------------------------------------------------
15+
*/
16+
'api_key' => env('SMITHSONIAN_API_KEY', 'invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A')
17+
];
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
5+
class AddSmithsonianOptionToMediaSourcesTable extends Migration
6+
{
7+
/**
8+
* Run the migrations.
9+
*
10+
* @return void
11+
*/
12+
public function up()
13+
{
14+
\Artisan::call('db:seed', [
15+
'--class' => AddSmithsonianOptionToMediaSourcesSeeder::class,
16+
'--force' => true
17+
]);
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*
23+
* @return void
24+
*/
25+
public function down()
26+
{
27+
28+
}
29+
}

0 commit comments

Comments
 (0)