github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/files/Client.go (about)

     1  // This class was auto-generated from the API references found at
     2  // https://epayments-api.developer-ingenico.com/
     3  
     4  package files
     5  
     6  import (
     7  	"github.com/Ingenico-ePayments/connect-sdk-go/communicator"
     8  	"github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication"
     9  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/errors"
    10  	sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors"
    11  	"github.com/Ingenico-ePayments/connect-sdk-go/internal/apiresource"
    12  )
    13  
    14  // Client represents a files client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // GetFile represents the resource /{merchantId}/files/{fileId} - Retrieve File
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/fileserviceapi/v1/en_US/go/files/getFile.html
    21  //
    22  // Can return any of the following errors:
    23  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    24  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    25  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    26  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    27  // or there was a conflict (HTTP status code 404, 409 or 410)
    28  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    29  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    30  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    31  // * APIError if the Ingenico ePayments platform returned any other error
    32  func (c *Client) GetFile(fileID string, context communication.CallContext, bodyHandler communicator.BodyHandler) error {
    33  	pathContext := map[string]string{
    34  		"fileId": fileID,
    35  	}
    36  
    37  	uri, err := c.apiResource.InstantiateURIWithContext("/files/v1/{merchantId}/files/{fileId}", pathContext)
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	clientHeaders := c.apiResource.ClientHeaders()
    43  
    44  	getErr := c.apiResource.Communicator().GetWithHandler(uri, clientHeaders, nil, context, bodyHandler)
    45  	if getErr != nil {
    46  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    47  		if isResponseError {
    48  			var errorObject interface{}
    49  
    50  			errorObject = &errors.ErrorResponse{}
    51  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
    52  			if err != nil {
    53  				return err
    54  			}
    55  
    56  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
    57  			if createErr != nil {
    58  				return createErr
    59  			}
    60  
    61  			return err
    62  		}
    63  
    64  		return getErr
    65  	}
    66  
    67  	return nil
    68  }
    69  
    70  // NewClient constructs a Files Client
    71  //
    72  // parent is the *apiresource.APIResource on top of which we want to build the new Files Client
    73  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
    74  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
    75  
    76  	return &Client{apiResource}
    77  }