-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1978cfc
commit 0d73e1d
Showing
14 changed files
with
746 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// This file was auto-generated by Fern from our API Definition. | ||
|
||
package api | ||
|
||
import ( | ||
json "encoding/json" | ||
fmt "fmt" | ||
core "github.com/trycourier/courier-go/v3/core" | ||
) | ||
|
||
type InboundTrackEvent struct { | ||
// A descriptive name of the event. This name will appear as a trigger in the Courier Automation Trigger node. | ||
Event string `json:"event" url:"event"` | ||
// A required unique identifier that will be used to de-duplicate requests. If not unique, will respond with 409 Conflict status | ||
MessageId string `json:"messageId" url:"messageId"` | ||
Properties map[string]interface{} `json:"properties,omitempty" url:"properties,omitempty"` | ||
// The user id assocatiated with the track | ||
UserId *string `json:"userId,omitempty" url:"userId,omitempty"` | ||
type_ string | ||
|
||
_rawJSON json.RawMessage | ||
} | ||
|
||
func (i *InboundTrackEvent) Type() string { | ||
return i.type_ | ||
} | ||
|
||
func (i *InboundTrackEvent) UnmarshalJSON(data []byte) error { | ||
type embed InboundTrackEvent | ||
var unmarshaler = struct { | ||
embed | ||
}{ | ||
embed: embed(*i), | ||
} | ||
if err := json.Unmarshal(data, &unmarshaler); err != nil { | ||
return err | ||
} | ||
*i = InboundTrackEvent(unmarshaler.embed) | ||
i.type_ = "track" | ||
i._rawJSON = json.RawMessage(data) | ||
return nil | ||
} | ||
|
||
func (i *InboundTrackEvent) MarshalJSON() ([]byte, error) { | ||
type embed InboundTrackEvent | ||
var marshaler = struct { | ||
embed | ||
Type string `json:"type"` | ||
}{ | ||
embed: embed(*i), | ||
Type: "track", | ||
} | ||
return json.Marshal(marshaler) | ||
} | ||
|
||
func (i *InboundTrackEvent) String() string { | ||
if len(i._rawJSON) > 0 { | ||
if value, err := core.StringifyJSON(i._rawJSON); err == nil { | ||
return value | ||
} | ||
} | ||
if value, err := core.StringifyJSON(i); err == nil { | ||
return value | ||
} | ||
return fmt.Sprintf("%#v", i) | ||
} | ||
|
||
type TrackAcceptedResponse struct { | ||
// A successful call returns a `202` status code along with a `requestId` in the response body. | ||
MessageId string `json:"messageId" url:"messageId"` | ||
|
||
_rawJSON json.RawMessage | ||
} | ||
|
||
func (t *TrackAcceptedResponse) UnmarshalJSON(data []byte) error { | ||
type unmarshaler TrackAcceptedResponse | ||
var value unmarshaler | ||
if err := json.Unmarshal(data, &value); err != nil { | ||
return err | ||
} | ||
*t = TrackAcceptedResponse(value) | ||
t._rawJSON = json.RawMessage(data) | ||
return nil | ||
} | ||
|
||
func (t *TrackAcceptedResponse) String() string { | ||
if len(t._rawJSON) > 0 { | ||
if value, err := core.StringifyJSON(t._rawJSON); err == nil { | ||
return value | ||
} | ||
} | ||
if value, err := core.StringifyJSON(t); err == nil { | ||
return value | ||
} | ||
return fmt.Sprintf("%#v", t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// This file was auto-generated by Fern from our API Definition. | ||
|
||
package inbound | ||
|
||
import ( | ||
bytes "bytes" | ||
context "context" | ||
json "encoding/json" | ||
errors "errors" | ||
v3 "github.com/trycourier/courier-go/v3" | ||
core "github.com/trycourier/courier-go/v3/core" | ||
option "github.com/trycourier/courier-go/v3/option" | ||
io "io" | ||
http "net/http" | ||
) | ||
|
||
type Client struct { | ||
baseURL string | ||
caller *core.Caller | ||
header http.Header | ||
} | ||
|
||
func NewClient(opts ...option.RequestOption) *Client { | ||
options := core.NewRequestOptions(opts...) | ||
return &Client{ | ||
baseURL: options.BaseURL, | ||
caller: core.NewCaller( | ||
&core.CallerParams{ | ||
Client: options.HTTPClient, | ||
MaxAttempts: options.MaxAttempts, | ||
}, | ||
), | ||
header: options.ToHeader(), | ||
} | ||
} | ||
|
||
func (c *Client) Track( | ||
ctx context.Context, | ||
request *v3.InboundTrackEvent, | ||
opts ...option.RequestOption, | ||
) (*v3.TrackAcceptedResponse, error) { | ||
options := core.NewRequestOptions(opts...) | ||
|
||
baseURL := "https://api.courier.com" | ||
if c.baseURL != "" { | ||
baseURL = c.baseURL | ||
} | ||
if options.BaseURL != "" { | ||
baseURL = options.BaseURL | ||
} | ||
endpointURL := baseURL + "/" + "inbound/courier" | ||
|
||
headers := core.MergeHeaders(c.header.Clone(), options.ToHeader()) | ||
|
||
errorDecoder := func(statusCode int, body io.Reader) error { | ||
raw, err := io.ReadAll(body) | ||
if err != nil { | ||
return err | ||
} | ||
apiError := core.NewAPIError(statusCode, errors.New(string(raw))) | ||
decoder := json.NewDecoder(bytes.NewReader(raw)) | ||
switch statusCode { | ||
case 400: | ||
value := new(v3.BadRequestError) | ||
value.APIError = apiError | ||
if err := decoder.Decode(value); err != nil { | ||
return apiError | ||
} | ||
return value | ||
case 409: | ||
value := new(v3.ConflictError) | ||
value.APIError = apiError | ||
if err := decoder.Decode(value); err != nil { | ||
return apiError | ||
} | ||
return value | ||
} | ||
return apiError | ||
} | ||
|
||
var response *v3.TrackAcceptedResponse | ||
if err := c.caller.Call( | ||
ctx, | ||
&core.CallParams{ | ||
URL: endpointURL, | ||
Method: http.MethodPost, | ||
MaxAttempts: options.MaxAttempts, | ||
Headers: headers, | ||
Client: options.HTTPClient, | ||
Request: request, | ||
Response: &response, | ||
ErrorDecoder: errorDecoder, | ||
}, | ||
); err != nil { | ||
return nil, err | ||
} | ||
return response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.