From 5bcc3babfa333d57cd704c28327ca8fc7b87c4b5 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Mon, 27 Mar 2023 20:05:45 +0000 Subject: [PATCH] ci: regenerated with OpenAPI Doc 0.6.0, Speakeay CLI 1.18.9 --- README.md | 152 +++++++ RELEASES.md | 9 + USAGE.md | 94 +++++ accounts.go | 307 ++++++++++++++ contacts.go | 307 ++++++++++++++ files.gen | 59 +++ gen.yaml | 7 +- go.mod | 7 + go.sum | 2 + leads.go | 247 ++++++++++++ opportunities.go | 307 ++++++++++++++ passthrough.go | 90 +++++ pkg/models/operations/createaccount.go | 40 ++ pkg/models/operations/createcontact.go | 40 ++ pkg/models/operations/createlead.go | 40 ++ pkg/models/operations/createopportunity.go | 40 ++ pkg/models/operations/getaccount.go | 38 ++ pkg/models/operations/getcontact.go | 38 ++ pkg/models/operations/getlead.go | 38 ++ pkg/models/operations/getopportunity.go | 38 ++ pkg/models/operations/getuser.go | 32 ++ pkg/models/operations/listaccounts.go | 53 +++ pkg/models/operations/listcontacts.go | 53 +++ pkg/models/operations/listleads.go | 53 +++ pkg/models/operations/listopportunities.go | 53 +++ pkg/models/operations/listusers.go | 53 +++ pkg/models/operations/searchaccounts.go | 51 +++ pkg/models/operations/searchcontacts.go | 51 +++ pkg/models/operations/searchopportunities.go | 51 +++ .../operations/sendpassthroughrequest.go | 85 ++++ pkg/models/operations/updateaccount.go | 45 +++ pkg/models/operations/updatecontact.go | 45 +++ pkg/models/operations/updatelead.go | 45 +++ pkg/models/operations/updateopportunity.go | 45 +++ pkg/models/shared/account.go | 25 ++ pkg/models/shared/addresses.go | 50 +++ pkg/models/shared/contact.go | 25 ++ pkg/models/shared/createupdateaccount.go | 16 + pkg/models/shared/createupdatecontact.go | 15 + pkg/models/shared/createupdatelead.go | 16 + pkg/models/shared/createupdateopportunity.go | 15 + pkg/models/shared/emailaddresses.go | 36 ++ pkg/models/shared/errors.go | 14 + pkg/models/shared/filter.go | 79 ++++ pkg/models/shared/lead.go | 30 ++ pkg/models/shared/logs.go | 15 + pkg/models/shared/opportunity.go | 26 ++ pkg/models/shared/phonenumbers.go | 39 ++ pkg/models/shared/security.go | 11 + pkg/models/shared/user.go | 18 + pkg/models/shared/warnings.go | 14 + pkg/types/date.go | 38 ++ pkg/utils/contenttype.go | 33 ++ pkg/utils/form.go | 108 +++++ pkg/utils/headers.go | 100 +++++ pkg/utils/pathparams.go | 115 ++++++ pkg/utils/queryparams.go | 173 ++++++++ pkg/utils/requestbody.go | 373 ++++++++++++++++++ pkg/utils/retries.go | 117 ++++++ pkg/utils/security.go | 284 +++++++++++++ pkg/utils/utils.go | 142 +++++++ sdk.go | 174 ++++++++ users.go | 131 ++++++ 63 files changed, 4846 insertions(+), 1 deletion(-) create mode 100755 README.md create mode 100644 RELEASES.md create mode 100755 USAGE.md create mode 100755 accounts.go create mode 100755 contacts.go create mode 100755 files.gen create mode 100755 go.mod create mode 100755 go.sum create mode 100755 leads.go create mode 100755 opportunities.go create mode 100755 passthrough.go create mode 100755 pkg/models/operations/createaccount.go create mode 100755 pkg/models/operations/createcontact.go create mode 100755 pkg/models/operations/createlead.go create mode 100755 pkg/models/operations/createopportunity.go create mode 100755 pkg/models/operations/getaccount.go create mode 100755 pkg/models/operations/getcontact.go create mode 100755 pkg/models/operations/getlead.go create mode 100755 pkg/models/operations/getopportunity.go create mode 100755 pkg/models/operations/getuser.go create mode 100755 pkg/models/operations/listaccounts.go create mode 100755 pkg/models/operations/listcontacts.go create mode 100755 pkg/models/operations/listleads.go create mode 100755 pkg/models/operations/listopportunities.go create mode 100755 pkg/models/operations/listusers.go create mode 100755 pkg/models/operations/searchaccounts.go create mode 100755 pkg/models/operations/searchcontacts.go create mode 100755 pkg/models/operations/searchopportunities.go create mode 100755 pkg/models/operations/sendpassthroughrequest.go create mode 100755 pkg/models/operations/updateaccount.go create mode 100755 pkg/models/operations/updatecontact.go create mode 100755 pkg/models/operations/updatelead.go create mode 100755 pkg/models/operations/updateopportunity.go create mode 100755 pkg/models/shared/account.go create mode 100755 pkg/models/shared/addresses.go create mode 100755 pkg/models/shared/contact.go create mode 100755 pkg/models/shared/createupdateaccount.go create mode 100755 pkg/models/shared/createupdatecontact.go create mode 100755 pkg/models/shared/createupdatelead.go create mode 100755 pkg/models/shared/createupdateopportunity.go create mode 100755 pkg/models/shared/emailaddresses.go create mode 100755 pkg/models/shared/errors.go create mode 100755 pkg/models/shared/filter.go create mode 100755 pkg/models/shared/lead.go create mode 100755 pkg/models/shared/logs.go create mode 100755 pkg/models/shared/opportunity.go create mode 100755 pkg/models/shared/phonenumbers.go create mode 100755 pkg/models/shared/security.go create mode 100755 pkg/models/shared/user.go create mode 100755 pkg/models/shared/warnings.go create mode 100755 pkg/types/date.go create mode 100755 pkg/utils/contenttype.go create mode 100755 pkg/utils/form.go create mode 100755 pkg/utils/headers.go create mode 100755 pkg/utils/pathparams.go create mode 100755 pkg/utils/queryparams.go create mode 100755 pkg/utils/requestbody.go create mode 100755 pkg/utils/retries.go create mode 100755 pkg/utils/security.go create mode 100755 pkg/utils/utils.go create mode 100755 sdk.go create mode 100755 users.go diff --git a/README.md b/README.md new file mode 100755 index 0000000..27bb04d --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ +# supaglue + + +## SDK Installation + +```bash +go get github.com/chase-crumbaugh/supaglue-test +``` + + +## SDK Example Usage + +```go +package main + +import ( + "context" + "log" + "supaglue" + "supaglue/pkg/models/shared" + "supaglue/pkg/models/operations" +) + +func main() { + s := sdk.New( + sdk.WithSecurity(shared.Security{ + APIKeyAuth: shared.SchemeAPIKeyAuth{ + APIKey: "YOUR_API_KEY_HERE", + }, + }), + ) + + req := operations.CreateAccountRequest{ + Headers: operations.CreateAccountHeaders{ + XCustomerID: "my-customer-1", + XProviderName: "salesforce", + }, + Request: operations.CreateAccountRequestBody{ + Model: shared.CreateUpdateAccount{ + Addresses: []shared.Addresses{ + shared.Addresses{ + AddressType: "other", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + shared.Addresses{ + AddressType: "billing", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + shared.Addresses{ + AddressType: "shipping", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + }, + CustomFields: map[string]interface{}{ + "vero": "perspiciatis", + "nulla": "nihil", + "fuga": "facilis", + }, + Description: "Integration API", + Industry: "API's", + Name: "Sample Customer", + NumberOfEmployees: 276000, + OwnerID: "9f3e97fd-4d5d-4efc-959d-bbebfac079f5", + PhoneNumbers: []shared.PhoneNumbers{ + shared.PhoneNumbers{ + PhoneNumber: "+14151234567", + PhoneNumberType: "mobile", + }, + shared.PhoneNumbers{ + PhoneNumber: "+14151234567", + PhoneNumberType: "primary", + }, + }, + Website: "https://supaglue.com/", + }, + }, + } + + ctx := context.Background() + res, err := s.Accounts.Create(ctx, req) + if err != nil { + log.Fatal(err) + } + + if res.CreateAccount201ApplicationJSONObject != nil { + // handle response + } +} +``` + + + +## SDK Available Operations + + +### Accounts + +* `Create` - Create account +* `Get` - Get account +* `List` - List accounts +* `Search` - Search accounts +* `Update` - Update account + +### Contacts + +* `Create` - Create contact +* `Get` - Get contact +* `List` - List contacts +* `Search` - Search contacts +* `Update` - Update contact + +### Leads + +* `Create` - Create lead +* `Get` - Get lead +* `List` - List leads +* `Update` - Update lead + +### Opportunities + +* `Create` - Create opportunity +* `Get` - Get opportunity +* `List` - List opportunities +* `Search` - Search Opportunities +* `Update` - Update opportunity + +### Passthrough + +* `Send` - Send passthrough request + +### Users + +* `Get` - Get user +* `List` - List users + + +### SDK Generated by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks) diff --git a/RELEASES.md b/RELEASES.md new file mode 100644 index 0000000..52f3473 --- /dev/null +++ b/RELEASES.md @@ -0,0 +1,9 @@ + + +## 2023-03-27 20:05:36 +### Changes +Based on: +- OpenAPI Doc 0.6.0 https://prod.speakeasyapi.dev/v1/apis/test-2-27/version/v1/schema/download +- Speakeasy CLI 1.18.9 (2.16.4) https://github.com/speakeasy-api/speakeasy +### Releases +- [Go v1.0.0] https://github.com/chase-crumbaugh/supaglue-test/releases/tag/v1.0.0 - . \ No newline at end of file diff --git a/USAGE.md b/USAGE.md new file mode 100755 index 0000000..a5fd593 --- /dev/null +++ b/USAGE.md @@ -0,0 +1,94 @@ + +```go +package main + +import ( + "context" + "log" + "supaglue" + "supaglue/pkg/models/shared" + "supaglue/pkg/models/operations" +) + +func main() { + s := sdk.New( + sdk.WithSecurity(shared.Security{ + APIKeyAuth: shared.SchemeAPIKeyAuth{ + APIKey: "YOUR_API_KEY_HERE", + }, + }), + ) + + req := operations.CreateAccountRequest{ + Headers: operations.CreateAccountHeaders{ + XCustomerID: "my-customer-1", + XProviderName: "salesforce", + }, + Request: operations.CreateAccountRequestBody{ + Model: shared.CreateUpdateAccount{ + Addresses: []shared.Addresses{ + shared.Addresses{ + AddressType: "other", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + shared.Addresses{ + AddressType: "billing", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + shared.Addresses{ + AddressType: "shipping", + City: "San Francisco", + Country: "USA", + PostalCode: "94107", + State: "CA", + Street1: "525 Brannan", + Street2: "null", + }, + }, + CustomFields: map[string]interface{}{ + "vero": "perspiciatis", + "nulla": "nihil", + "fuga": "facilis", + }, + Description: "Integration API", + Industry: "API's", + Name: "Sample Customer", + NumberOfEmployees: 276000, + OwnerID: "9f3e97fd-4d5d-4efc-959d-bbebfac079f5", + PhoneNumbers: []shared.PhoneNumbers{ + shared.PhoneNumbers{ + PhoneNumber: "+14151234567", + PhoneNumberType: "mobile", + }, + shared.PhoneNumbers{ + PhoneNumber: "+14151234567", + PhoneNumberType: "primary", + }, + }, + Website: "https://supaglue.com/", + }, + }, + } + + ctx := context.Background() + res, err := s.Accounts.Create(ctx, req) + if err != nil { + log.Fatal(err) + } + + if res.CreateAccount201ApplicationJSONObject != nil { + // handle response + } +} +``` + \ No newline at end of file diff --git a/accounts.go b/accounts.go new file mode 100755 index 0000000..6d8a7c2 --- /dev/null +++ b/accounts.go @@ -0,0 +1,307 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" +) + +// accounts - The `Account` Common Model is used to represent a "company" in CRMs. +type accounts struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newAccounts(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *accounts { + return &accounts{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Create - Create account +func (s *accounts) Create(ctx context.Context, request operations.CreateAccountRequest) (*operations.CreateAccountResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/accounts" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.CreateAccountResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 201: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.CreateAccount201ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.CreateAccount201ApplicationJSONObject = out + } + } + + return res, nil +} + +// Get - Get account +func (s *accounts) Get(ctx context.Context, request operations.GetAccountRequest) (*operations.GetAccountResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/accounts/{account_id}", request.PathParams, nil) + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.GetAccountResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *shared.Account + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.Account = out + } + } + + return res, nil +} + +// List - List accounts +// Get a list of accounts +func (s *accounts) List(ctx context.Context, request operations.ListAccountsRequest) (*operations.ListAccountsResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/accounts" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.ListAccountsResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.ListAccounts200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.ListAccounts200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Search - Search accounts +func (s *accounts) Search(ctx context.Context, request operations.SearchAccountsRequest) (*operations.SearchAccountsResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/accounts/_search" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.SearchAccountsResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.SearchAccounts200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.SearchAccounts200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Update - Update account +func (s *accounts) Update(ctx context.Context, request operations.UpdateAccountRequest) (*operations.UpdateAccountResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/accounts/{account_id}", request.PathParams, nil) + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "PATCH", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.UpdateAccountResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.UpdateAccount200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.UpdateAccount200ApplicationJSONObject = out + } + } + + return res, nil +} diff --git a/contacts.go b/contacts.go new file mode 100755 index 0000000..84387fc --- /dev/null +++ b/contacts.go @@ -0,0 +1,307 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" +) + +// contacts - The `Contact` Common Model is used to represent a "contact" in CRMs. +type contacts struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newContacts(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *contacts { + return &contacts{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Create - Create contact +func (s *contacts) Create(ctx context.Context, request operations.CreateContactRequest) (*operations.CreateContactResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/contacts" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.CreateContactResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 201: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.CreateContact201ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.CreateContact201ApplicationJSONObject = out + } + } + + return res, nil +} + +// Get - Get contact +func (s *contacts) Get(ctx context.Context, request operations.GetContactRequest) (*operations.GetContactResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/contacts/{contact_id}", request.PathParams, nil) + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.GetContactResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *shared.Contact + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.Contact = out + } + } + + return res, nil +} + +// List - List contacts +// Get a list of contacts +func (s *contacts) List(ctx context.Context, request operations.ListContactsRequest) (*operations.ListContactsResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/contacts" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.ListContactsResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.ListContacts200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.ListContacts200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Search - Search contacts +func (s *contacts) Search(ctx context.Context, request operations.SearchContactsRequest) (*operations.SearchContactsResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/contacts/_search" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.SearchContactsResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.SearchContacts200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.SearchContacts200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Update - Update contact +func (s *contacts) Update(ctx context.Context, request operations.UpdateContactRequest) (*operations.UpdateContactResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/contacts/{contact_id}", request.PathParams, nil) + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "PATCH", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.UpdateContactResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.UpdateContact200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.UpdateContact200ApplicationJSONObject = out + } + } + + return res, nil +} diff --git a/files.gen b/files.gen new file mode 100755 index 0000000..115d232 --- /dev/null +++ b/files.gen @@ -0,0 +1,59 @@ +accounts.go +contacts.go +leads.go +opportunities.go +passthrough.go +users.go +sdk.go +go.mod +go.sum +pkg/types/date.go +pkg/utils/contenttype.go +pkg/utils/form.go +pkg/utils/headers.go +pkg/utils/pathparams.go +pkg/utils/queryparams.go +pkg/utils/requestbody.go +pkg/utils/retries.go +pkg/utils/security.go +pkg/utils/utils.go +pkg/models/operations/createaccount.go +pkg/models/operations/getaccount.go +pkg/models/operations/listaccounts.go +pkg/models/operations/searchaccounts.go +pkg/models/operations/updateaccount.go +pkg/models/operations/createcontact.go +pkg/models/operations/getcontact.go +pkg/models/operations/listcontacts.go +pkg/models/operations/searchcontacts.go +pkg/models/operations/updatecontact.go +pkg/models/operations/createlead.go +pkg/models/operations/getlead.go +pkg/models/operations/listleads.go +pkg/models/operations/updatelead.go +pkg/models/operations/createopportunity.go +pkg/models/operations/getopportunity.go +pkg/models/operations/listopportunities.go +pkg/models/operations/searchopportunities.go +pkg/models/operations/updateopportunity.go +pkg/models/operations/sendpassthroughrequest.go +pkg/models/operations/getuser.go +pkg/models/operations/listusers.go +pkg/models/shared/warnings.go +pkg/models/shared/account.go +pkg/models/shared/phonenumbers.go +pkg/models/shared/user.go +pkg/models/shared/addresses.go +pkg/models/shared/logs.go +pkg/models/shared/errors.go +pkg/models/shared/createupdateaccount.go +pkg/models/shared/filter.go +pkg/models/shared/contact.go +pkg/models/shared/emailaddresses.go +pkg/models/shared/createupdatecontact.go +pkg/models/shared/lead.go +pkg/models/shared/createupdatelead.go +pkg/models/shared/opportunity.go +pkg/models/shared/createupdateopportunity.go +pkg/models/shared/security.go +USAGE.md \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index 6d85f4a..498c329 100644 --- a/gen.yaml +++ b/gen.yaml @@ -1,9 +1,14 @@ configVersion: 1.0.0 +management: + docChecksum: 580581d05c2e0bfeebe49cfcefe93d08 + docVersion: 0.6.0 + speakeasyVersion: 1.18.9 + generationVersion: 2.16.4 generation: telemetryEnabled: false sdkClassName: SDK sdkFlattening: false singleTagPerOp: false go: - version: "" + version: 1.0.0 packageName: supaglue diff --git a/go.mod b/go.mod new file mode 100755 index 0000000..db8423d --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module supaglue + +go 1.14 + +require ( + github.com/cenkalti/backoff/v4 v4.2.0 +) diff --git a/go.sum b/go.sum new file mode 100755 index 0000000..2307997 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= +github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= diff --git a/leads.go b/leads.go new file mode 100755 index 0000000..3a5c35c --- /dev/null +++ b/leads.go @@ -0,0 +1,247 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" +) + +// leads - The `Lead` Common Model is used to represent a "potential customer" in CRMs. +type leads struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newLeads(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *leads { + return &leads{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Create - Create lead +func (s *leads) Create(ctx context.Context, request operations.CreateLeadRequest) (*operations.CreateLeadResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/leads" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.CreateLeadResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 201: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.CreateLead201ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.CreateLead201ApplicationJSONObject = out + } + } + + return res, nil +} + +// Get - Get lead +func (s *leads) Get(ctx context.Context, request operations.GetLeadRequest) (*operations.GetLeadResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/leads/{lead_id}", request.PathParams, nil) + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.GetLeadResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *shared.Lead + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.Lead = out + } + } + + return res, nil +} + +// List - List leads +// Get a list of leads +func (s *leads) List(ctx context.Context, request operations.ListLeadsRequest) (*operations.ListLeadsResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/leads" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.ListLeadsResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.ListLeads200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.ListLeads200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Update - Update lead +func (s *leads) Update(ctx context.Context, request operations.UpdateLeadRequest) (*operations.UpdateLeadResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/leads/{lead_id}", request.PathParams, nil) + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "PATCH", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.UpdateLeadResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.UpdateLead200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.UpdateLead200ApplicationJSONObject = out + } + } + + return res, nil +} diff --git a/opportunities.go b/opportunities.go new file mode 100755 index 0000000..21f069d --- /dev/null +++ b/opportunities.go @@ -0,0 +1,307 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" +) + +// opportunities - The `Opportunity` Common Model is used to represent a "deal opportunity" in CRMs. +type opportunities struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newOpportunities(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *opportunities { + return &opportunities{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Create - Create opportunity +func (s *opportunities) Create(ctx context.Context, request operations.CreateOpportunityRequest) (*operations.CreateOpportunityResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/opportunities" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.CreateOpportunityResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 201: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.CreateOpportunity201ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.CreateOpportunity201ApplicationJSONObject = out + } + } + + return res, nil +} + +// Get - Get opportunity +func (s *opportunities) Get(ctx context.Context, request operations.GetOpportunityRequest) (*operations.GetOpportunityResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/opportunities/{opportunity_id}", request.PathParams, nil) + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.GetOpportunityResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *shared.Opportunity + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.Opportunity = out + } + } + + return res, nil +} + +// List - List opportunities +// Get a list of opportunities +func (s *opportunities) List(ctx context.Context, request operations.ListOpportunitiesRequest) (*operations.ListOpportunitiesResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/opportunities" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.ListOpportunitiesResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.ListOpportunities200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.ListOpportunities200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Search - Search Opportunities +func (s *opportunities) Search(ctx context.Context, request operations.SearchOpportunitiesRequest) (*operations.SearchOpportunitiesResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/opportunities/_search" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.SearchOpportunitiesResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.SearchOpportunities200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.SearchOpportunities200ApplicationJSONObject = out + } + } + + return res, nil +} + +// Update - Update opportunity +func (s *opportunities) Update(ctx context.Context, request operations.UpdateOpportunityRequest) (*operations.UpdateOpportunityResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/opportunities/{opportunity_id}", request.PathParams, nil) + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "PATCH", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.UpdateOpportunityResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.UpdateOpportunity200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.UpdateOpportunity200ApplicationJSONObject = out + } + } + + return res, nil +} diff --git a/passthrough.go b/passthrough.go new file mode 100755 index 0000000..c66a59f --- /dev/null +++ b/passthrough.go @@ -0,0 +1,90 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/utils" +) + +// passthrough - Passthrough operations to underlying providers. +type passthrough struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newPassthrough(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *passthrough { + return &passthrough{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Send - Send passthrough request +// Send request directly to a provider +func (s *passthrough) Send(ctx context.Context, request operations.SendPassthroughRequestRequest) (*operations.SendPassthroughRequestResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/passthrough" + + bodyReader, reqContentType, err := utils.SerializeRequestBody(ctx, request, "Request", "json") + if err != nil { + return nil, fmt.Errorf("error serializing request body: %w", err) + } + if bodyReader == nil { + return nil, fmt.Errorf("request body is required") + } + + req, err := http.NewRequestWithContext(ctx, "POST", url, bodyReader) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + req.Header.Set("Content-Type", reqContentType) + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.SendPassthroughRequestResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.SendPassthroughRequest200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.SendPassthroughRequest200ApplicationJSONObject = out + } + } + + return res, nil +} diff --git a/pkg/models/operations/createaccount.go b/pkg/models/operations/createaccount.go new file mode 100755 index 0000000..c57bd10 --- /dev/null +++ b/pkg/models/operations/createaccount.go @@ -0,0 +1,40 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type CreateAccountHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type CreateAccountRequestBody struct { + Model shared.CreateUpdateAccount `json:"model"` +} + +type CreateAccountRequest struct { + Headers CreateAccountHeaders + Request CreateAccountRequestBody `request:"mediaType=application/json"` +} + +// CreateAccount201ApplicationJSON - Account created +type CreateAccount201ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Account `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type CreateAccountResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Account created + CreateAccount201ApplicationJSONObject *CreateAccount201ApplicationJSON +} diff --git a/pkg/models/operations/createcontact.go b/pkg/models/operations/createcontact.go new file mode 100755 index 0000000..f140d0c --- /dev/null +++ b/pkg/models/operations/createcontact.go @@ -0,0 +1,40 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type CreateContactHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type CreateContactRequestBody struct { + Model shared.CreateUpdateContact `json:"model"` +} + +type CreateContactRequest struct { + Headers CreateContactHeaders + Request CreateContactRequestBody `request:"mediaType=application/json"` +} + +// CreateContact201ApplicationJSON - Contact created +type CreateContact201ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Contact `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type CreateContactResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Contact created + CreateContact201ApplicationJSONObject *CreateContact201ApplicationJSON +} diff --git a/pkg/models/operations/createlead.go b/pkg/models/operations/createlead.go new file mode 100755 index 0000000..68a03b3 --- /dev/null +++ b/pkg/models/operations/createlead.go @@ -0,0 +1,40 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type CreateLeadHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type CreateLeadRequestBody struct { + Model shared.CreateUpdateLead `json:"model"` +} + +type CreateLeadRequest struct { + Headers CreateLeadHeaders + Request CreateLeadRequestBody `request:"mediaType=application/json"` +} + +// CreateLead201ApplicationJSON - Lead created +type CreateLead201ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Lead `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type CreateLeadResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Lead created + CreateLead201ApplicationJSONObject *CreateLead201ApplicationJSON +} diff --git a/pkg/models/operations/createopportunity.go b/pkg/models/operations/createopportunity.go new file mode 100755 index 0000000..19f140f --- /dev/null +++ b/pkg/models/operations/createopportunity.go @@ -0,0 +1,40 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type CreateOpportunityHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type CreateOpportunityRequestBody struct { + Model shared.CreateUpdateOpportunity `json:"model"` +} + +type CreateOpportunityRequest struct { + Headers CreateOpportunityHeaders + Request CreateOpportunityRequestBody `request:"mediaType=application/json"` +} + +// CreateOpportunity201ApplicationJSON - Opportunity created +type CreateOpportunity201ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Opportunity `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type CreateOpportunityResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Opportunity created + CreateOpportunity201ApplicationJSONObject *CreateOpportunity201ApplicationJSON +} diff --git a/pkg/models/operations/getaccount.go b/pkg/models/operations/getaccount.go new file mode 100755 index 0000000..f7b0b9a --- /dev/null +++ b/pkg/models/operations/getaccount.go @@ -0,0 +1,38 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type GetAccountPathParams struct { + AccountID string `pathParam:"style=simple,explode=false,name=account_id"` +} + +type GetAccountQueryParams struct { + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` +} + +type GetAccountHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type GetAccountRequest struct { + PathParams GetAccountPathParams + QueryParams GetAccountQueryParams + Headers GetAccountHeaders +} + +type GetAccountResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Account + Account *shared.Account +} diff --git a/pkg/models/operations/getcontact.go b/pkg/models/operations/getcontact.go new file mode 100755 index 0000000..a6096d2 --- /dev/null +++ b/pkg/models/operations/getcontact.go @@ -0,0 +1,38 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type GetContactPathParams struct { + ContactID string `pathParam:"style=simple,explode=false,name=contact_id"` +} + +type GetContactQueryParams struct { + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` +} + +type GetContactHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type GetContactRequest struct { + PathParams GetContactPathParams + QueryParams GetContactQueryParams + Headers GetContactHeaders +} + +type GetContactResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Contact + Contact *shared.Contact +} diff --git a/pkg/models/operations/getlead.go b/pkg/models/operations/getlead.go new file mode 100755 index 0000000..10115a3 --- /dev/null +++ b/pkg/models/operations/getlead.go @@ -0,0 +1,38 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type GetLeadPathParams struct { + LeadID string `pathParam:"style=simple,explode=false,name=lead_id"` +} + +type GetLeadQueryParams struct { + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` +} + +type GetLeadHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type GetLeadRequest struct { + PathParams GetLeadPathParams + QueryParams GetLeadQueryParams + Headers GetLeadHeaders +} + +type GetLeadResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Lead + Lead *shared.Lead +} diff --git a/pkg/models/operations/getopportunity.go b/pkg/models/operations/getopportunity.go new file mode 100755 index 0000000..a6787a7 --- /dev/null +++ b/pkg/models/operations/getopportunity.go @@ -0,0 +1,38 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type GetOpportunityPathParams struct { + OpportunityID string `pathParam:"style=simple,explode=false,name=opportunity_id"` +} + +type GetOpportunityQueryParams struct { + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` +} + +type GetOpportunityHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type GetOpportunityRequest struct { + PathParams GetOpportunityPathParams + QueryParams GetOpportunityQueryParams + Headers GetOpportunityHeaders +} + +type GetOpportunityResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Opportunity + Opportunity *shared.Opportunity +} diff --git a/pkg/models/operations/getuser.go b/pkg/models/operations/getuser.go new file mode 100755 index 0000000..1686b64 --- /dev/null +++ b/pkg/models/operations/getuser.go @@ -0,0 +1,32 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type GetUserPathParams struct { + UserID string `pathParam:"style=simple,explode=false,name=user_id"` +} + +type GetUserHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type GetUserRequest struct { + PathParams GetUserPathParams + Headers GetUserHeaders +} + +type GetUserResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // User + User *shared.User +} diff --git a/pkg/models/operations/listaccounts.go b/pkg/models/operations/listaccounts.go new file mode 100755 index 0000000..b7fec6e --- /dev/null +++ b/pkg/models/operations/listaccounts.go @@ -0,0 +1,53 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" + "time" +) + +type ListAccountsQueryParams struct { + // If provided, will only return objects created after this datetime + CreatedAfter *time.Time `queryParam:"style=form,explode=true,name=created_after"` + // If provided, will only return objects created before this datetime + CreatedBefore *time.Time `queryParam:"style=form,explode=true,name=created_before"` + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` + // If provided, will only return objects modified after this datetime + UpdatedAfter *time.Time `queryParam:"style=form,explode=true,name=updated_after"` + // If provided, will only return objects modified before this datetime + UpdatedBefore *time.Time `queryParam:"style=form,explode=true,name=updated_before"` +} + +type ListAccountsHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type ListAccountsRequest struct { + QueryParams ListAccountsQueryParams + Headers ListAccountsHeaders +} + +// ListAccounts200ApplicationJSON - Accounts +type ListAccounts200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Account `json:"results,omitempty"` +} + +type ListAccountsResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Accounts + ListAccounts200ApplicationJSONObject *ListAccounts200ApplicationJSON +} diff --git a/pkg/models/operations/listcontacts.go b/pkg/models/operations/listcontacts.go new file mode 100755 index 0000000..5fe73a4 --- /dev/null +++ b/pkg/models/operations/listcontacts.go @@ -0,0 +1,53 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" + "time" +) + +type ListContactsQueryParams struct { + // If provided, will only return objects created after this datetime + CreatedAfter *time.Time `queryParam:"style=form,explode=true,name=created_after"` + // If provided, will only return objects created before this datetime + CreatedBefore *time.Time `queryParam:"style=form,explode=true,name=created_before"` + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` + // If provided, will only return objects modified after this datetime + UpdatedAfter *time.Time `queryParam:"style=form,explode=true,name=updated_after"` + // If provided, will only return objects modified before this datetime + UpdatedBefore *time.Time `queryParam:"style=form,explode=true,name=updated_before"` +} + +type ListContactsHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type ListContactsRequest struct { + QueryParams ListContactsQueryParams + Headers ListContactsHeaders +} + +// ListContacts200ApplicationJSON - Contacts +type ListContacts200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Contact `json:"results,omitempty"` +} + +type ListContactsResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Contacts + ListContacts200ApplicationJSONObject *ListContacts200ApplicationJSON +} diff --git a/pkg/models/operations/listleads.go b/pkg/models/operations/listleads.go new file mode 100755 index 0000000..c8b7e0f --- /dev/null +++ b/pkg/models/operations/listleads.go @@ -0,0 +1,53 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" + "time" +) + +type ListLeadsQueryParams struct { + // If provided, will only return objects created after this datetime + CreatedAfter *time.Time `queryParam:"style=form,explode=true,name=created_after"` + // If provided, will only return objects created before this datetime + CreatedBefore *time.Time `queryParam:"style=form,explode=true,name=created_before"` + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` + // If provided, will only return objects modified after this datetime + UpdatedAfter *time.Time `queryParam:"style=form,explode=true,name=updated_after"` + // If provided, will only return objects modified before this datetime + UpdatedBefore *time.Time `queryParam:"style=form,explode=true,name=updated_before"` +} + +type ListLeadsHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type ListLeadsRequest struct { + QueryParams ListLeadsQueryParams + Headers ListLeadsHeaders +} + +// ListLeads200ApplicationJSON - Leads +type ListLeads200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Lead `json:"results,omitempty"` +} + +type ListLeadsResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Leads + ListLeads200ApplicationJSONObject *ListLeads200ApplicationJSON +} diff --git a/pkg/models/operations/listopportunities.go b/pkg/models/operations/listopportunities.go new file mode 100755 index 0000000..a935e7b --- /dev/null +++ b/pkg/models/operations/listopportunities.go @@ -0,0 +1,53 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" + "time" +) + +type ListOpportunitiesQueryParams struct { + // If provided, will only return objects created after this datetime + CreatedAfter *time.Time `queryParam:"style=form,explode=true,name=created_after"` + // If provided, will only return objects created before this datetime + CreatedBefore *time.Time `queryParam:"style=form,explode=true,name=created_before"` + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` + // If provided, will only return objects modified after this datetime + UpdatedAfter *time.Time `queryParam:"style=form,explode=true,name=updated_after"` + // If provided, will only return objects modified before this datetime + UpdatedBefore *time.Time `queryParam:"style=form,explode=true,name=updated_before"` +} + +type ListOpportunitiesHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type ListOpportunitiesRequest struct { + QueryParams ListOpportunitiesQueryParams + Headers ListOpportunitiesHeaders +} + +// ListOpportunities200ApplicationJSON - Opportunities +type ListOpportunities200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Opportunity `json:"results,omitempty"` +} + +type ListOpportunitiesResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Opportunities + ListOpportunities200ApplicationJSONObject *ListOpportunities200ApplicationJSON +} diff --git a/pkg/models/operations/listusers.go b/pkg/models/operations/listusers.go new file mode 100755 index 0000000..3f87192 --- /dev/null +++ b/pkg/models/operations/listusers.go @@ -0,0 +1,53 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" + "time" +) + +type ListUsersQueryParams struct { + // If provided, will only return objects created after this datetime + CreatedAfter *time.Time `queryParam:"style=form,explode=true,name=created_after"` + // If provided, will only return objects created before this datetime + CreatedBefore *time.Time `queryParam:"style=form,explode=true,name=created_before"` + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces + Expand *string `queryParam:"style=form,explode=true,name=expand"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` + // If provided, will only return objects modified after this datetime + UpdatedAfter *time.Time `queryParam:"style=form,explode=true,name=updated_after"` + // If provided, will only return objects modified before this datetime + UpdatedBefore *time.Time `queryParam:"style=form,explode=true,name=updated_before"` +} + +type ListUsersHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type ListUsersRequest struct { + QueryParams ListUsersQueryParams + Headers ListUsersHeaders +} + +// ListUsers200ApplicationJSON - Users +type ListUsers200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.User `json:"results,omitempty"` +} + +type ListUsersResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Users + ListUsers200ApplicationJSONObject *ListUsers200ApplicationJSON +} diff --git a/pkg/models/operations/searchaccounts.go b/pkg/models/operations/searchaccounts.go new file mode 100755 index 0000000..a476abf --- /dev/null +++ b/pkg/models/operations/searchaccounts.go @@ -0,0 +1,51 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type SearchAccountsQueryParams struct { + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` +} + +type SearchAccountsHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type SearchAccountsRequestBodyFilters struct { + Website *shared.Filter `json:"website,omitempty"` +} + +type SearchAccountsRequestBody struct { + Filters SearchAccountsRequestBodyFilters `json:"filters"` +} + +type SearchAccountsRequest struct { + QueryParams SearchAccountsQueryParams + Headers SearchAccountsHeaders + Request SearchAccountsRequestBody `request:"mediaType=application/json"` +} + +// SearchAccounts200ApplicationJSON - Accounts +type SearchAccounts200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Account `json:"results,omitempty"` +} + +type SearchAccountsResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Accounts + SearchAccounts200ApplicationJSONObject *SearchAccounts200ApplicationJSON +} diff --git a/pkg/models/operations/searchcontacts.go b/pkg/models/operations/searchcontacts.go new file mode 100755 index 0000000..f18639b --- /dev/null +++ b/pkg/models/operations/searchcontacts.go @@ -0,0 +1,51 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type SearchContactsQueryParams struct { + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` +} + +type SearchContactsHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type SearchContactsRequestBodyFilters struct { + EmailAddress *shared.Filter `json:"email_address,omitempty"` +} + +type SearchContactsRequestBody struct { + Filters SearchContactsRequestBodyFilters `json:"filters"` +} + +type SearchContactsRequest struct { + QueryParams SearchContactsQueryParams + Headers SearchContactsHeaders + Request SearchContactsRequestBody `request:"mediaType=application/json"` +} + +// SearchContacts200ApplicationJSON - Contacts +type SearchContacts200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Contact `json:"results,omitempty"` +} + +type SearchContactsResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Contacts + SearchContacts200ApplicationJSONObject *SearchContacts200ApplicationJSON +} diff --git a/pkg/models/operations/searchopportunities.go b/pkg/models/operations/searchopportunities.go new file mode 100755 index 0000000..6192f47 --- /dev/null +++ b/pkg/models/operations/searchopportunities.go @@ -0,0 +1,51 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type SearchOpportunitiesQueryParams struct { + // The pagination cursor value + Cursor *string `queryParam:"style=form,explode=true,name=cursor"` + // Number of results to return per page + PageSize *string `queryParam:"style=form,explode=true,name=page_size"` +} + +type SearchOpportunitiesHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type SearchOpportunitiesRequestBodyFilters struct { + AccountID *shared.Filter `json:"account_id,omitempty"` +} + +type SearchOpportunitiesRequestBody struct { + Filters SearchOpportunitiesRequestBodyFilters `json:"filters"` +} + +type SearchOpportunitiesRequest struct { + QueryParams SearchOpportunitiesQueryParams + Headers SearchOpportunitiesHeaders + Request SearchOpportunitiesRequestBody `request:"mediaType=application/json"` +} + +// SearchOpportunities200ApplicationJSON - Opportunities +type SearchOpportunities200ApplicationJSON struct { + Next *string `json:"next,omitempty"` + Previous *string `json:"previous,omitempty"` + Results []shared.Opportunity `json:"results,omitempty"` +} + +type SearchOpportunitiesResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Opportunities + SearchOpportunities200ApplicationJSONObject *SearchOpportunities200ApplicationJSON +} diff --git a/pkg/models/operations/sendpassthroughrequest.go b/pkg/models/operations/sendpassthroughrequest.go new file mode 100755 index 0000000..7643903 --- /dev/null +++ b/pkg/models/operations/sendpassthroughrequest.go @@ -0,0 +1,85 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "encoding/json" + "fmt" + "net/http" +) + +type SendPassthroughRequestHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type SendPassthroughRequestRequestBodyMethodEnum string + +const ( + SendPassthroughRequestRequestBodyMethodEnumGet SendPassthroughRequestRequestBodyMethodEnum = "GET" + SendPassthroughRequestRequestBodyMethodEnumPost SendPassthroughRequestRequestBodyMethodEnum = "POST" + SendPassthroughRequestRequestBodyMethodEnumPut SendPassthroughRequestRequestBodyMethodEnum = "PUT" + SendPassthroughRequestRequestBodyMethodEnumPatch SendPassthroughRequestRequestBodyMethodEnum = "PATCH" + SendPassthroughRequestRequestBodyMethodEnumDelete SendPassthroughRequestRequestBodyMethodEnum = "DELETE" +) + +func (e *SendPassthroughRequestRequestBodyMethodEnum) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch s { + case "GET": + fallthrough + case "POST": + fallthrough + case "PUT": + fallthrough + case "PATCH": + fallthrough + case "DELETE": + *e = SendPassthroughRequestRequestBodyMethodEnum(s) + return nil + default: + return fmt.Errorf("invalid value for SendPassthroughRequestRequestBodyMethodEnum: %s", s) + } +} + +type SendPassthroughRequestRequestBody struct { + // Body to pass to downstream + Body *string `json:"body,omitempty"` + // Headers to pass to downstream + Headers map[string]string `json:"headers,omitempty"` + Method SendPassthroughRequestRequestBodyMethodEnum `json:"method"` + // The path to send the request to (do not pass the domain) + Path string `json:"path"` + // Query parameters to pass to downstream + Query map[string]string `json:"query,omitempty"` +} + +type SendPassthroughRequestRequest struct { + Headers SendPassthroughRequestHeaders + Request SendPassthroughRequestRequestBody `request:"mediaType=application/json"` +} + +// SendPassthroughRequest200ApplicationJSON - Passthrough response +type SendPassthroughRequest200ApplicationJSON struct { + // The body from the downstream + Body interface{} `json:"body,omitempty"` + // The response headers from the downstream + Headers map[string]string `json:"headers"` + // Status code from the downstream + Status float64 `json:"status"` + // The full URL the request was went to + URL string `json:"url"` +} + +type SendPassthroughRequestResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Passthrough response + SendPassthroughRequest200ApplicationJSONObject *SendPassthroughRequest200ApplicationJSON +} diff --git a/pkg/models/operations/updateaccount.go b/pkg/models/operations/updateaccount.go new file mode 100755 index 0000000..cfcecc0 --- /dev/null +++ b/pkg/models/operations/updateaccount.go @@ -0,0 +1,45 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type UpdateAccountPathParams struct { + AccountID string `pathParam:"style=simple,explode=false,name=account_id"` +} + +type UpdateAccountHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type UpdateAccountRequestBody struct { + Model shared.CreateUpdateAccount `json:"model"` +} + +type UpdateAccountRequest struct { + PathParams UpdateAccountPathParams + Headers UpdateAccountHeaders + Request UpdateAccountRequestBody `request:"mediaType=application/json"` +} + +// UpdateAccount200ApplicationJSON - Account updated +type UpdateAccount200ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Account `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type UpdateAccountResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Account updated + UpdateAccount200ApplicationJSONObject *UpdateAccount200ApplicationJSON +} diff --git a/pkg/models/operations/updatecontact.go b/pkg/models/operations/updatecontact.go new file mode 100755 index 0000000..6e3fe9b --- /dev/null +++ b/pkg/models/operations/updatecontact.go @@ -0,0 +1,45 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type UpdateContactPathParams struct { + ContactID string `pathParam:"style=simple,explode=false,name=contact_id"` +} + +type UpdateContactHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type UpdateContactRequestBody struct { + Model shared.CreateUpdateContact `json:"model"` +} + +type UpdateContactRequest struct { + PathParams UpdateContactPathParams + Headers UpdateContactHeaders + Request UpdateContactRequestBody `request:"mediaType=application/json"` +} + +// UpdateContact200ApplicationJSON - Contact updated +type UpdateContact200ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Contact `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type UpdateContactResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Contact updated + UpdateContact200ApplicationJSONObject *UpdateContact200ApplicationJSON +} diff --git a/pkg/models/operations/updatelead.go b/pkg/models/operations/updatelead.go new file mode 100755 index 0000000..6c1f29d --- /dev/null +++ b/pkg/models/operations/updatelead.go @@ -0,0 +1,45 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type UpdateLeadPathParams struct { + LeadID string `pathParam:"style=simple,explode=false,name=lead_id"` +} + +type UpdateLeadHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type UpdateLeadRequestBody struct { + Model shared.CreateUpdateLead `json:"model"` +} + +type UpdateLeadRequest struct { + PathParams UpdateLeadPathParams + Headers UpdateLeadHeaders + Request UpdateLeadRequestBody `request:"mediaType=application/json"` +} + +// UpdateLead200ApplicationJSON - Lead updated +type UpdateLead200ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Lead `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type UpdateLeadResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Lead updated + UpdateLead200ApplicationJSONObject *UpdateLead200ApplicationJSON +} diff --git a/pkg/models/operations/updateopportunity.go b/pkg/models/operations/updateopportunity.go new file mode 100755 index 0000000..e4aa3f2 --- /dev/null +++ b/pkg/models/operations/updateopportunity.go @@ -0,0 +1,45 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package operations + +import ( + "net/http" + "supaglue/pkg/models/shared" +) + +type UpdateOpportunityPathParams struct { + OpportunityID string `pathParam:"style=simple,explode=false,name=opportunity_id"` +} + +type UpdateOpportunityHeaders struct { + // The customer ID that uniquely identifies the customer in your application + XCustomerID string `header:"style=simple,explode=false,name=x-customer-id"` + // The provider name + XProviderName string `header:"style=simple,explode=false,name=x-provider-name"` +} + +type UpdateOpportunityRequestBody struct { + Model shared.CreateUpdateOpportunity `json:"model"` +} + +type UpdateOpportunityRequest struct { + PathParams UpdateOpportunityPathParams + Headers UpdateOpportunityHeaders + Request UpdateOpportunityRequestBody `request:"mediaType=application/json"` +} + +// UpdateOpportunity200ApplicationJSON - Opportunity updated +type UpdateOpportunity200ApplicationJSON struct { + Errors []shared.Errors `json:"errors,omitempty"` + Logs []shared.Logs `json:"logs,omitempty"` + Model *shared.Opportunity `json:"model,omitempty"` + Warnings []shared.Warnings `json:"warnings,omitempty"` +} + +type UpdateOpportunityResponse struct { + ContentType string + StatusCode int + RawResponse *http.Response + // Opportunity updated + UpdateOpportunity200ApplicationJSONObject *UpdateOpportunity200ApplicationJSON +} diff --git a/pkg/models/shared/account.go b/pkg/models/shared/account.go new file mode 100755 index 0000000..726e1eb --- /dev/null +++ b/pkg/models/shared/account.go @@ -0,0 +1,25 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "time" +) + +// Account - Account +type Account struct { + Addresses []Addresses `json:"addresses"` + CreatedAt time.Time `json:"created_at"` + Description string `json:"description"` + ID string `json:"id"` + Industry string `json:"industry"` + LastActivityAt time.Time `json:"last_activity_at"` + Name string `json:"name"` + NumberOfEmployees int64 `json:"number_of_employees"` + Owner *User `json:"owner,omitempty"` + OwnerID string `json:"owner_id"` + PhoneNumbers []PhoneNumbers `json:"phone_numbers"` + RemoteID string `json:"remote_id"` + UpdatedAt time.Time `json:"updated_at"` + Website string `json:"website"` +} diff --git a/pkg/models/shared/addresses.go b/pkg/models/shared/addresses.go new file mode 100755 index 0000000..297709d --- /dev/null +++ b/pkg/models/shared/addresses.go @@ -0,0 +1,50 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type AddressesAddressTypeEnum string + +const ( + AddressesAddressTypeEnumPrimary AddressesAddressTypeEnum = "primary" + AddressesAddressTypeEnumMailing AddressesAddressTypeEnum = "mailing" + AddressesAddressTypeEnumOther AddressesAddressTypeEnum = "other" + AddressesAddressTypeEnumBilling AddressesAddressTypeEnum = "billing" + AddressesAddressTypeEnumShipping AddressesAddressTypeEnum = "shipping" +) + +func (e *AddressesAddressTypeEnum) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch s { + case "primary": + fallthrough + case "mailing": + fallthrough + case "other": + fallthrough + case "billing": + fallthrough + case "shipping": + *e = AddressesAddressTypeEnum(s) + return nil + default: + return fmt.Errorf("invalid value for AddressesAddressTypeEnum: %s", s) + } +} + +type Addresses struct { + AddressType AddressesAddressTypeEnum `json:"address_type"` + City string `json:"city"` + Country string `json:"country"` + PostalCode string `json:"postal_code"` + State string `json:"state"` + Street1 string `json:"street1"` + Street2 string `json:"street2"` +} diff --git a/pkg/models/shared/contact.go b/pkg/models/shared/contact.go new file mode 100755 index 0000000..d6fd482 --- /dev/null +++ b/pkg/models/shared/contact.go @@ -0,0 +1,25 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "time" +) + +// Contact - Contact +type Contact struct { + Account *Account `json:"account,omitempty"` + AccountID string `json:"account_id"` + Addresses []Addresses `json:"addresses"` + CreatedAt time.Time `json:"created_at"` + EmailAddresses []EmailAddresses `json:"email_addresses"` + FirstName string `json:"first_name"` + ID string `json:"id"` + LastActivityAt time.Time `json:"last_activity_at"` + LastName string `json:"last_name"` + Owner *User `json:"owner,omitempty"` + OwnerID string `json:"owner_id"` + PhoneNumbers []PhoneNumbers `json:"phone_numbers"` + RemoteID string `json:"remote_id"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/pkg/models/shared/createupdateaccount.go b/pkg/models/shared/createupdateaccount.go new file mode 100755 index 0000000..e15ed91 --- /dev/null +++ b/pkg/models/shared/createupdateaccount.go @@ -0,0 +1,16 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type CreateUpdateAccount struct { + Addresses []Addresses `json:"addresses,omitempty"` + // Custom properties to be inserted that are not covered by the common model. Object keys must match exactly to the corresponding provider API. + CustomFields map[string]interface{} `json:"custom_fields,omitempty"` + Description *string `json:"description,omitempty"` + Industry *string `json:"industry,omitempty"` + Name *string `json:"name,omitempty"` + NumberOfEmployees *int64 `json:"number_of_employees,omitempty"` + OwnerID *string `json:"owner_id,omitempty"` + PhoneNumbers []PhoneNumbers `json:"phone_numbers,omitempty"` + Website *string `json:"website,omitempty"` +} diff --git a/pkg/models/shared/createupdatecontact.go b/pkg/models/shared/createupdatecontact.go new file mode 100755 index 0000000..a89a69c --- /dev/null +++ b/pkg/models/shared/createupdatecontact.go @@ -0,0 +1,15 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type CreateUpdateContact struct { + AccountID *string `json:"account_id,omitempty"` + Addresses []Addresses `json:"addresses,omitempty"` + // Custom properties to be inserted that are not covered by the common model. Object keys must match exactly to the corresponding provider API. + CustomFields map[string]interface{} `json:"custom_fields,omitempty"` + EmailAddresses []EmailAddresses `json:"email_addresses,omitempty"` + FirstName *string `json:"first_name,omitempty"` + LastName *string `json:"last_name,omitempty"` + OwnerID *string `json:"owner_id,omitempty"` + PhoneNumbers []PhoneNumbers `json:"phone_numbers,omitempty"` +} diff --git a/pkg/models/shared/createupdatelead.go b/pkg/models/shared/createupdatelead.go new file mode 100755 index 0000000..b593847 --- /dev/null +++ b/pkg/models/shared/createupdatelead.go @@ -0,0 +1,16 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type CreateUpdateLead struct { + Addresses []Addresses `json:"addresses,omitempty"` + Company *string `json:"company,omitempty"` + // Custom properties to be inserted that are not covered by the common model. Object keys must match exactly to the corresponding provider API. + CustomFields map[string]interface{} `json:"custom_fields,omitempty"` + EmailAddresses []EmailAddresses `json:"email_addresses,omitempty"` + FirstName *string `json:"first_name,omitempty"` + LastName *string `json:"last_name,omitempty"` + LeadSource *string `json:"lead_source,omitempty"` + OwnerID *string `json:"owner_id,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/pkg/models/shared/createupdateopportunity.go b/pkg/models/shared/createupdateopportunity.go new file mode 100755 index 0000000..d6ead0b --- /dev/null +++ b/pkg/models/shared/createupdateopportunity.go @@ -0,0 +1,15 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type CreateUpdateOpportunity struct { + AccountID *string `json:"account_id,omitempty"` + Amount *int64 `json:"amount,omitempty"` + CloseDate *string `json:"close_date,omitempty"` + // Custom properties to be inserted that are not covered by the common model. Object keys must match exactly to the corresponding provider API. + CustomFields map[string]interface{} `json:"custom_fields,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + OwnerID *string `json:"owner_id,omitempty"` + Stage *string `json:"stage,omitempty"` +} diff --git a/pkg/models/shared/emailaddresses.go b/pkg/models/shared/emailaddresses.go new file mode 100755 index 0000000..b737c11 --- /dev/null +++ b/pkg/models/shared/emailaddresses.go @@ -0,0 +1,36 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type EmailAddressesEmailAddressTypeEnum string + +const ( + EmailAddressesEmailAddressTypeEnumPrimary EmailAddressesEmailAddressTypeEnum = "primary" + EmailAddressesEmailAddressTypeEnumWork EmailAddressesEmailAddressTypeEnum = "work" +) + +func (e *EmailAddressesEmailAddressTypeEnum) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch s { + case "primary": + fallthrough + case "work": + *e = EmailAddressesEmailAddressTypeEnum(s) + return nil + default: + return fmt.Errorf("invalid value for EmailAddressesEmailAddressTypeEnum: %s", s) + } +} + +type EmailAddresses struct { + EmailAddress string `json:"email_address"` + EmailAddressType EmailAddressesEmailAddressTypeEnum `json:"email_address_type"` +} diff --git a/pkg/models/shared/errors.go b/pkg/models/shared/errors.go new file mode 100755 index 0000000..a86e4bd --- /dev/null +++ b/pkg/models/shared/errors.go @@ -0,0 +1,14 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type ErrorsSource struct { + Pointer *string `json:"pointer,omitempty"` +} + +type Errors struct { + Detail *string `json:"detail,omitempty"` + ProblemType *string `json:"problem_type,omitempty"` + Source *ErrorsSource `json:"source,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/pkg/models/shared/filter.go b/pkg/models/shared/filter.go new file mode 100755 index 0000000..7401b78 --- /dev/null +++ b/pkg/models/shared/filter.go @@ -0,0 +1,79 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" +) + +type Filter1TypeEnum string + +const ( + Filter1TypeEnumEquals Filter1TypeEnum = "equals" +) + +func (e *Filter1TypeEnum) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch s { + case "equals": + *e = Filter1TypeEnum(s) + return nil + default: + return fmt.Errorf("invalid value for Filter1TypeEnum: %s", s) + } +} + +type Filter1 struct { + Type Filter1TypeEnum `json:"type"` + Value string `json:"value"` +} + +type FilterType string + +const ( + FilterTypeFilter1 FilterType = "filter_1" +) + +type Filter struct { + Filter1 *Filter1 + + Type FilterType +} + +func CreateFilterFilter1(filter1 Filter1) Filter { + typ := FilterTypeFilter1 + + return Filter{ + Filter1: &filter1, + Type: typ, + } +} + +func (u *Filter) UnmarshalJSON(data []byte) error { + var d *json.Decoder + + filter1 := new(Filter1) + d = json.NewDecoder(bytes.NewReader(data)) + d.DisallowUnknownFields() + if err := d.Decode(&filter1); err == nil { + u.Filter1 = filter1 + u.Type = FilterTypeFilter1 + return nil + } + + return errors.New("could not unmarshal into supported union types") +} + +func (u Filter) MarshalJSON() ([]byte, error) { + if u.Filter1 != nil { + return json.Marshal(u.Filter1) + } + + return nil, nil +} diff --git a/pkg/models/shared/lead.go b/pkg/models/shared/lead.go new file mode 100755 index 0000000..94a0ff5 --- /dev/null +++ b/pkg/models/shared/lead.go @@ -0,0 +1,30 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "time" +) + +// Lead - Lead +type Lead struct { + Addresses []Addresses `json:"addresses"` + Company string `json:"company"` + ConvertedAccount *Account `json:"converted_account,omitempty"` + ConvertedAccountID string `json:"converted_account_id"` + ConvertedContact *Contact `json:"converted_contact,omitempty"` + ConvertedContactID string `json:"converted_contact_id"` + ConvertedDate time.Time `json:"converted_date"` + CreatedAt time.Time `json:"created_at"` + EmailAddresses []EmailAddresses `json:"email_addresses,omitempty"` + FirstName *string `json:"first_name,omitempty"` + ID string `json:"id"` + LastName string `json:"last_name"` + LeadSource string `json:"lead_source"` + Owner *User `json:"owner,omitempty"` + OwnerID string `json:"owner_id"` + PhoneNumbers []PhoneNumbers `json:"phone_numbers"` + RemoteID string `json:"remote_id"` + Title string `json:"title"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/pkg/models/shared/logs.go b/pkg/models/shared/logs.go new file mode 100755 index 0000000..fc961ca --- /dev/null +++ b/pkg/models/shared/logs.go @@ -0,0 +1,15 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type LogsLogSummary struct { + Method *string `json:"method,omitempty"` + StatusCode *float64 `json:"status_code,omitempty"` + URL *string `json:"url,omitempty"` +} + +type Logs struct { + DashboardView *string `json:"dashboard_view,omitempty"` + LogID *string `json:"log_id,omitempty"` + LogSummary *LogsLogSummary `json:"log_summary,omitempty"` +} diff --git a/pkg/models/shared/opportunity.go b/pkg/models/shared/opportunity.go new file mode 100755 index 0000000..0d43a9d --- /dev/null +++ b/pkg/models/shared/opportunity.go @@ -0,0 +1,26 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "time" +) + +// Opportunity - Opportunity +type Opportunity struct { + Account *Account `json:"account,omitempty"` + AccountID string `json:"account_id"` + Amount int64 `json:"amount"` + CloseDate *time.Time `json:"close_date,omitempty"` + CreatedAt time.Time `json:"created_at"` + Description string `json:"description"` + ID string `json:"id"` + LastActivityAt time.Time `json:"last_activity_at"` + Name string `json:"name"` + Owner *User `json:"owner,omitempty"` + OwnerID string `json:"owner_id"` + RemoteID string `json:"remote_id"` + Stage string `json:"stage"` + Status string `json:"status"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/pkg/models/shared/phonenumbers.go b/pkg/models/shared/phonenumbers.go new file mode 100755 index 0000000..b1954c7 --- /dev/null +++ b/pkg/models/shared/phonenumbers.go @@ -0,0 +1,39 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "encoding/json" + "fmt" +) + +type PhoneNumbersPhoneNumberTypeEnum string + +const ( + PhoneNumbersPhoneNumberTypeEnumPrimary PhoneNumbersPhoneNumberTypeEnum = "primary" + PhoneNumbersPhoneNumberTypeEnumMobile PhoneNumbersPhoneNumberTypeEnum = "mobile" + PhoneNumbersPhoneNumberTypeEnumFax PhoneNumbersPhoneNumberTypeEnum = "fax" +) + +func (e *PhoneNumbersPhoneNumberTypeEnum) UnmarshalJSON(data []byte) error { + var s string + if err := json.Unmarshal(data, &s); err != nil { + return err + } + switch s { + case "primary": + fallthrough + case "mobile": + fallthrough + case "fax": + *e = PhoneNumbersPhoneNumberTypeEnum(s) + return nil + default: + return fmt.Errorf("invalid value for PhoneNumbersPhoneNumberTypeEnum: %s", s) + } +} + +type PhoneNumbers struct { + PhoneNumber string `json:"phone_number"` + PhoneNumberType PhoneNumbersPhoneNumberTypeEnum `json:"phone_number_type"` +} diff --git a/pkg/models/shared/security.go b/pkg/models/shared/security.go new file mode 100755 index 0000000..f91d1eb --- /dev/null +++ b/pkg/models/shared/security.go @@ -0,0 +1,11 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type SchemeAPIKeyAuth struct { + APIKey string `security:"name=x-api-key"` +} + +type Security struct { + APIKeyAuth SchemeAPIKeyAuth `security:"scheme,type=apiKey,subtype=header"` +} diff --git a/pkg/models/shared/user.go b/pkg/models/shared/user.go new file mode 100755 index 0000000..49b05a1 --- /dev/null +++ b/pkg/models/shared/user.go @@ -0,0 +1,18 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +import ( + "time" +) + +// User - User +type User struct { + CreatedAt time.Time `json:"created_at"` + Email string `json:"email"` + ID string `json:"id"` + IsActive bool `json:"is_active"` + Name string `json:"name"` + RemoteID string `json:"remote_id"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/pkg/models/shared/warnings.go b/pkg/models/shared/warnings.go new file mode 100755 index 0000000..cfdf849 --- /dev/null +++ b/pkg/models/shared/warnings.go @@ -0,0 +1,14 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package shared + +type WarningsSource struct { + Pointer *string `json:"pointer,omitempty"` +} + +type Warnings struct { + Detail *string `json:"detail,omitempty"` + ProblemType *string `json:"problem_type,omitempty"` + Source *WarningsSource `json:"source,omitempty"` + Title *string `json:"title,omitempty"` +} diff --git a/pkg/types/date.go b/pkg/types/date.go new file mode 100755 index 0000000..2b77ce5 --- /dev/null +++ b/pkg/types/date.go @@ -0,0 +1,38 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package types + +import ( + "encoding/json" + "fmt" + "strings" + "time" +) + +type Date struct { + time.Time +} + +var ( + _ json.Marshaler = &Date{} + _ json.Unmarshaler = &Date{} + _ fmt.Stringer = &Date{} +) + +func (d Date) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`"%s"`, d.Time.Format("2006-01-02"))), nil +} + +func (d *Date) UnmarshalJSON(data []byte) error { + var err error + + str := string(data) + str = strings.Trim(str, `"`) + + d.Time, err = time.Parse("2006-01-02", str) + return err +} + +func (d Date) String() string { + return d.Time.Format("2006-01-02") +} diff --git a/pkg/utils/contenttype.go b/pkg/utils/contenttype.go new file mode 100755 index 0000000..8ed13e2 --- /dev/null +++ b/pkg/utils/contenttype.go @@ -0,0 +1,33 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "fmt" + "mime" + "strings" +) + +func MatchContentType(contentType string, pattern string) bool { + if contentType == pattern || pattern == "*" || pattern == "*/*" { + return true + } + + mediaType, _, err := mime.ParseMediaType(contentType) + if err != nil { + return false + } + + if mediaType == pattern { + return true + } + + parts := strings.Split(mediaType, "/") + if len(parts) == 2 { + if fmt.Sprintf("%s/*", parts[0]) == pattern || fmt.Sprintf("*/%s", parts[1]) == pattern { + return true + } + } + + return false +} diff --git a/pkg/utils/form.go b/pkg/utils/form.go new file mode 100755 index 0000000..3ab1eb0 --- /dev/null +++ b/pkg/utils/form.go @@ -0,0 +1,108 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "fmt" + "net/url" + "reflect" + "strings" + "time" + + "supaglue/pkg/types" +) + +func populateForm(paramName string, explode bool, objType reflect.Type, objValue reflect.Value, getFieldName func(reflect.StructField) string) url.Values { + formValues := url.Values{} + + if objType.Kind() == reflect.Pointer { + if objValue.IsNil() { + return formValues + } + objType = objType.Elem() + objValue = objValue.Elem() + } + + switch objType.Kind() { + case reflect.Struct: + switch objValue.Interface().(type) { + case time.Time: + formValues.Add(paramName, valToString(objValue.Interface())) + case types.Date: + formValues.Add(paramName, valToString(objValue.Interface())) + default: + var items []string + + for i := 0; i < objType.NumField(); i++ { + fieldType := objType.Field(i) + valType := objValue.Field(i) + + if valType.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + + valType = valType.Elem() + } + + fieldName := getFieldName(fieldType) + if fieldName == "" { + continue + } + + if explode { + formValues.Add(fieldName, valToString(valType.Interface())) + } else { + items = append(items, fmt.Sprintf("%s,%s", fieldName, valToString(valType.Interface()))) + } + } + + if len(items) > 0 { + formValues.Add(paramName, strings.Join(items, ",")) + } + } + case reflect.Map: + items := []string{} + + iter := objValue.MapRange() + for iter.Next() { + if explode { + formValues.Add(iter.Key().String(), valToString(iter.Value().Interface())) + } else { + items = append(items, fmt.Sprintf("%s,%s", iter.Key().String(), valToString(iter.Value().Interface()))) + } + } + + if len(items) > 0 { + formValues.Add(paramName, strings.Join(items, ",")) + } + case reflect.Slice, reflect.Array: + values := parseFormStyleArray(explode, objValue) + for _, v := range values { + formValues.Add(paramName, v) + } + default: + formValues.Add(paramName, valToString(objValue.Interface())) + } + + return formValues +} + +func parseFormStyleArray(explode bool, objValue reflect.Value) []string { + values := []string{} + items := []string{} + + for i := 0; i < objValue.Len(); i++ { + if explode { + values = append(values, valToString(objValue.Index(i).Interface())) + } else { + items = append(items, valToString(objValue.Index(i).Interface())) + } + } + + if len(items) > 0 { + values = append(values, strings.Join(items, ",")) + } + + return values +} diff --git a/pkg/utils/headers.go b/pkg/utils/headers.go new file mode 100755 index 0000000..d8ca9b1 --- /dev/null +++ b/pkg/utils/headers.go @@ -0,0 +1,100 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "context" + "fmt" + "net/http" + "reflect" + "strings" +) + +func PopulateHeaders(ctx context.Context, req *http.Request, headers interface{}) { + headerParamsStructType := reflect.TypeOf(headers) + headerParamsValType := reflect.ValueOf(headers) + + for i := 0; i < headerParamsStructType.NumField(); i++ { + fieldType := headerParamsStructType.Field(i) + valType := headerParamsValType.Field(i) + + tag := parseParamTag(headerParamTagKey, fieldType, "simple", false) + if tag == nil { + continue + } + + value := serializeHeader(fieldType.Type, valType, tag.Explode) + if value != "" { + req.Header.Add(tag.ParamName, value) + } + } +} + +func serializeHeader(objType reflect.Type, objValue reflect.Value, explode bool) string { + if objType.Kind() == reflect.Pointer { + if objValue.IsNil() { + return "" + } + objType = objType.Elem() + objValue = objValue.Elem() + } + + switch objType.Kind() { + case reflect.Struct: + items := []string{} + + for i := 0; i < objType.NumField(); i++ { + fieldType := objType.Field(i) + valType := objValue.Field(i) + + if fieldType.Type.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + valType = valType.Elem() + } + + tag := parseParamTag(headerParamTagKey, fieldType, "simple", false) + if tag == nil { + continue + } + + fieldName := tag.ParamName + + if fieldName == "" { + continue + } + + if explode { + items = append(items, fmt.Sprintf("%s=%s", fieldName, valToString(valType.Interface()))) + } else { + items = append(items, fieldName, valToString(valType.Interface())) + } + } + + return strings.Join(items, ",") + case reflect.Map: + items := []string{} + + iter := objValue.MapRange() + for iter.Next() { + if explode { + items = append(items, fmt.Sprintf("%s=%s", iter.Key().String(), valToString(iter.Value().Interface()))) + } else { + items = append(items, iter.Key().String(), valToString(iter.Value().Interface())) + } + } + + return strings.Join(items, ",") + case reflect.Slice, reflect.Array: + items := []string{} + + for i := 0; i < objValue.Len(); i++ { + items = append(items, valToString(objValue.Index(i).Interface())) + } + + return strings.Join(items, ",") + default: + return valToString(objValue.Interface()) + } +} diff --git a/pkg/utils/pathparams.go b/pkg/utils/pathparams.go new file mode 100755 index 0000000..7bf4b87 --- /dev/null +++ b/pkg/utils/pathparams.go @@ -0,0 +1,115 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "context" + "fmt" + "reflect" + "strings" +) + +func GenerateURL(ctx context.Context, serverURL, path string, pathParams interface{}, globals map[string]map[string]map[string]interface{}) string { + url := strings.TrimSuffix(serverURL, "/") + path + + pathParamsStructType := reflect.TypeOf(pathParams) + pathParamsValType := reflect.ValueOf(pathParams) + + parsedParameters := map[string]string{} + + for i := 0; i < pathParamsStructType.NumField(); i++ { + fieldType := pathParamsStructType.Field(i) + valType := pathParamsValType.Field(i) + + requestTag := getRequestTag(fieldType) + if requestTag != nil { + continue + } + + ppTag := parseParamTag(pathParamTagKey, fieldType, "simple", false) + if ppTag == nil { + continue + } + + valType = populateFromGlobals(fieldType, valType, "pathParam", globals) + + // TODO: support other styles + switch ppTag.Style { + case "simple": + simpleParams := getSimplePathParams(ctx, ppTag.ParamName, fieldType.Type, valType, ppTag.Explode) + for k, v := range simpleParams { + parsedParameters[k] = v + } + } + } + + // TODO should we handle the case where there are no matching path params? + return ReplaceParameters(url, parsedParameters) +} + +func getSimplePathParams(ctx context.Context, parentName string, objType reflect.Type, objValue reflect.Value, explode bool) map[string]string { + pathParams := make(map[string]string) + + if objType.Kind() == reflect.Ptr { + if objValue.IsNil() { + return nil + } + objType = objType.Elem() + objValue = objValue.Elem() + } + + switch objType.Kind() { + case reflect.Array, reflect.Slice: + if objValue.Len() == 0 { + return nil + } + var ppVals []string + for i := 0; i < objValue.Len(); i++ { + ppVals = append(ppVals, valToString(objValue.Index(i).Interface())) + } + pathParams[parentName] = strings.Join(ppVals, ",") + case reflect.Map: + if objValue.Len() == 0 { + return nil + } + var ppVals []string + objMap := objValue.MapRange() + for objMap.Next() { + if explode { + ppVals = append(ppVals, fmt.Sprintf("%s=%s", objMap.Key().String(), valToString(objMap.Value().Interface()))) + } else { + ppVals = append(ppVals, fmt.Sprintf("%s,%s", objMap.Key().String(), valToString(objMap.Value().Interface()))) + } + } + pathParams[parentName] = strings.Join(ppVals, ",") + case reflect.Struct: + var ppVals []string + for i := 0; i < objType.NumField(); i++ { + fieldType := objType.Field(i) + valType := objValue.Field(i) + + ppTag := parseParamTag(pathParamTagKey, fieldType, "simple", explode) + if ppTag == nil { + continue + } + + if fieldType.Type.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + valType = valType.Elem() + } + + if explode { + ppVals = append(ppVals, fmt.Sprintf("%s=%s", ppTag.ParamName, valToString(valType.Interface()))) + } else { + ppVals = append(ppVals, fmt.Sprintf("%s,%s", ppTag.ParamName, valToString(valType.Interface()))) + } + } + pathParams[parentName] = strings.Join(ppVals, ",") + default: + pathParams[parentName] = valToString(objValue.Interface()) + } + + return pathParams +} diff --git a/pkg/utils/queryparams.go b/pkg/utils/queryparams.go new file mode 100755 index 0000000..ca07229 --- /dev/null +++ b/pkg/utils/queryparams.go @@ -0,0 +1,173 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/url" + "reflect" +) + +func PopulateQueryParams(ctx context.Context, req *http.Request, queryParams interface{}, globals map[string]map[string]map[string]interface{}) error { + queryParamsStructType := reflect.TypeOf(queryParams) + queryParamsValType := reflect.ValueOf(queryParams) + + values := url.Values{} + + for i := 0; i < queryParamsStructType.NumField(); i++ { + fieldType := queryParamsStructType.Field(i) + valType := queryParamsValType.Field(i) + + requestTag := getRequestTag(fieldType) + if requestTag != nil { + continue + } + + qpTag := parseQueryParamTag(fieldType) + if qpTag == nil { + continue + } + + valType = populateFromGlobals(fieldType, valType, "queryParam", globals) + + if qpTag.Serialization != "" { + vals, err := populateSerializedParams(req, qpTag, fieldType.Type, valType) + if err != nil { + return err + } + for k, v := range vals { + for _, vv := range v { + values.Add(k, vv) + } + } + } else { + switch qpTag.Style { + case "deepObject": + vals := populateDeepObjectParams(req, qpTag, fieldType.Type, valType) + for k, v := range vals { + for _, vv := range v { + values.Add(k, vv) + } + } + case "form": + vals := populateFormParams(req, qpTag, fieldType.Type, valType) + for k, v := range vals { + for _, vv := range v { + values.Add(k, vv) + } + } + default: + return fmt.Errorf("unsupported style: %s", qpTag.Style) + } + } + } + + req.URL.RawQuery = values.Encode() + + return nil +} + +func populateSerializedParams(req *http.Request, tag *paramTag, objType reflect.Type, objValue reflect.Value) (url.Values, error) { + values := url.Values{} + + if objType.Kind() == reflect.Pointer { + if objValue.IsNil() { + return values, nil + } + objValue = objValue.Elem() + } + if objValue.Interface() == nil { + return values, nil + } + + switch tag.Serialization { + case "json": + data, err := json.Marshal(objValue.Interface()) + if err != nil { + return nil, fmt.Errorf("error marshaling json: %v", err) + } + values.Add(tag.ParamName, string(data)) + } + + return values, nil +} + +func populateDeepObjectParams(req *http.Request, tag *paramTag, objType reflect.Type, objValue reflect.Value) url.Values { + values := url.Values{} + + if objType.Kind() == reflect.Pointer { + if objValue.IsNil() { + return values + } + objType = objType.Elem() + objValue = objValue.Elem() + } + + switch objType.Kind() { + case reflect.Struct: + for i := 0; i < objType.NumField(); i++ { + fieldType := objType.Field(i) + valType := objValue.Field(i) + + if fieldType.Type.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + valType = valType.Elem() + } + + qpTag := parseQueryParamTag(fieldType) + if qpTag == nil { + continue + } + + switch valType.Kind() { + case reflect.Array, reflect.Slice: + for i := 0; i < valType.Len(); i++ { + values.Add(fmt.Sprintf("%s[%s]", tag.ParamName, qpTag.ParamName), valToString(valType.Index(i).Interface())) + } + default: + values.Add(fmt.Sprintf("%s[%s]", tag.ParamName, qpTag.ParamName), valToString(valType.Interface())) + } + } + case reflect.Map: + iter := objValue.MapRange() + for iter.Next() { + switch iter.Value().Kind() { + case reflect.Array, reflect.Slice: + for i := 0; i < iter.Value().Len(); i++ { + values.Add(fmt.Sprintf("%s[%s]", tag.ParamName, iter.Key().String()), valToString(iter.Value().Index(i).Interface())) + } + default: + values.Add(fmt.Sprintf("%s[%s]", tag.ParamName, iter.Key().String()), valToString(iter.Value().Interface())) + } + } + } + + return values +} + +func populateFormParams(req *http.Request, tag *paramTag, objType reflect.Type, objValue reflect.Value) url.Values { + return populateForm(tag.ParamName, tag.Explode, objType, objValue, func(fieldType reflect.StructField) string { + qpTag := parseQueryParamTag(fieldType) + if qpTag == nil { + return "" + } + + return qpTag.ParamName + }) +} + +type paramTag struct { + Style string + Explode bool + ParamName string + Serialization string +} + +func parseQueryParamTag(field reflect.StructField) *paramTag { + return parseParamTag(queryParamTagKey, field, "form", true) +} diff --git a/pkg/utils/requestbody.go b/pkg/utils/requestbody.go new file mode 100755 index 0000000..340829f --- /dev/null +++ b/pkg/utils/requestbody.go @@ -0,0 +1,373 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "mime/multipart" + "net/url" + "reflect" + "regexp" +) + +const ( + requestTagKey = "request" + multipartFormTagKey = "multipartForm" + formTagKey = "form" +) + +var ( + jsonEncodingRegex = regexp.MustCompile(`(application|text)\/.*?\+*json.*`) + multipartEncodingRegex = regexp.MustCompile(`multipart\/.*`) + urlEncodedEncodingRegex = regexp.MustCompile(`application\/x-www-form-urlencoded.*`) +) + +func SerializeRequestBody(ctx context.Context, request interface{}, requestFieldName string, serializationMethod string) (*bytes.Buffer, string, error) { + requestStructType := reflect.TypeOf(request) + requestValType := reflect.ValueOf(request) + + if requestStructType.Kind() == reflect.Pointer { + if requestValType.IsNil() { + return nil, "", nil + } + + requestStructType = requestStructType.Elem() + requestValType = requestValType.Elem() + } + + if requestStructType.Kind() != reflect.Struct { + return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType) + } + + requestField, ok := requestStructType.FieldByName(requestFieldName) + + if ok { + tag := getRequestTag(requestField) + if tag != nil { + // request object (non-flattened) + requestVal := requestValType.FieldByName(requestFieldName) + if requestField.Type.Kind() == reflect.Pointer && requestVal.IsNil() { + return nil, "", nil + } + + return serializeContentType(requestFieldName, tag.MediaType, requestVal) + } + } + + // flattened request object + return serializeContentType(requestFieldName, SerializationMethodToContentType[serializationMethod], requestValType) +} + +func serializeContentType(fieldName string, mediaType string, val reflect.Value) (*bytes.Buffer, string, error) { + buf := &bytes.Buffer{} + + switch { + case jsonEncodingRegex.MatchString(mediaType): + if err := json.NewEncoder(buf).Encode(val.Interface()); err != nil { + return nil, "", err + } + case multipartEncodingRegex.MatchString(mediaType): + var err error + mediaType, err = encodeMultipartFormData(buf, val.Interface()) + if err != nil { + return nil, "", err + } + case urlEncodedEncodingRegex.MatchString(mediaType): + if err := encodeFormData(fieldName, buf, val.Interface()); err != nil { + return nil, "", err + } + default: + val = reflect.Indirect(val) + + switch { + case val.Type().Kind() == reflect.String: + if _, err := buf.WriteString(valToString(val.Interface())); err != nil { + return nil, "", err + } + case val.Type() == reflect.TypeOf([]byte(nil)): + if _, err := buf.Write(val.Bytes()); err != nil { + return nil, "", err + } + default: + return nil, "", fmt.Errorf("invalid request body type %s for mediaType %s", val.Type(), mediaType) + } + } + + return buf, mediaType, nil +} + +func encodeMultipartFormData(w io.Writer, data interface{}) (string, error) { + requestStructType := reflect.TypeOf(data) + requestValType := reflect.ValueOf(data) + + if requestStructType.Kind() == reflect.Pointer { + requestStructType = requestStructType.Elem() + requestValType = requestValType.Elem() + } + + writer := multipart.NewWriter(w) + + for i := 0; i < requestStructType.NumField(); i++ { + field := requestStructType.Field(i) + fieldType := field.Type + valType := requestValType.Field(i) + + if fieldType.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + + fieldType = fieldType.Elem() + valType = valType.Elem() + } + + tag := parseMultipartFormTag(field) + if tag.File { + if err := encodeMultipartFormDataFile(writer, fieldType, valType); err != nil { + writer.Close() + return "", err + } + } else if tag.JSON { + jw, err := writer.CreateFormField(tag.Name) + if err != nil { + writer.Close() + return "", err + } + d, err := json.Marshal(valType.Interface()) + if err != nil { + writer.Close() + return "", err + } + if _, err := jw.Write(d); err != nil { + writer.Close() + return "", err + } + } else { + switch fieldType.Kind() { + case reflect.Slice, reflect.Array: + values := parseFormStyleArray(true, valType) + for _, v := range values { + if err := writer.WriteField(tag.Name+"[]", v); err != nil { + writer.Close() + return "", err + } + } + default: + if err := writer.WriteField(tag.Name, valToString(valType.Interface())); err != nil { + writer.Close() + return "", err + } + } + } + } + + if err := writer.Close(); err != nil { + return "", err + } + + return writer.FormDataContentType(), nil +} + +func encodeMultipartFormDataFile(w *multipart.Writer, fieldType reflect.Type, valType reflect.Value) error { + if fieldType.Kind() != reflect.Struct { + return fmt.Errorf("invalid type %s for multipart/form-data file", valType.Type()) + } + + var fieldName string + var fileName string + var content []byte + + for i := 0; i < fieldType.NumField(); i++ { + field := fieldType.Field(i) + val := valType.Field(i) + + tag := parseMultipartFormTag(field) + if !tag.Content && tag.Name == "" { + continue + } + + if tag.Content { + content = val.Bytes() + } else { + fieldName = tag.Name + fileName = val.String() + } + } + + if fieldName == "" || fileName == "" || content == nil { + return fmt.Errorf("invalid multipart/form-data file") + } + + fw, err := w.CreateFormFile(fieldName, fileName) + if err != nil { + return err + } + if _, err := fw.Write(content); err != nil { + return err + } + + return nil +} + +func encodeFormData(fieldName string, w io.Writer, data interface{}) error { + requestType := reflect.TypeOf(data) + requestValType := reflect.ValueOf(data) + + if requestType.Kind() == reflect.Pointer { + requestType = requestType.Elem() + requestValType = requestValType.Elem() + } + + dataValues := url.Values{} + + switch requestType.Kind() { + case reflect.Struct: + for i := 0; i < requestType.NumField(); i++ { + field := requestType.Field(i) + fieldType := field.Type + valType := requestValType.Field(i) + + if fieldType.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + + fieldType = fieldType.Elem() + valType = valType.Elem() + } + + tag := parseFormTag(field) + if tag.JSON { + data, err := json.Marshal(valType.Interface()) + if err != nil { + return err + } + dataValues.Set(tag.Name, string(data)) + } else { + switch tag.Style { + // TODO: support other styles + case "form": + values := populateForm(tag.Name, tag.Explode, fieldType, valType, func(sf reflect.StructField) string { + tag := parseFormTag(field) + if tag == nil { + return "" + } + + return tag.Name + }) + for k, v := range values { + for _, vv := range v { + dataValues.Add(k, vv) + } + } + } + } + } + case reflect.Map: + for _, k := range requestValType.MapKeys() { + v := requestValType.MapIndex(k) + dataValues.Set(fmt.Sprintf("%v", k.Interface()), valToString(v.Interface())) + } + case reflect.Slice, reflect.Array: + for i := 0; i < requestValType.Len(); i++ { + v := requestValType.Index(i) + dataValues.Set(fieldName, valToString(v.Interface())) + } + } + + if _, err := w.Write([]byte(dataValues.Encode())); err != nil { + return err + } + + return nil +} + +type requestTag struct { + MediaType string +} + +func getRequestTag(field reflect.StructField) *requestTag { + // example `request:"mediaType=multipart/form-data"` + values := parseStructTag(requestTagKey, field) + if values == nil { + return nil + } + + tag := &requestTag{ + MediaType: "application/octet-stream", + } + + for k, v := range values { + switch k { + case "mediaType": + tag.MediaType = v + } + } + + return tag +} + +type multipartFormTag struct { + File bool + Content bool + JSON bool + Name string +} + +func parseMultipartFormTag(field reflect.StructField) *multipartFormTag { + // example `multipartForm:"name=file"` + values := parseStructTag(multipartFormTagKey, field) + + tag := &multipartFormTag{} + + for k, v := range values { + switch k { + case "file": + tag.File = v == "true" + case "content": + tag.Content = v == "true" + case "name": + tag.Name = v + case "json": + tag.JSON = v == "true" + } + } + + return tag +} + +type formTag struct { + Name string + JSON bool + Style string + Explode bool +} + +func parseFormTag(field reflect.StructField) *formTag { + // example `form:"name=propName,style=spaceDelimited,explode"` + values := parseStructTag(formTagKey, field) + + tag := &formTag{ + Style: "form", + Explode: true, + } + + for k, v := range values { + switch k { + case "name": + tag.Name = v + case "json": + tag.JSON = v == "true" + case "style": + tag.Style = v + case "explode": + tag.Explode = v == "true" + } + } + + return tag +} diff --git a/pkg/utils/retries.go b/pkg/utils/retries.go new file mode 100755 index 0000000..ff39d0d --- /dev/null +++ b/pkg/utils/retries.go @@ -0,0 +1,117 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + "strconv" + "strings" + "time" + + "github.com/cenkalti/backoff/v4" +) + +var errRequestFailed = errors.New("request failed") + +type BackoffStrategy struct { + InitialInterval int + MaxInterval int + Exponent float64 + MaxElapsedTime int +} + +type RetryConfig struct { + Strategy string + Backoff *BackoffStrategy + RetryConnectionErrors bool +} + +type Retries struct { + Config *RetryConfig + StatusCodes []string +} + +func Retry(ctx context.Context, r Retries, action func() (*http.Response, error)) (*http.Response, error) { + switch r.Config.Strategy { + case "backoff": + if r.Config.Backoff == nil { + return action() + } + + config := backoff.NewExponentialBackOff() + config.InitialInterval = time.Duration(r.Config.Backoff.InitialInterval) * time.Millisecond + config.MaxInterval = time.Duration(r.Config.Backoff.MaxInterval) * time.Millisecond + config.Multiplier = r.Config.Backoff.Exponent + config.MaxElapsedTime = time.Duration(r.Config.Backoff.MaxElapsedTime) * time.Millisecond + config.Reset() + + var resp *http.Response + + err := backoff.Retry(func() error { + if resp != nil { + resp.Body.Close() + } + + select { + case <-ctx.Done(): + return backoff.Permanent(ctx.Err()) + default: + } + + res, err := action() + if err != nil { + urlError := new(url.Error) + if errors.As(err, &urlError) { + if (urlError.Temporary() || urlError.Timeout()) && r.Config.RetryConnectionErrors { + return err + } + } + + return backoff.Permanent(err) + } + resp = res + if res == nil { + return fmt.Errorf("no response") + } + + for _, code := range r.StatusCodes { + if strings.Contains(strings.ToUpper(code), "X") { + codeRange, err := strconv.Atoi(code[:1]) + if err != nil { + continue + } + + s := res.StatusCode / 100 + + if s >= codeRange && s < codeRange+1 { + return errRequestFailed + } + } else { + parsedCode, err := strconv.Atoi(code) + if err != nil { + continue + } + + if res.StatusCode == parsedCode { + return errRequestFailed + } + } + } + + resp = res + + return nil + }, config) + if err != nil && !errors.Is(err, errRequestFailed) { + return nil, err + } + + return resp, nil + default: + return action() + } +} diff --git a/pkg/utils/security.go b/pkg/utils/security.go new file mode 100755 index 0000000..c920eab --- /dev/null +++ b/pkg/utils/security.go @@ -0,0 +1,284 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "encoding/base64" + "fmt" + "net/http" + "reflect" + "strings" +) + +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +const ( + securityTagKey = "security" +) + +type securityTag struct { + Option bool + Scheme bool + Name string + Type string + SubType string +} + +type SecurityClient struct { + client HTTPClient + headers map[string]string + queryParams map[string]string +} + +func newSecurityClient(client HTTPClient) *SecurityClient { + return &SecurityClient{ + client: client, + headers: make(map[string]string), + queryParams: make(map[string]string), + } +} + +func (c *SecurityClient) Do(req *http.Request) (*http.Response, error) { + for k, v := range c.headers { + req.Header.Set(k, v) + } + + queryParams := req.URL.Query() + + for k, v := range c.queryParams { + queryParams.Set(k, v) + } + + req.URL.RawQuery = queryParams.Encode() + + return c.client.Do(req) +} + +func ConfigureSecurityClient(c HTTPClient, security interface{}) *SecurityClient { + client := parseSecurityStruct(c, security) + if client != nil { + return client + } + + return newSecurityClient(c) +} + +func parseSecurityStruct(c HTTPClient, security interface{}) *SecurityClient { + securityStructType := reflect.TypeOf(security) + securityValType := reflect.ValueOf(security) + + if securityStructType.Kind() == reflect.Ptr { + if securityValType.IsNil() { + return nil + } + + securityStructType = securityStructType.Elem() + securityValType = securityValType.Elem() + } + + client := newSecurityClient(c) + + for i := 0; i < securityStructType.NumField(); i++ { + fieldType := securityStructType.Field(i) + valType := securityValType.Field(i) + + kind := valType.Kind() + + if fieldType.Type.Kind() == reflect.Pointer { + if valType.IsNil() { + continue + } + + kind = valType.Elem().Kind() + } + + secTag := parseSecurityTag(fieldType) + if secTag != nil { + if secTag.Option { + return parseSecurityOption(c, valType.Interface()) + } else if secTag.Scheme { + // Special case for basic auth which could be a flattened struct + if secTag.SubType == "basic" && kind != reflect.Struct { + parseSecurityScheme(client, secTag, security) + return client + } else { + parseSecurityScheme(client, secTag, valType.Interface()) + } + } + } + } + + return client +} + +func parseSecurityOption(c HTTPClient, option interface{}) *SecurityClient { + optionStructType := reflect.TypeOf(option) + optionValType := reflect.ValueOf(option) + + if optionStructType.Kind() == reflect.Ptr { + if optionValType.IsNil() { + return nil + } + + optionStructType = optionStructType.Elem() + optionValType = optionValType.Elem() + } + + client := newSecurityClient(c) + + for i := 0; i < optionStructType.NumField(); i++ { + fieldType := optionStructType.Field(i) + valType := optionValType.Field(i) + + secTag := parseSecurityTag(fieldType) + if secTag != nil && secTag.Scheme { + parseSecurityScheme(client, secTag, valType.Interface()) + } + } + + return client +} + +func parseSecurityScheme(client *SecurityClient, schemeTag *securityTag, scheme interface{}) { + schemeType := reflect.TypeOf(scheme) + schemeVal := reflect.ValueOf(scheme) + + if schemeType.Kind() == reflect.Ptr { + if schemeVal.IsNil() { + return + } + + schemeType = schemeType.Elem() + schemeVal = schemeVal.Elem() + } + + if schemeType.Kind() == reflect.Struct { + if schemeTag.Type == "http" && schemeTag.SubType == "basic" { + parseBasicAuthScheme(client, schemeVal.Interface()) + return + } + + for i := 0; i < schemeType.NumField(); i++ { + fieldType := schemeType.Field(i) + valType := schemeVal.Field(i) + + if fieldType.Type.Kind() == reflect.Ptr { + if valType.IsNil() { + continue + } + + valType = valType.Elem() + } + + secTag := parseSecurityTag(fieldType) + if secTag == nil || secTag.Name == "" { + return + } + + parseSecuritySchemeValue(client, schemeTag, secTag, valType.Interface()) + } + } else { + parseSecuritySchemeValue(client, schemeTag, schemeTag, schemeVal.Interface()) + } +} + +func parseSecuritySchemeValue(client *SecurityClient, schemeTag *securityTag, secTag *securityTag, val interface{}) { + switch schemeTag.Type { + case "apiKey": + switch schemeTag.SubType { + case "header": + client.headers[secTag.Name] = valToString(val) + case "query": + client.queryParams[secTag.Name] = valToString(val) + case "cookie": + client.headers["Cookie"] = fmt.Sprintf("%s=%s", secTag.Name, valToString(val)) + default: + panic("not supported") + } + case "openIdConnect": + client.headers[secTag.Name] = valToString(val) + case "oauth2": + client.headers[secTag.Name] = valToString(val) + case "http": + switch schemeTag.SubType { + case "bearer": + client.headers[secTag.Name] = valToString(val) + default: + panic("not supported") + } + default: + panic("not supported") + } +} + +func parseBasicAuthScheme(client *SecurityClient, scheme interface{}) { + schemeStructType := reflect.TypeOf(scheme) + schemeValType := reflect.ValueOf(scheme) + + var username, password string + + for i := 0; i < schemeStructType.NumField(); i++ { + fieldType := schemeStructType.Field(i) + valType := schemeValType.Field(i) + + secTag := parseSecurityTag(fieldType) + if secTag == nil || secTag.Name == "" { + continue + } + + switch secTag.Name { + case "username": + username = valType.String() + case "password": + password = valType.String() + } + } + + client.headers["Authorization"] = fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password)))) +} + +func parseSecurityTag(field reflect.StructField) *securityTag { + tag := field.Tag.Get(securityTagKey) + if tag == "" { + return nil + } + + option := false + scheme := false + name := "" + securityType := "" + securitySubType := "" + + options := strings.Split(tag, ",") + for _, optionConf := range options { + parts := strings.Split(optionConf, "=") + if len(parts) < 1 || len(parts) > 2 { + continue + } + + switch parts[0] { + case "name": + name = parts[1] + case "type": + securityType = parts[1] + case "subtype": + securitySubType = parts[1] + case "option": + option = true + case "scheme": + scheme = true + } + } + + // TODO: validate tag? + + return &securityTag{ + Option: option, + Scheme: scheme, + Name: name, + Type: securityType, + SubType: securitySubType, + } +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go new file mode 100755 index 0000000..c50f4ee --- /dev/null +++ b/pkg/utils/utils.go @@ -0,0 +1,142 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package utils + +import ( + "encoding/json" + "fmt" + "io" + "reflect" + "regexp" + "strings" + "time" +) + +const ( + queryParamTagKey = "queryParam" + headerParamTagKey = "header" + pathParamTagKey = "pathParam" +) + +var ( + paramRegex = regexp.MustCompile(`({.*?})`) + SerializationMethodToContentType = map[string]string{ + "json": "application/json", + "form": "application/x-www-form-urlencoded", + "multipart": "multipart/form-data", + "raw": "application/octet-stream", + "string": "text/plain", + } +) + +func UnmarshalJsonFromResponseBody(body io.Reader, out interface{}) error { + data, err := io.ReadAll(body) + if err != nil { + return fmt.Errorf("error reading response body: %w", err) + } + if err := json.Unmarshal(data, &out); err != nil { + return fmt.Errorf("error unmarshalling json response body: %w", err) + } + + return nil +} + +func ReplaceParameters(stringWithParams string, params map[string]string) string { + return paramRegex.ReplaceAllStringFunc(stringWithParams, func(match string) string { + match = match[1 : len(match)-1] + return params[match] + }) +} + +func Contains(slice []string, item string) bool { + for _, s := range slice { + if s == item { + return true + } + } + return false +} + +func parseStructTag(tagKey string, field reflect.StructField) map[string]string { + tag := field.Tag.Get(tagKey) + if tag == "" { + return nil + } + + values := map[string]string{} + + options := strings.Split(tag, ",") + for _, optionConf := range options { + parts := strings.Split(optionConf, "=") + + switch len(parts) { + case 1: + // flag option + parts = append(parts, "true") + case 2: + // key=value option + break + default: + // invalid option + continue + } + + values[parts[0]] = parts[1] + } + + return values +} + +func parseParamTag(tagKey string, field reflect.StructField, defaultStyle string, defaultExplode bool) *paramTag { + // example `{tagKey}:"style=simple,explode=false,name=apiID"` + values := parseStructTag(tagKey, field) + + tag := ¶mTag{ + Style: defaultStyle, + Explode: defaultExplode, + ParamName: strings.ToLower(field.Name), + } + + for k, v := range values { + switch k { + case "style": + tag.Style = v + case "explode": + tag.Explode = v == "true" + case "name": + tag.ParamName = v + case "serialization": + tag.Serialization = v + } + } + + return tag +} + +func valToString(val interface{}) string { + switch v := val.(type) { + case time.Time: + return v.Format(time.RFC3339Nano) + default: + return fmt.Sprintf("%v", v) + } +} + +func populateFromGlobals(fieldType reflect.StructField, valType reflect.Value, paramType string, globals map[string]map[string]map[string]interface{}) reflect.Value { + if globals != nil && fieldType.Type.Kind() == reflect.Ptr { + parameters, ok := globals["parameters"] + if ok { + paramsOfType, ok := parameters[paramType] + if ok { + globalVal, ok := paramsOfType[fieldType.Name] + if ok { + if reflect.TypeOf(globalVal).Kind() == fieldType.Type.Elem().Kind() && valType.IsNil() { + valType = reflect.ValueOf(&globalVal) + } + } + } + } + } + + return valType +} diff --git a/sdk.go b/sdk.go new file mode 100755 index 0000000..a615c54 --- /dev/null +++ b/sdk.go @@ -0,0 +1,174 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "net/http" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" + "time" +) + +// ServerList contains the list of servers available to the SDK +var ServerList = []string{ + // Local Supaglue API + "http://localhost:8080/crm/v1", +} + +// HTTPClient provides an interface for suplying the SDK with a custom HTTP client +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + +// String provides a helper function to return a pointer to a string +func String(s string) *string { return &s } + +// SDK - # Introduction +// Welcome to the Supaglue unified CRM API documentation. You can use this API to read data that has been synced into Supaglue from third-party providers. +// ### Base API URL +// ``` +// http://localhost:8080/crm/v1 +// ``` +// +// https://www.postman.com/supaglue/workspace/supaglue-public/overview - Try out our API in Postman! +type SDK struct { + // Accounts - The `Account` Common Model is used to represent a "company" in CRMs. + Accounts *accounts + // Contacts - The `Contact` Common Model is used to represent a "contact" in CRMs. + Contacts *contacts + // Leads - The `Lead` Common Model is used to represent a "potential customer" in CRMs. + Leads *leads + // Opportunities - The `Opportunity` Common Model is used to represent a "deal opportunity" in CRMs. + Opportunities *opportunities + // Passthrough - Passthrough operations to underlying providers. + Passthrough *passthrough + // Users - The `User` Common Model is used to represent a "user" that can login to CRMs. + Users *users + + // Non-idiomatic field names below are to namespace fields from the fields names above to avoid name conflicts + _defaultClient HTTPClient + _securityClient HTTPClient + _security *shared.Security + _serverURL string + _language string + _sdkVersion string + _genVersion string +} + +type SDKOption func(*SDK) + +// WithServerURL allows the overriding of the default server URL +func WithServerURL(serverURL string) SDKOption { + return func(sdk *SDK) { + sdk._serverURL = serverURL + } +} + +// WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters +func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption { + return func(sdk *SDK) { + if params != nil { + serverURL = utils.ReplaceParameters(serverURL, params) + } + + sdk._serverURL = serverURL + } +} + +// WithClient allows the overriding of the default HTTP client used by the SDK +func WithClient(client HTTPClient) SDKOption { + return func(sdk *SDK) { + sdk._defaultClient = client + } +} + +// WithSecurity configures the SDK to use the provided security details +func WithSecurity(security shared.Security) SDKOption { + return func(sdk *SDK) { + sdk._security = &security + } +} + +// New creates a new instance of the SDK with the provided options +func New(opts ...SDKOption) *SDK { + sdk := &SDK{ + _language: "go", + _sdkVersion: "1.0.0", + _genVersion: "2.16.4", + } + for _, opt := range opts { + opt(sdk) + } + + // Use WithClient to override the default client if you would like to customize the timeout + if sdk._defaultClient == nil { + sdk._defaultClient = &http.Client{Timeout: 60 * time.Second} + } + if sdk._securityClient == nil { + if sdk._security != nil { + sdk._securityClient = utils.ConfigureSecurityClient(sdk._defaultClient, sdk._security) + } else { + sdk._securityClient = sdk._defaultClient + } + } + + if sdk._serverURL == "" { + sdk._serverURL = ServerList[0] + } + + sdk.Accounts = newAccounts( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + sdk.Contacts = newContacts( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + sdk.Leads = newLeads( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + sdk.Opportunities = newOpportunities( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + sdk.Passthrough = newPassthrough( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + sdk.Users = newUsers( + sdk._defaultClient, + sdk._securityClient, + sdk._serverURL, + sdk._language, + sdk._sdkVersion, + sdk._genVersion, + ) + + return sdk +} diff --git a/users.go b/users.go new file mode 100755 index 0000000..8ffe8df --- /dev/null +++ b/users.go @@ -0,0 +1,131 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +package sdk + +import ( + "context" + "fmt" + "net/http" + "strings" + "supaglue/pkg/models/operations" + "supaglue/pkg/models/shared" + "supaglue/pkg/utils" +) + +// users - The `User` Common Model is used to represent a "user" that can login to CRMs. +type users struct { + defaultClient HTTPClient + securityClient HTTPClient + serverURL string + language string + sdkVersion string + genVersion string +} + +func newUsers(defaultClient, securityClient HTTPClient, serverURL, language, sdkVersion, genVersion string) *users { + return &users{ + defaultClient: defaultClient, + securityClient: securityClient, + serverURL: serverURL, + language: language, + sdkVersion: sdkVersion, + genVersion: genVersion, + } +} + +// Get - Get user +func (s *users) Get(ctx context.Context, request operations.GetUserRequest) (*operations.GetUserResponse, error) { + baseURL := s.serverURL + url := utils.GenerateURL(ctx, baseURL, "/users/{user_id}", request.PathParams, nil) + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.GetUserResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *shared.User + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.User = out + } + } + + return res, nil +} + +// List - List users +// Get a list of users +func (s *users) List(ctx context.Context, request operations.ListUsersRequest) (*operations.ListUsersResponse, error) { + baseURL := s.serverURL + url := strings.TrimSuffix(baseURL, "/") + "/users" + + req, err := http.NewRequestWithContext(ctx, "GET", url, nil) + if err != nil { + return nil, fmt.Errorf("error creating request: %w", err) + } + + utils.PopulateHeaders(ctx, req, request.Headers) + + if err := utils.PopulateQueryParams(ctx, req, request.QueryParams, nil); err != nil { + return nil, fmt.Errorf("error populating query params: %w", err) + } + + client := s.securityClient + + httpRes, err := client.Do(req) + if err != nil { + return nil, fmt.Errorf("error sending request: %w", err) + } + if httpRes == nil { + return nil, fmt.Errorf("error sending request: no response") + } + defer httpRes.Body.Close() + + contentType := httpRes.Header.Get("Content-Type") + + res := &operations.ListUsersResponse{ + StatusCode: httpRes.StatusCode, + ContentType: contentType, + RawResponse: httpRes, + } + switch { + case httpRes.StatusCode == 200: + switch { + case utils.MatchContentType(contentType, `application/json`): + var out *operations.ListUsers200ApplicationJSON + if err := utils.UnmarshalJsonFromResponseBody(httpRes.Body, &out); err != nil { + return nil, err + } + + res.ListUsers200ApplicationJSONObject = out + } + } + + return res, nil +}