Skip to content

Commit 6d36a9b

Browse files
authored
Merge pull request #139 from deploymenttheory/dev
Removed redundant code post refactor of api handler
2 parents 7cadc27 + 143f29f commit 6d36a9b

File tree

6 files changed

+3
-323
lines changed

6 files changed

+3
-323
lines changed

apiintegrations/apihandler/apihandler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type APIHandler interface {
1515
ConstructAPIAuthEndpoint(instanceName string, endpointPath string, log logger.Logger) string
1616
MarshalRequest(body interface{}, method string, endpoint string, log logger.Logger) ([]byte, error)
1717
MarshalMultipartRequest(fields map[string]string, files map[string]string, log logger.Logger) ([]byte, string, error)
18-
//HandleAPISuccessResponse(resp *http.Response, out interface{}, log logger.Logger) error
1918
GetContentTypeHeader(method string, log logger.Logger) string
2019
GetAcceptHeader() string
2120
GetDefaultBaseDomain() string

apiintegrations/jamfpro/README.MD

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ The Jamf Pro API Handler is an integral component of the Go API HTTP Client, des
99
- **Accept Header Management**: Generates a weighted `Accept` header to indicate the client's capability to process various MIME types, prioritizing XML for compatibility with the Classic API.
1010
- **Standard Headers**: Provides a set of standard headers required for API requests, including `Accept`, `Content-Type`, and `Authorization`.
1111
- **Request Marshaling**: Encodes request bodies into the appropriate format (XML or JSON) based on the target API endpoint, with support for multipart/form-data encoding for file uploads.
12-
- **Response Handling**: Processes API responses, decoding them into the desired data structures and handling binary data responses where applicable.
1312

1413
The logic of this api handler is defined as follows:
1514
Classic API:
@@ -36,43 +35,4 @@ For responses (DELETE):
3635
- Handle response codes as response body lacks anything useful.
3736
Headers
3837
- Sets accept headers based on weighting. Jamf Pro API doesn't support XML, so MIME type is skipped and returns JSON
39-
- Set content header as application/json with edge case exceptions based on need.
40-
41-
42-
## Usage
43-
44-
To utilize the Jamf Pro API Handler within the Go API HTTP Client, instantiate the client with the Jamf Pro-specific configuration:
45-
46-
```go
47-
package main
48-
49-
import (
50-
"log"
51-
52-
"github.com/deploymenttheory/go-api-http-client/httpclient"
53-
"github.com/deploymenttheory/go-api-http-client/apihandlers/jamfpro"
54-
)
55-
56-
func main() {
57-
// Configuration for the HTTP client specific to Jamf Pro
58-
config := httpclient.ClientConfig{
59-
Environment: httpclient.EnvironmentConfig{
60-
InstanceName: "your-instance-name",
61-
APIType: "jamfpro", // Specify the API type as "jamfpro"
62-
},
63-
// Other configuration settings...
64-
}
65-
66-
// Initialize the Jamf Pro API handler with the configuration
67-
jamfHandler, err := jamfpro.LoadAPIHandler(config.Environment.APIType, config.Logger)
68-
if err != nil {
69-
log.Fatalf("Failed to initialize Jamf Pro API handler: %v", err)
70-
}
71-
72-
// Use the handler for API interactions
73-
// Example: Constructing an API resource endpoint
74-
resourceURL := jamfHandler.ConstructAPIResourceEndpoint(config.Environment.InstanceName, "/path/to/resource", config.Logger)
75-
log.Printf("Constructed Resource URL: %s", resourceURL)
76-
77-
// Proceed with making API calls using the constructed URLs and the configured HTTP client...
78-
}
38+
- Set content header as application/json with edge case exceptions based on need.

apiintegrations/jamfpro/jamfpro_api_response.go.back

Lines changed: 0 additions & 111 deletions
This file was deleted.

apiintegrations/msgraph/msgraph_api_response.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

httpclient/request.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -388,61 +388,3 @@ func (c *Client) do(req *http.Request, log logger.Logger, method, endpoint strin
388388

389389
return resp, nil
390390
}
391-
392-
// handleErrorResponse processes and logs errors from an HTTP response, allowing for a customizable error message.
393-
//
394-
// Parameters:
395-
// - resp: The *http.Response received from the server.
396-
// - log: An instance of a logger (conforming to the logger.Logger interface) for logging the error details.
397-
// - errorMessage: A custom error message that provides context about the error.
398-
// - method: The HTTP method used for the request, for logging purposes.
399-
// - endpoint: The endpoint the request was sent to, for logging purposes.
400-
//
401-
// Returns:
402-
// - An error object parsed from the HTTP response, indicating the nature of the failure.
403-
// func (c *Client) handleErrorResponse(resp *http.Response, out interface{}, log logger.Logger, method, endpoint string) error {
404-
// if err := c.APIHandler.HandleAPIErrorResponse(resp, out, log); err != nil {
405-
// log.Error("Failed to unmarshal HTTP response",
406-
// zap.String("method", method),
407-
// zap.String("endpoint", endpoint),
408-
// zap.Error(err),
409-
// )
410-
// return err
411-
// }
412-
// log.Info("HTTP request succeeded",
413-
// zap.String("method", method),
414-
// zap.String("endpoint", endpoint),
415-
// zap.Int("status_code", resp.StatusCode),
416-
// )
417-
// return nil
418-
// }
419-
420-
// handleSuccessResponse unmarshals a successful HTTP response into the provided output parameter and logs the
421-
// success details. It's designed for use when the response indicates success (status code within 200-299).
422-
// The function logs the request's success and, in case of unmarshalling errors, logs the failure and returns the error.
423-
//
424-
// Parameters:
425-
// - resp: The *http.Response received from the server.
426-
// - out: A pointer to the variable where the unmarshalled response will be stored.
427-
// - log: An instance of a logger (conforming to the logger.Logger interface) for logging success or unmarshalling errors.
428-
// - method: The HTTP method used for the request, for logging purposes.
429-
// - endpoint: The endpoint the request was sent to, for logging purposes.
430-
//
431-
// Returns:
432-
// - nil if the response was successfully unmarshalled into the 'out' parameter, or an error if unmarshalling failed.
433-
// func (c *Client) handleSuccessResponse(resp *http.Response, out interface{}, log logger.Logger, method, endpoint string) error {
434-
// if err := c.APIHandler.HandleAPISuccessResponse(resp, out, log); err != nil {
435-
// log.Error("Failed to unmarshal HTTP response",
436-
// zap.String("method", method),
437-
// zap.String("endpoint", endpoint),
438-
// zap.Error(err),
439-
// )
440-
// return err
441-
// }
442-
// log.Info("HTTP request succeeded",
443-
// zap.String("method", method),
444-
// zap.String("endpoint", endpoint),
445-
// zap.Int("status_code", resp.StatusCode),
446-
// )
447-
// return nil
448-
// }

response/success.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ func HandleAPISuccessResponse(resp *http.Response, out interface{}, log logger.L
4646
// handleDeleteRequest handles the special case for DELETE requests, where a successful response might not contain a body.
4747
func handleDeleteRequest(resp *http.Response, log logger.Logger) error {
4848
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
49+
log.Info("Successfully processed DELETE request", zap.String("URL", resp.Request.URL.String()), zap.Int("Status Code", resp.StatusCode))
4950
return nil
5051
}
51-
return log.Error("DELETE request failed", zap.Int("Status Code", resp.StatusCode))
52+
return log.Error("DELETE request failed", zap.String("URL", resp.Request.URL.String()), zap.Int("Status Code", resp.StatusCode))
5253
}
5354

5455
// readResponseBody reads and returns the body of an HTTP response. It logs an error if reading fails.

0 commit comments

Comments
 (0)