Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/CUR 4097 Add query param to content get list api #1340

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ MSTEAMS_REDIRECT_URL=

#true for only vivensity
GCR_ENV_PERMISSION_VIV=true

#Smithsonian Open Access API
SMITHSONIAN_API_BASE_URL=
SMITHSONIAN_API_KEY=
29 changes: 29 additions & 0 deletions app/CurrikiGo/Smithsonian/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Institution Open Access API end points
* ClassName Client
*/
namespace App\CurrikiGo\Smithsonian;

use App\CurrikiGo\Smithsonian\Contracts\Command;

class Client
{
/**
* Client constructor.
*/
public function __construct()
{
}

/**
* Run a Smithsonian Institution Open Access API command
* @param \App\CurrikiGo\Smithsonian\Contracts\Command $command
* @return null|Response
*/
public function run(Command $command)
{
return $command->execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Content Detail
* ClassName GetContentDetailCommand
*/
namespace App\CurrikiGo\Smithsonian\Commands\Contents;

use App\CurrikiGo\Smithsonian\Contracts\Command;
use Illuminate\Support\Facades\Http;

class GetContentDetailCommand implements Command
{
/**
* Smithsonian Institution Open Access API query param
* @var array
*/
private $getParam;

/**
* GetContentDetailCommand constructor.
* @param array $getParam
* @return array
*/
public function __construct($getParam)
{
$this->getParam = $getParam;
}

/**
* Execute an API request to return Smithsonian content detail
* @return json object $response
*/
public function execute()
{
$apiUrl = config('smithsonian.api_base_url') . '/content/'.$this->getParam['id'].'?api_key='.config('smithsonian.api_key');
$response = Http::get($apiUrl);
return $response->json();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Content List
* ClassName GetContentListCommand
*/
namespace App\CurrikiGo\Smithsonian\Commands\Contents;

use App\CurrikiGo\Smithsonian\Contracts\Command;
use Illuminate\Support\Facades\Http;

class GetContentListCommand implements Command
{

/**
* Smithsonian Institution Open Access API query param
* @var array
*/
private $getParam;

/**
* GetContentListCommand constructor.
* @param array $getParam
* @return array
*/
public function __construct($getParam)
{
$this->getParam = $getParam;
}

/**
* Execute an API request to return Smithsonian content list
* @return json object $response
*/
public function execute()
{
$apiUrl = config('smithsonian.api_base_url') . '/search?api_key='.config('smithsonian.api_key').'&' . http_build_query($this->getParam);
$response = Http::get($apiUrl);
return $response->json();
}
}
47 changes: 47 additions & 0 deletions app/CurrikiGo/Smithsonian/Contents/GetContentDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Institution Open Access get content details API end point
* ClassName GetContentDetail
*/
namespace App\CurrikiGo\Smithsonian\Contents;

use App\Exceptions\GeneralException;
use App\CurrikiGo\Smithsonian\Commands\Contents\GetContentDetailCommand;

class GetContentDetail
{
/**
* Smithsonian content detail instance
* @var \App\CurrikiGo\Smithsonian\Client
*/
private $smithsonianClient;

/**
* GetContentDetail constructor.
* Create a new smithsonianClient instance.
* @param object $client
* @return object
*/
public function __construct($client)
{
$this->smithsonianClient = $client;
}

/**
* Fetch Smithsonian content detail
* @param array $getParam
* @return json object $response
* @throws GeneralException
*/
public function fetch($getParam)
{
$response = $this->smithsonianClient->run(new GetContentDetailCommand($getParam));
if ( $response ) {
return $response;
} else {
throw new GeneralException('No Record Found!');
}
}

}
47 changes: 47 additions & 0 deletions app/CurrikiGo/Smithsonian/Contents/GetContentList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Institution Open Access Get Content List API end point
* ClassName GetContentList
*/
namespace App\CurrikiGo\Smithsonian\Contents;

use App\Exceptions\GeneralException;
use App\CurrikiGo\Smithsonian\Commands\Contents\GetContentListCommand;

class GetContentList
{
/**
* Smithsonian content list instance
* @var \App\CurrikiGo\Smithsonian\Client
*/
private $smithsonianClient;

/**
* GetContentList constructor.
* Create a new smithsonianClient instance.
* @param object $client
* @return object
*/
public function __construct($client)
{
$this->smithsonianClient = $client;
}

/**
* Fetch Smithsonian contents list
* @param array $getParam
* @return json object $response
* @throws GeneralException
*/
public function fetch($getParam)
{
$response = $this->smithsonianClient->run(new GetContentListCommand($getParam));
if ( $response ) {
return $response;
} else {
throw new GeneralException('No Record Found!');
}
}

}
14 changes: 14 additions & 0 deletions app/CurrikiGo/Smithsonian/Contracts/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @Author Asim Sarwar
* Interface Command
*/
namespace App\CurrikiGo\Smithsonian\Contracts;

interface Command
{
/**
* Execute a command
*/
public function execute();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* @Author Asim Sarwar
* Description Handle Smithsonian Institution Open Access API's Client
* ClassName SmithsonianIOAAPIClientController
*/
namespace App\Http\Controllers\Api\V1\Integration;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\CurrikiGo\Smithsonian\Client;
use App\CurrikiGo\Smithsonian\Contents\GetContentList;
use App\CurrikiGo\Smithsonian\Contents\GetContentDetail;
use App\Exceptions\GeneralException;

class SmithsonianIOAAPIClientController extends Controller
{
protected $client;
/**
* SmithsonianIOAAPIClientController constructor.
* Create a new Client instance.
* @return object $client
*/
public function __construct()
{
$this->client = new Client();
}

/**
* Get Smithsonian Contents List
* @param Request $request
* @bodyParam q string use for search record Example: q=online_visual_material:true AND IC 443
* @bodyParam start int like page number Example: 1
* @bodyParam rows int like page size or number of record per page Example: 10
* @bodyParam sort string Sort list by id, newest, updated and random field
* @bodyParam type string get list by type = edanmdm or ead_collection or ead_component or all
* @bodyParam row_group string The designated set of row types you are filtering it may be objects, archives
* @return object $response
* @throws GeneralException
*/
public function getContentList(Request $request)
{
$getParam = $request->only([
'q',
'start',
'rows',
'sort',
'type',
'row_group'
]);
$auth = \Auth::user();
if ( $auth && $auth->id ) {
$instance = new GetContentList($this->client);
$response = $instance->fetch($getParam);
return $response;
}
throw new GeneralException('Unauthorized!');
}

/**
* Get Smithsonian Content Detail
* @param Request $request
* @bodyParam id string Example: con-1620124231687-1620150333404-0
* @return object $response
* @throws GeneralException
*/
public function getContentDetail(Request $request)
{
$getParam = $request->only([
'id'
]);
$auth = \Auth::user();
if ( $auth && $auth->id && isset($getParam['id']) && $getParam['id'] != '') {
$instance = new GetContentDetail($this->client);
$response = $instance->fetch($getParam);
return $response;
}
throw new GeneralException('Please check you payload data. id field is require!');
}
}
17 changes: 17 additions & 0 deletions config/smithsonian.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Smithsonian API Base Url
|--------------------------------------------------------------------------
*/
'api_base_url' => env('SMITHSONIAN_API_BASE_URL', 'https://api.si.edu/openaccess/api/v1.0'),

/*
|--------------------------------------------------------------------------
| Smithsonian API Key
|--------------------------------------------------------------------------
*/
'api_key' => env('SMITHSONIAN_API_KEY', 'invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A')
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;

class AddSmithsonianOptionToMediaSourcesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Artisan::call('db:seed', [
'--class' => AddSmithsonianOptionToMediaSourcesSeeder::class,
'--force' => true
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{

}
}
27 changes: 27 additions & 0 deletions database/seeds/AddSmithsonianOptionToMediaSourcesSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class AddSmithsonianOptionToMediaSourcesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$checkAlreadyAdded = DB::table('media_sources')
->where('name', 'Smithsonian')
->where('media_type', 'Image')
->first();
if ( empty($checkAlreadyAdded) ) {
DB::table('media_sources')->insert([
'name' => 'Smithsonian',
'media_type' => 'Image',
'created_at' => now()
]);
}
}
}
Loading