Skip to content

Commit

Permalink
Merge pull request #3 from Harikrishnan1819/main
Browse files Browse the repository at this point in the history
changes in service provider
  • Loading branch information
gotocva authored May 8, 2024
2 parents 151ea6a + 1972995 commit 9760cf5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 57 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
"laravel": {
"providers": [
"Sparkouttech\\BugAtlas\\BugAtlasServiceProvider"
],
"aliases": {
"BugAtlas": "Sparkouttech\\BugAtlas\\BugAtlasFacade"
}
]
}
}
}
21 changes: 0 additions & 21 deletions src/BugAtlasFacade.php

This file was deleted.

31 changes: 16 additions & 15 deletions src/BugAtlasServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,29 @@ class BugAtlasServiceProvider extends ServiceProvider

/**
* Bootstrap services.
*
* Checks the keys(API key, secret key, or tag) are configured or not.
* If not function returns without further processing.
* Otherwise, it proceeds with preparing log details based on the provided request and sends the log details.
* @param \Illuminate\Http\Request $request
* @return void
* @return bool | void
*/
public function boot(Request $request)
{
$this->mergeConfigFrom(__DIR__ . '/../config/bugatlas.php', 'bugatlas');
if (empty(config('bugatlas.api_key')) || empty(config('bugatlas.secret_key')) || empty(config('bugatlas.tag'))) {
return;
}
$logDetails = $this->prepareLogDetails($request);
$this->sendLogToApi($logDetails);
}

/**
* Prepare log details for a given HTTP request.
* Prepares log details for HTTP request.
*
* This function extracts relevant details from the request and response
* to prepare a log entry. It collects headers, fetches additional data
* from the server, and formats them into an array.
* Extracts relevant details from request and response,
* collects headers, fetches server data, formats into array.
*
* @param Request $request The HTTP request object containing request details.
* @return array An array containing various details for logging.
* @param \Illuminate\Http\Request $request
* @return array
*/
private function prepareLogDetails(Request $request)
{
Expand All @@ -43,7 +46,6 @@ private function prepareLogDetails(Request $request)
});
$response = Http::get(config("app.url"));

// Log the details
return [
"protocol" => $request->server("SERVER_PROTOCOL"),
"request_url" => $request->fullUrl(),
Expand All @@ -61,13 +63,12 @@ private function prepareLogDetails(Request $request)
}

/**
* Send log details to the API for storage.
* Sends log details to API for storage.
*
* This function prepares a structured payload containing various log details
* and sends it to the specified API endpoint for storage. It constructs the
* payload based on the provided log details and additional metadata.
* Prepares payload with log details and metadata,
* sends it to specified endpoint for storage.
*
* @param array $logDetails An array containing various log details to be sent to the API.
* @param array $logDetails
* @return void
*/
private function sendLogToApi($logDetails)
Expand Down
25 changes: 8 additions & 17 deletions src/Traits/ApiBugAtlas.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ trait ApiBugAtlas
private $baseURL = 'https://api.bugatlas.com/v1';

/**
* Process API response for a given endpoint and payload.
*
* This function sends a POST request to the specified API endpoint
* with the provided payload and retrieves the response. It sets the
* necessary headers for the API request using the `getApiHeaders()`
* method and constructs the full URL by appending the endpoint to
* the base URL. The response from the API is returned.
*
* @param string $endPoint The endpoint of the API to send the request to.
* @param array $payload The payload to send with the request.
* @return \Illuminate\Http\Client\Response The response from the API.
* Sends a POST request to the API endpoint with provided payload,headers.
* Returns the API response.
* @param string $endPoint API endpoint.
* @param array $payload payload to send with the request.
* @return \Illuminate\Http\Client\Response
*/
public function processApiResponse($endPoint, $payload)
{
Expand All @@ -30,13 +24,10 @@ public function processApiResponse($endPoint, $payload)


/**
* Retrieve headers for API requests.
*
* This function retrieves the required headers for making requests
* to the BugAtlas API. It fetches the API key and secret key from
* the application configuration and sets the content type to JSON.
* Retrieves headers for BugAtlas API requests.
*
* @return array An array containing the API request headers.
* Fetches API and secret keys from config,
* @return array API request headers.
*/
private function getApiHeaders()
{
Expand Down

0 comments on commit 9760cf5

Please sign in to comment.