Skip to content

Commit

Permalink
docs(package): add missing docs (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bismapervaiz committed Jul 27, 2023
1 parent 88e91d5 commit f35951a
Show file tree
Hide file tree
Showing 19 changed files with 285 additions and 31 deletions.
74 changes: 53 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,94 @@

## Introduction

Core library for Apimatic's Go SDK hosted on [github.com/apimatic/go-core-runtime](https://pkg.go.dev/github.com/apimatic/go-core-runtime)
The `go-core-runtime` is a core library for Apimatic's Go SDK, providing essential utilities and structures for handling API requests and responses using the HTTP protocol. For detailed API documentation and usage examples, visit the [GoDoc documentation](https://pkg.go.dev/github.com/apimatic/go-core-runtime).

## Requirement

Go v1.18
This package requires Go v1.18 or higher.

## Install the Package
## Installation

Run the following command to install the package and automatically add the package to your module or .mod file:
To install the package, you can use `go get`:

```go
go get "github.com/apimatic/go-core-runtime"
```bash
go get github.com/apimatic/go-core-runtime
```

Or add it to the go.mod file manually as given below:
Alternatively, you can add the package manually to your go.mod file:


```go
require "github.com/apimatic/go-core-runtime" v0.0.x
```
And run the following command to install the package automatically:
Then, run the following command to install the package automatically:

```go
go get ./...
```

## Package Details
### HTTPS

### API Error
The apiError package provides a structure to represent error responses from API calls.

| File Name | Description |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [`Call Builder`](https/callBuilder.go) | Provides the logic related to the HTTPs request. Includes building and making the request call. |
| [`File Wrapper`](https/fileWrapper.go) | Provides a wrapper for the file parameter to use in the HTTPs calls. |
| [`Form Data`](https/formData.go) | Provides handling of form parameters in the request. |
| [`HTTP Client`](https/httpClient.go) | Provides an interface for the HTTP Client to use for making the calls. |
| [`HTTP Configuration`](https/httpConfiguration.go) | Provides configurations for the HTTP calls. |
| [`HTTP Context`](https/httpContext.go) | Provides a struct that holds request and corresponding response instances. |
| [`HTTP Headers`](https/httpHeaders.go) | Provides handling for headers to send with the request. |
| [`Interceptors`](https/interceptors.go) | Provides handling to intercept requests. |

| [`API Error`](apiError/apiError.go) | Provides a structure to represent error responses from API calls. |

### API Error
### HTTPS
The https package provides logic related to HTTP requests, including building and making the request call. It offers features such as handling form data, file parameters, headers, and interceptors.

| File Name | Description |
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [`API Response`](https/apiResponse.go) | Provides a struct around the HTTP response and the data. |
| [`Call Builder`](https/callBuilder.go) | Provides the logic related to the HTTPs request. Includes building and making the request call. |
| [`File Wrapper`](https/fileWrapper.go) | Provides a wrapper for file parameters to use in the HTTPs calls. |
| [`Form Data`](https/formData.go) | Provides handling of form parameters in the request. |
| [`HTTP Client`](https/httpClient.go) | Provides an interface for the HTTP Client to use for making the calls. |
| [`HTTP Configuration`](https/httpConfiguration.go) | Provides configurations for the HTTP calls. |
| [`HTTP Context`](https/httpContext.go) | Provides a struct that holds request and corresponding response instances. |
| [`HTTP Headers`](https/httpHeaders.go) | Provides handling for headers to send with the request. |
| [`Internal Error`](https/internalError.go) | Provides handling for internal errors that may occur during the API calls. |
| [`Interceptors`](https/interceptors.go) | Provides handling to intercept requests. |
| [`Retryer`](https/retryer.go) | Provides handling to automatically retry for failed requests. |

### Test Helper
Package testHelper provides helper functions for testing purposes.
| File Name | Description |
|---------------------------------------------|------------------------------------------------------------------|
| [`BodyMatchers`](testHelper/bodyMatchers.go) | Provides functions to match JSON response bodies with expected bodies. |
| [`HeadersMatchers`](testHelper/headersMatchers.go) | Provides functions to match HTTP headers with expected headers. |
| [`StatusCodeMatchers`](testHelper/statusCodeMatchers.go) | Provides functions to match HTTP status codes with expected status codes. |

### Types
Package types provides utility types and functions.

| File Name | Description |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [`API Error`](apiError/apiError.go) | Provides the error struct that is used in the endpoint calls. |
| [`Optional`](types/optional.go) | Provides a wrapper to use any type as optional and nullable.


### Utilities
The utilities package provides utility functions for making HTTP calls.

| File Name | Description |
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------|
| [`API Helper`](utilities/apiHelper.go) | Provides helper methods for making the HTTP calls. |


Each package contains its test files and code coverage reports as well.
Each package contains its test files.


## Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvement, please open an issue.

## License
This project is licensed under the [MIT License](LICENSE).


## Contact
For any questions or support, please feel free to contact us at support@apimatic.io.


[license-badge]: https://img.shields.io/badge/licence-MIT-blue
Expand Down
11 changes: 8 additions & 3 deletions apiError/apiError.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
// Package apiError provides a structure to represent error responses from API calls.
// Copyright (c) APIMatic. All rights reserved.
package apiError

import (
"fmt"
"net/http"
)

// This is the base struct for all exceptions that represent an error response from the server.
// ApiError is the base struct for all error responses from the server.
// It holds information about the original HTTP request, the status code, headers, and response body.
type ApiError struct {
Request http.Request `json:"Request"`
StatusCode int `json:"StatusCode"`
Headers map[string]string `json:"Headers"`
Body string `json:"Body"`
}

// Constructor for ApiError.
// NewApiError is the constructor function for ApiError.
// It creates and returns a pointer to an ApiError instance with the given status code and response body.
func NewApiError(
statusCode int,
body string) *ApiError {
Expand All @@ -23,7 +27,8 @@ func NewApiError(
}
}

// Implementing the Error method for the error interface.
// Error implements the Error method for the error interface.
// It returns a string representation of the ApiError instance when used in an error context.
func (a *ApiError) Error() string {
return fmt.Sprintf("ApiError occured %v", a.Body)
}
8 changes: 8 additions & 0 deletions https/apiResponse.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Package https provides utilities and structures for handling
// API requests and responses using the HTTP protocol.
// Copyright (c) APIMatic. All rights reserved.
package https

import "net/http"

// ApiResponse is a generic struct that represents an API response containing data and the HTTP response.
// The `Data` field holds the data of any type `T` returned by the API.
// The `Response` field contains the underlying HTTP response associated with the API call.
type ApiResponse[T any] struct {
Data T `json:"data"`
Response *http.Response `json:"response"`
}

// NewApiResponse creates a new instance of ApiResponse.
// It takes the `data` of type `T` and the `response` as parameters, and returns an ApiResponse[T] struct.
func NewApiResponse[T any](data T, response *http.Response) ApiResponse[T] {
apiResponse := ApiResponse[T]{
Data: data,
Expand Down
Loading

0 comments on commit f35951a

Please sign in to comment.