From 89eeb3c51ccac4fe61e72efe4d9b53119483b5b5 Mon Sep 17 00:00:00 2001 From: Asim Sarwar Date: Wed, 28 Sep 2022 14:14:49 +0500 Subject: [PATCH 1/4] CUR-4097: Implement the Smithsonian Images API. --- app/CurrikiGo/Smithsonian/Client.php | 29 ++++++++ .../Contents/GetContentDetailCommand.php | 40 +++++++++++ .../Contents/GetContentListCommand.php | 41 +++++++++++ .../Smithsonian/Contents/GetContentDetail.php | 47 ++++++++++++ .../Smithsonian/Contents/GetContentList.php | 47 ++++++++++++ .../Smithsonian/Contracts/Command.php | 14 ++++ .../SmithsonianIOAAPIClientController.php | 72 +++++++++++++++++++ config/smithsonian.php | 17 +++++ ...thsonian_option_to_media_sources_table.php | 29 ++++++++ ...dSmithsonianOptionToMediaSourcesSeeder.php | 27 +++++++ routes/integrations.php | 6 ++ 11 files changed, 369 insertions(+) create mode 100644 app/CurrikiGo/Smithsonian/Client.php create mode 100644 app/CurrikiGo/Smithsonian/Commands/Contents/GetContentDetailCommand.php create mode 100644 app/CurrikiGo/Smithsonian/Commands/Contents/GetContentListCommand.php create mode 100644 app/CurrikiGo/Smithsonian/Contents/GetContentDetail.php create mode 100644 app/CurrikiGo/Smithsonian/Contents/GetContentList.php create mode 100644 app/CurrikiGo/Smithsonian/Contracts/Command.php create mode 100644 app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php create mode 100644 config/smithsonian.php create mode 100644 database/migrations/2022_09_22_083747_add_smithsonian_option_to_media_sources_table.php create mode 100644 database/seeds/AddSmithsonianOptionToMediaSourcesSeeder.php 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 + * @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 + * @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..d93455d6a --- /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'); + }); }); From fb7302a9826c42124cb5489c0ec7ea8b752ab9a0 Mon Sep 17 00:00:00 2001 From: Asim Sarwar Date: Wed, 28 Sep 2022 16:02:47 +0500 Subject: [PATCH 2/4] CUR-4097 update config file. --- config/smithsonian.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/smithsonian.php b/config/smithsonian.php index d93455d6a..505e4ab85 100644 --- a/config/smithsonian.php +++ b/config/smithsonian.php @@ -6,12 +6,12 @@ | Smithsonian API Base Url |-------------------------------------------------------------------------- */ - 'api_base_url' => env('Smithsonian_API_BASE_URL', 'https://api.si.edu/openaccess/api/v1.0'), + 'api_base_url' => env('SMITHSONIAN_API_KEY', 'https://api.si.edu/openaccess/api/v1.0'), /* |-------------------------------------------------------------------------- | Smithsonian API Key |-------------------------------------------------------------------------- */ - 'api_key' => env('Smithsonian_API_KEY', 'invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A') + 'api_key' => env('SMITHSONIAN_API_KEY', 'invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A') ]; From 39ae2d19004a2c3bd30757921626cfd4fe4036c0 Mon Sep 17 00:00:00 2001 From: Asim Sarwar Date: Wed, 28 Sep 2022 17:48:06 +0500 Subject: [PATCH 3/4] Update the requested changes. --- .env.example | 4 ++++ .../SmithsonianIOAAPIClientController.php | 12 ++++++++++++ config/smithsonian.php | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 18f7016bc..9ac21c0d2 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='https://api.si.edu/openaccess/api/v1.0' +SMITHSONIAN_API_KEY='invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A' \ No newline at end of file diff --git a/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php b/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php index fc39b399c..16544589e 100644 --- a/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php +++ b/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php @@ -29,6 +29,17 @@ public function __construct() /** * 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 The sort of the row response set. Default is relevancy. newest is sort rows by timestamp * of record in descending order. updated is sort rows by lastTimeUpdated of record in descending order. + * Default value: relevancy + * Allowed values: id, newest, updated, random + * @bodyParam type string The type of row object.. Each type will conform to a published schema. + * Default value: edanmdm + * Allowed values: edanmdm, ead_collection, ead_component, all + * @bodyParam row_group string The designated set of row types you are filtering against.. Objects refers to * objects, artifacts, specimens. Archives are all archives collection and item records. + * Default value: objects + * Allowed values: objects, archives * @return object $response * @throws GeneralException */ @@ -53,6 +64,7 @@ public function getContentList(Request $request) /** * Get Smithsonian Content Detail * @param Request $request + * @bodyParam id string Example: con-1620124231687-1620150333404-0 * @return object $response * @throws GeneralException */ diff --git a/config/smithsonian.php b/config/smithsonian.php index 505e4ab85..ebea1d843 100644 --- a/config/smithsonian.php +++ b/config/smithsonian.php @@ -6,7 +6,7 @@ | Smithsonian API Base Url |-------------------------------------------------------------------------- */ - 'api_base_url' => env('SMITHSONIAN_API_KEY', 'https://api.si.edu/openaccess/api/v1.0'), + 'api_base_url' => env('SMITHSONIAN_API_BASE_URL', 'https://api.si.edu/openaccess/api/v1.0'), /* |-------------------------------------------------------------------------- From 8055f64fb410a6b09deb20da381eafb0ec2511ba Mon Sep 17 00:00:00 2001 From: Asim Sarwar Date: Wed, 28 Sep 2022 19:40:33 +0500 Subject: [PATCH 4/4] Updat suggested changes. --- .env.example | 4 ++-- .../SmithsonianIOAAPIClientController.php | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 9ac21c0d2..0c725fb85 100644 --- a/.env.example +++ b/.env.example @@ -157,5 +157,5 @@ MSTEAMS_REDIRECT_URL= GCR_ENV_PERMISSION_VIV=true #Smithsonian Open Access API -SMITHSONIAN_API_BASE_URL='https://api.si.edu/openaccess/api/v1.0' -SMITHSONIAN_API_KEY='invpQb67otWXfxjTj8EYXd77UeCLnSguDczIni5A' \ No newline at end of file +SMITHSONIAN_API_BASE_URL= +SMITHSONIAN_API_KEY= \ No newline at end of file diff --git a/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php b/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php index 16544589e..4ad4f32e3 100644 --- a/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php +++ b/app/Http/Controllers/Api/V1/Integration/SmithsonianIOAAPIClientController.php @@ -31,15 +31,9 @@ public function __construct() * @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 The sort of the row response set. Default is relevancy. newest is sort rows by timestamp * of record in descending order. updated is sort rows by lastTimeUpdated of record in descending order. - * Default value: relevancy - * Allowed values: id, newest, updated, random - * @bodyParam type string The type of row object.. Each type will conform to a published schema. - * Default value: edanmdm - * Allowed values: edanmdm, ead_collection, ead_component, all - * @bodyParam row_group string The designated set of row types you are filtering against.. Objects refers to * objects, artifacts, specimens. Archives are all archives collection and item records. - * Default value: objects - * Allowed values: objects, archives + * @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 */