diff --git a/.env.example b/.env.example index 18f7016bc..0c725fb85 100644 --- a/.env.example +++ b/.env.example @@ -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= \ No newline at end of file diff --git a/app/CurrikiGo/Smithsonian/Client.php b/app/CurrikiGo/Smithsonian/Client.php new file mode 100644 index 000000000..0ae33f667 --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Client.php @@ -0,0 +1,29 @@ +execute(); + } +} diff --git a/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentDetailCommand.php b/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentDetailCommand.php new file mode 100644 index 000000000..bb7acf7fc --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentDetailCommand.php @@ -0,0 +1,40 @@ +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(); + } +} diff --git a/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentListCommand.php b/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentListCommand.php new file mode 100644 index 000000000..30f0d49ca --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Commands/Contents/GetContentListCommand.php @@ -0,0 +1,41 @@ +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').'&q=online_visual_material:true&' . http_build_query($this->getParam); + $response = Http::get($apiUrl); + return $response->json(); + } +} diff --git a/app/CurrikiGo/Smithsonian/Contents/GetContentDetail.php b/app/CurrikiGo/Smithsonian/Contents/GetContentDetail.php new file mode 100644 index 000000000..f54704240 --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Contents/GetContentDetail.php @@ -0,0 +1,47 @@ +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!'); + } + } + +} diff --git a/app/CurrikiGo/Smithsonian/Contents/GetContentList.php b/app/CurrikiGo/Smithsonian/Contents/GetContentList.php new file mode 100644 index 000000000..a04eda949 --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Contents/GetContentList.php @@ -0,0 +1,47 @@ +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!'); + } + } + +} diff --git a/app/CurrikiGo/Smithsonian/Contracts/Command.php b/app/CurrikiGo/Smithsonian/Contracts/Command.php new file mode 100644 index 000000000..5038cd5dc --- /dev/null +++ b/app/CurrikiGo/Smithsonian/Contracts/Command.php @@ -0,0 +1,14 @@ +client = new Client(); + } + + /** + * Get Smithsonian Contents List + * @param Request $request + * @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([ + '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!'); + } +} diff --git a/config/smithsonian.php b/config/smithsonian.php new file mode 100644 index 000000000..ebea1d843 --- /dev/null +++ b/config/smithsonian.php @@ -0,0 +1,17 @@ + env('SMITHSONIAN_API_BASE_URL', 'https://api.si.edu/openaccess/api/v1.0'), + + /* + |-------------------------------------------------------------------------- + | Smithsonian API Key + |-------------------------------------------------------------------------- + */ + 'api_key' => env('SMITHSONIAN_API_KEY', 'invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A') +]; diff --git a/database/migrations/2022_09_22_083747_add_smithsonian_option_to_media_sources_table.php b/database/migrations/2022_09_22_083747_add_smithsonian_option_to_media_sources_table.php new file mode 100644 index 000000000..8f204b074 --- /dev/null +++ b/database/migrations/2022_09_22_083747_add_smithsonian_option_to_media_sources_table.php @@ -0,0 +1,29 @@ + AddSmithsonianOptionToMediaSourcesSeeder::class, + '--force' => true + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + + } +} diff --git a/database/seeds/AddSmithsonianOptionToMediaSourcesSeeder.php b/database/seeds/AddSmithsonianOptionToMediaSourcesSeeder.php new file mode 100644 index 000000000..40e76c0c8 --- /dev/null +++ b/database/seeds/AddSmithsonianOptionToMediaSourcesSeeder.php @@ -0,0 +1,27 @@ +where('name', 'Smithsonian') + ->where('media_type', 'Image') + ->first(); + if ( empty($checkAlreadyAdded) ) { + DB::table('media_sources')->insert([ + 'name' => 'Smithsonian', + 'media_type' => 'Image', + 'created_at' => now() + ]); + } + } +} diff --git a/routes/integrations.php b/routes/integrations.php index 6239d9a8f..892931e79 100644 --- a/routes/integrations.php +++ b/routes/integrations.php @@ -35,6 +35,12 @@ Route::group(['prefix' => 'komodo'], function () { Route::post('get-my-video-list', 'Integration\KomodoAPIClientController@getMyVideosList'); }); + + // Smithsonian Institution Open Access API's + Route::group(['prefix' => 'smithsonian'], function () { + Route::post('get-content-list', 'Integration\SmithsonianIOAAPIClientController@getContentList'); + Route::post('get-content-detail', 'Integration\SmithsonianIOAAPIClientController@getContentDetail'); + }); });