Skip to content

Commit

Permalink
feat: Add WithContext methods
Browse files Browse the repository at this point in the history
  • Loading branch information
processout-machine committed Feb 21, 2025
1 parent 8a47415 commit 87b3083
Show file tree
Hide file tree
Showing 33 changed files with 978 additions and 121 deletions.
17 changes: 15 additions & 2 deletions activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -81,6 +82,11 @@ type ActivityAllParameters struct {

// All allows you to get all the project activities.
func (s Activity) All(options ...ActivityAllParameters) (*Iterator, error) {
return s.AllWithContext(context.Background(), options...)
}

// All allows you to get all the project activities., passes the provided context to the request
func (s Activity) AllWithContext(ctx context.Context, options ...ActivityAllParameters) (*Iterator, error) {
if s.client == nil {
panic("Please use the client.NewActivity() method to create a new Activity object")
}
Expand Down Expand Up @@ -119,7 +125,8 @@ func (s Activity) All(options ...ActivityAllParameters) (*Iterator, error) {

path := "/activities"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -188,6 +195,11 @@ type ActivityFindParameters struct {

// Find allows you to find a specific activity and fetch its data.
func (s Activity) Find(activityID string, options ...ActivityFindParameters) (*Activity, error) {
return s.FindWithContext(context.Background(), activityID, options...)
}

// Find allows you to find a specific activity and fetch its data., passes the provided context to the request
func (s Activity) FindWithContext(ctx context.Context, activityID string, options ...ActivityFindParameters) (*Activity, error) {
if s.client == nil {
panic("Please use the client.NewActivity() method to create a new Activity object")
}
Expand Down Expand Up @@ -225,7 +237,8 @@ func (s Activity) Find(activityID string, options ...ActivityFindParameters) (*A

path := "/activities/" + url.QueryEscape(activityID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down
41 changes: 36 additions & 5 deletions addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -108,6 +109,11 @@ type AddonFetchSubscriptionAddonsParameters struct {

// FetchSubscriptionAddons allows you to get the addons applied to the subscription.
func (s Addon) FetchSubscriptionAddons(subscriptionID string, options ...AddonFetchSubscriptionAddonsParameters) (*Iterator, error) {
return s.FetchSubscriptionAddonsWithContext(context.Background(), subscriptionID, options...)
}

// FetchSubscriptionAddons allows you to get the addons applied to the subscription., passes the provided context to the request
func (s Addon) FetchSubscriptionAddonsWithContext(ctx context.Context, subscriptionID string, options ...AddonFetchSubscriptionAddonsParameters) (*Iterator, error) {
if s.client == nil {
panic("Please use the client.NewAddon() method to create a new Addon object")
}
Expand Down Expand Up @@ -146,7 +152,8 @@ func (s Addon) FetchSubscriptionAddons(subscriptionID string, options ...AddonFe

path := "/subscriptions/" + url.QueryEscape(subscriptionID) + "/addons"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -218,6 +225,11 @@ type AddonCreateParameters struct {

// Create allows you to create a new addon to the given subscription ID.
func (s Addon) Create(options ...AddonCreateParameters) (*Addon, error) {
return s.CreateWithContext(context.Background(), options...)
}

// Create allows you to create a new addon to the given subscription ID., passes the provided context to the request
func (s Addon) CreateWithContext(ctx context.Context, options ...AddonCreateParameters) (*Addon, error) {
if s.client == nil {
panic("Please use the client.NewAddon() method to create a new Addon object")
}
Expand Down Expand Up @@ -273,7 +285,8 @@ func (s Addon) Create(options ...AddonCreateParameters) (*Addon, error) {

path := "/subscriptions/" + url.QueryEscape(*s.SubscriptionID) + "/addons"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"POST",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -317,6 +330,11 @@ type AddonFindParameters struct {

// Find allows you to find a subscription's addon by its ID.
func (s Addon) Find(subscriptionID, addonID string, options ...AddonFindParameters) (*Addon, error) {
return s.FindWithContext(context.Background(), subscriptionID, addonID, options...)
}

// Find allows you to find a subscription's addon by its ID., passes the provided context to the request
func (s Addon) FindWithContext(ctx context.Context, subscriptionID, addonID string, options ...AddonFindParameters) (*Addon, error) {
if s.client == nil {
panic("Please use the client.NewAddon() method to create a new Addon object")
}
Expand Down Expand Up @@ -354,7 +372,8 @@ func (s Addon) Find(subscriptionID, addonID string, options ...AddonFindParamete

path := "/subscriptions/" + url.QueryEscape(subscriptionID) + "/addons/" + url.QueryEscape(addonID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -402,6 +421,11 @@ type AddonSaveParameters struct {

// Save allows you to save the updated addon attributes.
func (s Addon) Save(options ...AddonSaveParameters) (*Addon, error) {
return s.SaveWithContext(context.Background(), options...)
}

// Save allows you to save the updated addon attributes., passes the provided context to the request
func (s Addon) SaveWithContext(ctx context.Context, options ...AddonSaveParameters) (*Addon, error) {
if s.client == nil {
panic("Please use the client.NewAddon() method to create a new Addon object")
}
Expand Down Expand Up @@ -459,7 +483,8 @@ func (s Addon) Save(options ...AddonSaveParameters) (*Addon, error) {

path := "/subscriptions/" + url.QueryEscape(*s.SubscriptionID) + "/addons/" + url.QueryEscape(*s.ID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"PUT",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -506,6 +531,11 @@ type AddonDeleteParameters struct {

// Delete allows you to delete an addon applied to a subscription.
func (s Addon) Delete(options ...AddonDeleteParameters) error {
return s.DeleteWithContext(context.Background(), options...)
}

// Delete allows you to delete an addon applied to a subscription., passes the provided context to the request
func (s Addon) DeleteWithContext(ctx context.Context, options ...AddonDeleteParameters) error {
if s.client == nil {
panic("Please use the client.NewAddon() method to create a new Addon object")
}
Expand Down Expand Up @@ -548,7 +578,8 @@ func (s Addon) Delete(options ...AddonDeleteParameters) error {

path := "/subscriptions/" + url.QueryEscape(*s.SubscriptionID) + "/addons/" + url.QueryEscape(*s.ID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"DELETE",
Host+path,
bytes.NewReader(body),
Expand Down
17 changes: 15 additions & 2 deletions alternative_merchant_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -60,6 +61,11 @@ type AlternativeMerchantCertificateSaveParameters struct {

// Save allows you to save new alternative apple pay certificates
func (s AlternativeMerchantCertificate) Save(options ...AlternativeMerchantCertificateSaveParameters) (*AlternativeMerchantCertificate, error) {
return s.SaveWithContext(context.Background(), options...)
}

// Save allows you to save new alternative apple pay certificates, passes the provided context to the request
func (s AlternativeMerchantCertificate) SaveWithContext(ctx context.Context, options ...AlternativeMerchantCertificateSaveParameters) (*AlternativeMerchantCertificate, error) {
if s.client == nil {
panic("Please use the client.NewAlternativeMerchantCertificate() method to create a new AlternativeMerchantCertificate object")
}
Expand Down Expand Up @@ -97,7 +103,8 @@ func (s AlternativeMerchantCertificate) Save(options ...AlternativeMerchantCerti

path := "/projects/applepay/alternative-merchant-certificates"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"POST",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -141,6 +148,11 @@ type AlternativeMerchantCertificateDeleteParameters struct {

// Delete allows you to delete a given alternative merchant certificate
func (s AlternativeMerchantCertificate) Delete(options ...AlternativeMerchantCertificateDeleteParameters) error {
return s.DeleteWithContext(context.Background(), options...)
}

// Delete allows you to delete a given alternative merchant certificate, passes the provided context to the request
func (s AlternativeMerchantCertificate) DeleteWithContext(ctx context.Context, options ...AlternativeMerchantCertificateDeleteParameters) error {
if s.client == nil {
panic("Please use the client.NewAlternativeMerchantCertificate() method to create a new AlternativeMerchantCertificate object")
}
Expand Down Expand Up @@ -177,7 +189,8 @@ func (s AlternativeMerchantCertificate) Delete(options ...AlternativeMerchantCer

path := "/projects/applepay/alternative-merchant-certificates/" + url.QueryEscape(*s.ID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"DELETE",
Host+path,
bytes.NewReader(body),
Expand Down
9 changes: 8 additions & 1 deletion apple_pay_alternative_merchant_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -54,6 +55,11 @@ type ApplePayAlternativeMerchantCertificatesFetchParameters struct {

// Fetch allows you to fetch the project's alternative certificates by ID
func (s ApplePayAlternativeMerchantCertificates) Fetch(options ...ApplePayAlternativeMerchantCertificatesFetchParameters) (*ApplePayAlternativeMerchantCertificates, error) {
return s.FetchWithContext(context.Background(), options...)
}

// Fetch allows you to fetch the project's alternative certificates by ID, passes the provided context to the request
func (s ApplePayAlternativeMerchantCertificates) FetchWithContext(ctx context.Context, options ...ApplePayAlternativeMerchantCertificatesFetchParameters) (*ApplePayAlternativeMerchantCertificates, error) {
if s.client == nil {
panic("Please use the client.NewApplePayAlternativeMerchantCertificates() method to create a new ApplePayAlternativeMerchantCertificates object")
}
Expand Down Expand Up @@ -91,7 +97,8 @@ func (s ApplePayAlternativeMerchantCertificates) Fetch(options ...ApplePayAltern

path := "/projects/applepay/alternative-merchant-certificates"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down
9 changes: 8 additions & 1 deletion balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -51,6 +52,11 @@ type BalancesFindParameters struct {

// Find allows you to fetch a customer token's balance
func (s Balances) Find(tokenID string, options ...BalancesFindParameters) (*Balances, error) {
return s.FindWithContext(context.Background(), tokenID, options...)
}

// Find allows you to fetch a customer token's balance, passes the provided context to the request
func (s Balances) FindWithContext(ctx context.Context, tokenID string, options ...BalancesFindParameters) (*Balances, error) {
if s.client == nil {
panic("Please use the client.NewBalances() method to create a new Balances object")
}
Expand Down Expand Up @@ -88,7 +94,8 @@ func (s Balances) Find(tokenID string, options ...BalancesFindParameters) (*Bala

path := "/balances/tokens/" + url.QueryEscape(tokenID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down
25 changes: 22 additions & 3 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -162,6 +163,11 @@ type CardAllParameters struct {

// All allows you to get all the cards.
func (s Card) All(options ...CardAllParameters) (*Iterator, error) {
return s.AllWithContext(context.Background(), options...)
}

// All allows you to get all the cards., passes the provided context to the request
func (s Card) AllWithContext(ctx context.Context, options ...CardAllParameters) (*Iterator, error) {
if s.client == nil {
panic("Please use the client.NewCard() method to create a new Card object")
}
Expand Down Expand Up @@ -200,7 +206,8 @@ func (s Card) All(options ...CardAllParameters) (*Iterator, error) {

path := "/cards"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -269,6 +276,11 @@ type CardFindParameters struct {

// Find allows you to find a card by its ID.
func (s Card) Find(cardID string, options ...CardFindParameters) (*Card, error) {
return s.FindWithContext(context.Background(), cardID, options...)
}

// Find allows you to find a card by its ID., passes the provided context to the request
func (s Card) FindWithContext(ctx context.Context, cardID string, options ...CardFindParameters) (*Card, error) {
if s.client == nil {
panic("Please use the client.NewCard() method to create a new Card object")
}
Expand Down Expand Up @@ -306,7 +318,8 @@ func (s Card) Find(cardID string, options ...CardFindParameters) (*Card, error)

path := "/cards/" + url.QueryEscape(cardID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"GET",
Host+path,
bytes.NewReader(body),
Expand Down Expand Up @@ -350,6 +363,11 @@ type CardAnonymizeParameters struct {

// Anonymize allows you to anonymize the card.
func (s Card) Anonymize(options ...CardAnonymizeParameters) error {
return s.AnonymizeWithContext(context.Background(), options...)
}

// Anonymize allows you to anonymize the card., passes the provided context to the request
func (s Card) AnonymizeWithContext(ctx context.Context, options ...CardAnonymizeParameters) error {
if s.client == nil {
panic("Please use the client.NewCard() method to create a new Card object")
}
Expand Down Expand Up @@ -386,7 +404,8 @@ func (s Card) Anonymize(options ...CardAnonymizeParameters) error {

path := "/cards/" + url.QueryEscape(*s.ID) + ""

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"DELETE",
Host+path,
bytes.NewReader(body),
Expand Down
9 changes: 8 additions & 1 deletion card_create_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processout

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
Expand Down Expand Up @@ -108,6 +109,11 @@ type CardCreateRequestCreateParameters struct {

// Create allows you to create a new card.
func (s CardCreateRequest) Create(options ...CardCreateRequestCreateParameters) (*CardCreateRequest, error) {
return s.CreateWithContext(context.Background(), options...)
}

// Create allows you to create a new card., passes the provided context to the request
func (s CardCreateRequest) CreateWithContext(ctx context.Context, options ...CardCreateRequestCreateParameters) (*CardCreateRequest, error) {
if s.client == nil {
panic("Please use the client.NewCardCreateRequest() method to create a new CardCreateRequest object")
}
Expand Down Expand Up @@ -179,7 +185,8 @@ func (s CardCreateRequest) Create(options ...CardCreateRequestCreateParameters)

path := "/cards"

req, err := http.NewRequest(
req, err := http.NewRequestWithContext(
ctx,
"POST",
Host+path,
bytes.NewReader(body),
Expand Down
Loading

0 comments on commit 87b3083

Please sign in to comment.