Skip to content

Commit 7655948

Browse files
committed
Update readme
1 parent a5c2b0c commit 7655948

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Duffel API Go Client
22

3-
A Go (golang) client library for the [Duffel](https://duffel.com) API implemented by the Airheart team.
3+
A Go (golang) client library for the [Duffel Flights API](https://duffel.com) implemented by the [Airheart](https://airheart.com) team.
44

55
[![Tests](https://github.com/airheartdev/duffel/actions/workflows/ci.yaml/badge.svg)](https://github.com/airheartdev/duffel/actions/workflows/ci.yaml)
66

77
## Installation
88

9-
**Requires at least Go 1.18-rc1 since we use generics on the internal API client**
9+
We've designed this pkg to be familiar and ideomatic to any Go developer. Go get it the usual way:
10+
11+
> NOTE: Requires at least Go 1.18 since we use generics on the internal API client
1012
1113
```shell
1214
go get github.com/airheartdev/duffel
@@ -22,7 +24,7 @@ The easiest way to get started, assuming you have a Duffel account set up and an
2224

2325
```go
2426
// Create a new client:
25-
client := duffel.New(os.Getenv("DUFFEL_TOKEN"))
27+
dfl := duffel.New(os.Getenv("DUFFEL_TOKEN"))
2628
```
2729

2830
For available methods, see:
@@ -48,8 +50,8 @@ total.String() // 100.00 USD
4850
All requests that return more than one record will return an iterator. An Iterator automatically paginates results and respects rate limits, reducing the complexity of the overall programming model.
4951

5052
```go
51-
client := duffel.New(os.Getenv("DUFFEL_TOKEN"))
52-
iter := client.ListAirports(ctx, duffel.ListAirportsParams{
53+
dfl := duffel.New(os.Getenv("DUFFEL_TOKEN"))
54+
iter := dfl.ListAirports(ctx, duffel.ListAirportsParams{
5355
IATACountryCode: "AU",
5456
})
5557

@@ -76,14 +78,20 @@ if err != nil {
7678
// airports is a []*duffel.Airport
7779
```
7880

79-
### Error Handling
81+
## Error Handling
8082

8183
Each API method returns an error or an iterator that returns errors at each iteration. If an error is returned from Duffel, it will be of type `DuffelError` and expose more details on how to handle it.
8284

8385
```go
8486
// Example error inspection after making an API call:
85-
offer, err := client.GetOffer(ctx, "off_123")
87+
offer, err := dfl.GetOffer(ctx, "off_123")
8688
if err != nil {
89+
// Simple error code check
90+
if duffel.IsErrorCode(err, duffel.AirlineInternal) {
91+
// Don't retry airline errors, contact support
92+
}
93+
94+
// Access the DuffelError object to see more detail
8795
if derr, ok:= err.(*duffel.DuffelError); ok {
8896
// derr.Errors[0].Type etc
8997
// derr.IsCode(duffel.BadRequest)
@@ -93,6 +101,16 @@ if err != nil {
93101
}
94102
```
95103

104+
### `duffel.IsErrorCode(err, code)`
105+
106+
`IsErrorCode` is a concenience method to check if an error is a specific error code from Duffel.
107+
This simplifies error handling branches without needing to type cast multiple times in your code.
108+
109+
### `duffel.IsErrorType(err, typ)`
110+
111+
`IsErrorType` is a concenience method to check if an error is a specific error type from Duffel.
112+
This simplifies error handling branches without needing to type cast multiple times in your code.
113+
96114
You can also check the `derr.Retryable` field, which will be false if you need to contact Duffel support to resolve the issue, and should not be retried. Example, creating an order.
97115

98116
## Implementation status
@@ -118,7 +136,7 @@ To maintain simplicity and ease of use, this client library is hand-coded (inste
118136
- [x] Airports
119137
- [x] Airlines
120138
- [x] Equipment (Aircraft)
121-
- [ ] Payments
139+
- [ ] Payments (Looking for contributions)
122140

123141
## License
124142

0 commit comments

Comments
 (0)