diff --git a/examples/go/go-client/go.mod b/examples/go/go-client/go.mod index 6ec75755d..051b04e0e 100644 --- a/examples/go/go-client/go.mod +++ b/examples/go/go-client/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/golang/mock v1.6.0 github.com/stretchr/testify v1.7.0 - github.com/twilio/twilio-go v0.25.0 + github.com/twilio/twilio-go v1.29.1 ) require ( diff --git a/examples/go/go-client/go.sum b/examples/go/go-client/go.sum index b46acb1dc..0fe98cd0d 100644 --- a/examples/go/go-client/go.sum +++ b/examples/go/go-client/go.sum @@ -1,8 +1,9 @@ +github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= @@ -11,6 +12,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/localtunnel/go-localtunnel v0.0.0-20170326223115-8a804488f275/go.mod h1:zt6UU74K6Z6oMOYJbJzYpYucqdcQwSMPBEdSvGiaUMw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -19,8 +21,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/twilio/twilio-go v0.25.0 h1:Vk3OjsIcm//WTpywp3y+HD+Goiyf1SIiLQR+sxw+/gM= -github.com/twilio/twilio-go v0.25.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE= +github.com/twilio/twilio-go v1.29.1 h1:4dx1d9EhRUhL5ubzYrDROERAiw55s7mBE6/w3q2epVg= +github.com/twilio/twilio-go v1.29.1/go.mod h1:FpgNWMoD8CFnmukpKq9RNpUSGXC0BwnbeKZj2YHlIkw= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/examples/go/go-client/helper/client/mock_client.go b/examples/go/go-client/helper/client/mock_client.go index b8253464a..894107282 100644 --- a/examples/go/go-client/helper/client/mock_client.go +++ b/examples/go/go-client/helper/client/mock_client.go @@ -11,6 +11,7 @@ import ( time "time" gomock "github.com/golang/mock/gomock" + client "github.com/twilio/twilio-go/client" ) // MockBaseClient is a mock of BaseClient interface. @@ -51,18 +52,23 @@ func (mr *MockBaseClientMockRecorder) AccountSid() *gomock.Call { } // SendRequest mocks base method. -func (m *MockBaseClient) SendRequest(method, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error) { +func (m *MockBaseClient) SendRequest(method, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SendRequest", method, rawURL, data, headers) + varargs := []interface{}{method, rawURL, data, headers} + for _, a := range body { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SendRequest", varargs...) ret0, _ := ret[0].(*http.Response) ret1, _ := ret[1].(error) return ret0, ret1 } // SendRequest indicates an expected call of SendRequest. -func (mr *MockBaseClientMockRecorder) SendRequest(method, rawURL, data, headers interface{}) *gomock.Call { +func (mr *MockBaseClientMockRecorder) SendRequest(method, rawURL, data, headers interface{}, body ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRequest", reflect.TypeOf((*MockBaseClient)(nil).SendRequest), method, rawURL, data, headers) + varargs := append([]interface{}{method, rawURL, data, headers}, body...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendRequest", reflect.TypeOf((*MockBaseClient)(nil).SendRequest), varargs...) } // SetTimeout mocks base method. @@ -76,3 +82,29 @@ func (mr *MockBaseClientMockRecorder) SetTimeout(timeout interface{}) *gomock.Ca mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTimeout", reflect.TypeOf((*MockBaseClient)(nil).SetTimeout), timeout) } + +// SetOauth mocks base method. +func (m *MockBaseClient) SetOauth(auth client.OAuth) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetOauth", auth) +} + +// SetOauth indicates an expected call of SetOauth. +func (mr *MockBaseClientMockRecorder) SetOauth(auth interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetOauth", reflect.TypeOf((*MockBaseClient)(nil).SetOauth), auth) +} + +// OAuth mocks base method. +func (m *MockBaseClient) OAuth() client.OAuth { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "OAuth") + ret0, _ := ret[0].(client.OAuth) + return ret0 +} + +// OAuth indicates an expected call of OAuth. +func (mr *MockBaseClientMockRecorder) OAuth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OAuth", reflect.TypeOf((*MockBaseClient)(nil).OAuth)) +} diff --git a/examples/go/go-client/helper/client/test_client.go b/examples/go/go-client/helper/client/test_client.go index 264f6ee9b..909450804 100644 --- a/examples/go/go-client/helper/client/test_client.go +++ b/examples/go/go-client/helper/client/test_client.go @@ -12,7 +12,9 @@ type BaseClient interface { AccountSid() string SetTimeout(timeout time.Duration) SendRequest(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) + headers map[string]interface{}, body ...byte) (*http.Response, error) + SetOauth(auth client.OAuth) + OAuth() client.OAuth } type TestClient struct { @@ -37,6 +39,6 @@ func (tc *TestClient) getParsedUrl(path string) *url.URL { return parsedUrl } -func (tc *TestClient) SendRequest(method string, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error) { - return tc.Client.SendRequest(method, tc.getParsedUrl(rawURL).String(), data, headers) +func (tc *TestClient) SendRequest(method string, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { + return tc.Client.SendRequest(method, tc.getParsedUrl(rawURL).String(), data, headers, body...) } diff --git a/examples/go/go-client/helper/rest/api/v2010/unit_test.go b/examples/go/go-client/helper/rest/api/v2010/unit_test.go index d8a7a845a..8efae2255 100644 --- a/examples/go/go-client/helper/rest/api/v2010/unit_test.go +++ b/examples/go/go-client/helper/rest/api/v2010/unit_test.go @@ -28,7 +28,7 @@ func TestPathIsCorrect(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, "https://api.twilio.com/2010-04-01/Accounts/AC222222222222222222222222222222/Calls/123.json", rawURL) return &http.Response{Body: getEmptyBody()}, nil }, @@ -50,7 +50,7 @@ func TestAccountSidAsOptionalParam(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, "https://api.twilio.com/2010-04-01/Accounts/AC444444444444444444444444444444/Calls/123.json", rawURL) return &http.Response{Body: getEmptyBody()}, nil }, @@ -81,7 +81,7 @@ func TestAddingHeader(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, expectedHeader, headers) return &http.Response{Body: getEmptyBody()}, nil }, @@ -118,7 +118,7 @@ func TestQueryParams(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, expectedData, data) return &http.Response{Body: getEmptyBody()}, nil }, @@ -150,7 +150,7 @@ func TestArrayTypeParam(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, expectedData, data) return &http.Response{Body: getEmptyBody()}, nil }, @@ -169,7 +169,7 @@ func TestResponseDecodeTypes(t *testing.T) { gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error) { + DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "test_number": 123.45, "test_number_float": "67.89", @@ -205,7 +205,7 @@ func TestList(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "accounts": []map[string]interface{}{ { @@ -271,7 +271,7 @@ func TestListPaging(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "accounts": []map[string]interface{}{ { @@ -296,7 +296,7 @@ func TestListPaging(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "accounts": []map[string]interface{}{ { @@ -318,7 +318,7 @@ func TestListPaging(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { return &http.Response{Body: getEmptyBody()}, nil }, ) @@ -353,7 +353,7 @@ func TestListPagingError(t *testing.T) { gomock.InOrder( testClient.EXPECT().SendRequest(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "recordings": []map[string]interface{}{ { @@ -372,7 +372,7 @@ func TestListPagingError(t *testing.T) { }), testClient.EXPECT().SendRequest(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { return &http.Response{Body: io.NopCloser(bytes.NewReader(nil))}, nil }), ) diff --git a/examples/go/go-client/helper/rest/flex/v1/README.md b/examples/go/go-client/helper/rest/flex/v1/README.md index 0e3536d92..b4bb028c6 100644 --- a/examples/go/go-client/helper/rest/flex/v1/README.md +++ b/examples/go/go-client/helper/rest/flex/v1/README.md @@ -35,6 +35,7 @@ Class | Method | HTTP request | Description *CredentialsAWSApi* | [**DeleteCredentialAws**](docs/CredentialsAWSApi.md#deletecredentialaws) | **Delete** /v1/Credentials/AWS/{Sid} | *CredentialsAWSApi* | [**FetchCredentialAws**](docs/CredentialsAWSApi.md#fetchcredentialaws) | **Get** /v1/Credentials/AWS/{Sid} | *CredentialsAWSApi* | [**ListCredentialAws**](docs/CredentialsAWSApi.md#listcredentialaws) | **Get** /v1/Credentials/AWS | +*CredentialsAWSApi* | [**PatchCredentialAws**](docs/CredentialsAWSApi.md#patchcredentialaws) | **Patch** /v1/Credentials/AWS/{Sid} | *CredentialsAWSApi* | [**UpdateCredentialAws**](docs/CredentialsAWSApi.md#updatecredentialaws) | **Post** /v1/Credentials/AWS/{Sid} | *CredentialsAWSHistoryApi* | [**FetchCredentialHistory**](docs/CredentialsAWSHistoryApi.md#fetchcredentialhistory) | **Get** /v1/Credentials/AWS/{Sid}/History | *VoiceApi* | [**UpdateCall**](docs/VoiceApi.md#updatecall) | **Post** /v1/Voice/{Sid} | diff --git a/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go b/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go index 62cfd6df2..b4eaf3c93 100644 --- a/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go +++ b/examples/go/go-client/helper/rest/flex/v1/credentials_aws.go @@ -417,6 +417,54 @@ func (c *ApiService) getNextListCredentialAwsResponse(nextPageUrl string) (inter return ps, nil } +// Optional parameters for the method 'PatchCredentialAws' +type PatchCredentialAwsParams struct { + // + TestString *string `json:"TestString,omitempty"` + // + TestBoolean *bool `json:"TestBoolean,omitempty"` +} + +func (params *PatchCredentialAwsParams) SetTestString(TestString string) *PatchCredentialAwsParams { + params.TestString = &TestString + return params +} +func (params *PatchCredentialAwsParams) SetTestBoolean(TestBoolean bool) *PatchCredentialAwsParams { + params.TestBoolean = &TestBoolean + return params +} + +func (c *ApiService) PatchCredentialAws(Sid string, params *PatchCredentialAwsParams) (*TestResponseObject, error) { + path := "/v1/Credentials/AWS/{Sid}" + path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1) + + data := url.Values{} + headers := map[string]interface{}{ + "Content-Type": "application/x-www-form-urlencoded", + } + + if params != nil && params.TestString != nil { + data.Set("TestString", *params.TestString) + } + if params != nil && params.TestBoolean != nil { + data.Set("TestBoolean", fmt.Sprint(*params.TestBoolean)) + } + + resp, err := c.requestHandler.Patch(c.baseURL+path, data, headers) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + ps := &TestResponseObject{} + if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { + return nil, err + } + + return ps, err +} + // Optional parameters for the method 'UpdateCredentialAws' type UpdateCredentialAwsParams struct { // diff --git a/examples/go/go-client/helper/rest/flex/v1/unit_test.go b/examples/go/go-client/helper/rest/flex/v1/unit_test.go index 80643c1bd..de1cb561e 100644 --- a/examples/go/go-client/helper/rest/flex/v1/unit_test.go +++ b/examples/go/go-client/helper/rest/flex/v1/unit_test.go @@ -42,7 +42,7 @@ func TestObjectArrayTypeParam(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, expectedData, data) return &http.Response{Body: getEmptyBody()}, nil }, @@ -59,7 +59,7 @@ func TestUpdateOperation(t *testing.T) { gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error) { + DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, "POST", method) assert.Equal(t, "https://flex-api.twilio.com/v1/Voice/VO123", rawURL) return &http.Response{Body: getEmptyBody()}, nil @@ -83,7 +83,7 @@ func TestListError(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "credentials": []map[string]interface{}{ { @@ -129,7 +129,7 @@ func TestListNoNextPage(t *testing.T) { gomock.Any(), gomock.Any()). DoAndReturn(func(method string, rawURL string, data url.Values, - headers map[string]interface{}) (*http.Response, error) { + headers map[string]interface{}, body ...byte) (*http.Response, error) { response := map[string]interface{}{ "credentials": []map[string]interface{}{ { @@ -176,7 +176,7 @@ func TestPageToken(t *testing.T) { gomock.Any(), gomock.Any(), gomock.Any()). - DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error) { + DoAndReturn(func(method string, rawURL string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) { assert.Equal(t, expectedData, data) return &http.Response{Body: getEmptyBody()}, nil }).AnyTimes() diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/Aws.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/Aws.java index 1fded4654..03252126b 100644 --- a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/Aws.java +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/Aws.java @@ -86,6 +86,12 @@ public static AwsReader reader() { + + + + + + public static AwsUpdater updater(final String pathSid) { return new AwsUpdater( diff --git a/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsPatcher.java b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsPatcher.java new file mode 100644 index 000000000..a4c62658c --- /dev/null +++ b/examples/java/src/main/java/com/twilio/rest/flexapi/v1/credential/AwsPatcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.credential; + +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; + +import com.twilio.type.*; + + + public class AwsPatcher extends Patcher { + private String pathSid; + private String testString; + private Boolean testBoolean; + + public AwsPatcher(final String pathSid) { + this.pathSid = pathSid; + } + + +public AwsPatcher setTestString(final String testString){ + this.testString = testString; + return this; +} + + +public AwsPatcher setTestBoolean(final Boolean testBoolean){ + this.testBoolean = testBoolean; + return this; +} + + + @Override + public Aws patch(final TwilioRestClient client) { + + String path = "/v1/Credentials/AWS/{Sid}"; + + path = path.replace("{"+"Sid"+"}", this.pathSid.toString()); + + + Request request = new Request( + HttpMethod.PATCH, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException("Aws patch failed: Unable to connect to server"); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content", response.getStatusCode()); + } + throw new ApiException(restException); + } + + return Aws.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addPostParams(final Request request) { + + if (testString != null) { + Serializer.toString(request, "TestString", testString, ParameterType.URLENCODED); + } + + + + if (testBoolean != null) { + Serializer.toString(request, "TestBoolean", testBoolean, ParameterType.URLENCODED); + } + + +} + } diff --git a/examples/node/src/rest/flexApi/v1/credential/aws.ts b/examples/node/src/rest/flexApi/v1/credential/aws.ts index 7032b63ef..0e0a0c514 100644 --- a/examples/node/src/rest/flexApi/v1/credential/aws.ts +++ b/examples/node/src/rest/flexApi/v1/credential/aws.ts @@ -23,6 +23,16 @@ import { isValidPathParam } from "../../../../base/utility"; import { ApiResponse } from "../../../../base/ApiResponse"; import { HistoryListInstance } from "./aws/history"; +/** + * Options to pass to patch a AwsInstance + */ +export interface AwsContextPatchOptions { + /** */ + testString?: string; + /** */ + testBoolean?: boolean; +} + /** * Options to pass to update a AwsInstance */ @@ -116,6 +126,52 @@ export interface AwsContext { callback?: (error: Error | null, item?: ApiResponse) => any, ): Promise>; + /** + * Patch a AwsInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance + */ + patch( + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise; + /** + * Patch a AwsInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance + */ + patch( + params: AwsContextPatchOptions, + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise; + + /** + * Patch a AwsInstance and return HTTP info + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance with HTTP metadata + */ + patchWithHttpInfo( + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise>; + /** + * Patch a AwsInstance and return HTTP info + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance with HTTP metadata + */ + patchWithHttpInfo( + params: AwsContextPatchOptions, + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise>; + /** * Update a AwsInstance * @@ -300,6 +356,103 @@ export class AwsContextImpl implements AwsContext { return operationPromise; } + patch( + params?: + | AwsContextPatchOptions + | ((error: Error | null, item?: AwsInstance) => any), + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + if (params["testString"] !== undefined) + data["TestString"] = params["testString"]; + if (params["testBoolean"] !== undefined) + data["TestBoolean"] = serialize.bool(params["testBoolean"]); + + const headers: any = {}; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; + + const instance = this; + let operationVersion = instance._version, + operationPromise = operationVersion.patch({ + uri: instance._uri, + method: "patch", + data, + headers, + }); + + operationPromise = operationPromise.then( + (payload) => + new AwsInstance(operationVersion, payload, instance._solution.sid), + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback, + ); + return operationPromise; + } + + patchWithHttpInfo( + params?: + | AwsContextPatchOptions + | ((error: Error | null, item?: ApiResponse) => any), + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise> { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + if (params["testString"] !== undefined) + data["TestString"] = params["testString"]; + if (params["testBoolean"] !== undefined) + data["TestBoolean"] = serialize.bool(params["testBoolean"]); + + const headers: any = {}; + headers["Content-Type"] = "application/x-www-form-urlencoded"; + headers["Accept"] = "application/json"; + + const instance = this; + let operationVersion = instance._version; + // CREATE, FETCH, UPDATE operations + let operationPromise = operationVersion + .patchWithResponseInfo({ + uri: instance._uri, + method: "patch", + data, + headers, + }) + .then( + (response): ApiResponse => ({ + ...response, + body: new AwsInstance( + operationVersion, + response.body, + instance._solution.sid, + ), + }), + ); + + operationPromise = instance._version.setPromiseCallback( + operationPromise, + callback, + ); + return operationPromise; + } + update( params?: | AwsContextUpdateOptions @@ -502,6 +655,66 @@ export class AwsInstance { return this._proxy.fetchWithHttpInfo(callback); } + /** + * Patch a AwsInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance + */ + patch( + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise; + /** + * Patch a AwsInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance + */ + patch( + params: AwsContextPatchOptions, + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise; + + patch( + params?: any, + callback?: (error: Error | null, item?: AwsInstance) => any, + ): Promise { + return this._proxy.patch(params, callback); + } + + /** + * Patch a AwsInstance and return HTTP info + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance with HTTP metadata + */ + patchWithHttpInfo( + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise>; + /** + * Patch a AwsInstance and return HTTP info + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed AwsInstance with HTTP metadata + */ + patchWithHttpInfo( + params: AwsContextPatchOptions, + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise>; + + patchWithHttpInfo( + params?: any, + callback?: (error: Error | null, item?: ApiResponse) => any, + ): Promise> { + return this._proxy.patchWithHttpInfo(params, callback); + } + /** * Update a AwsInstance * diff --git a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsContext.php b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsContext.php index e33fb4e13..433d99821 100644 --- a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsContext.php +++ b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsContext.php @@ -153,6 +153,69 @@ public function fetchWithMetadata(): ResourceMetadata } + /** + * Helper function for Patch + * + * @param array|Options $options Optional Arguments + * @return Response Patchd Response + * @throws TwilioException When an HTTP error occurs. + */ + private function _patch(array $options = []): Response + { + $options = new Values($options); + + $data = Values::of([ + 'TestString' => + $options['testString'], + 'TestBoolean' => + Serialize::booleanToString($options['testBoolean']), + ]); + + $headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]); + return $this->version->handleRequest('PATCH', $this->uri, [], $data, $headers, "patch"); + } + + /** + * Patch the AwsInstance + * + * @param array|Options $options Optional Arguments + * @return AwsInstance Patchd AwsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function patch(array $options = []): AwsInstance + { + $response = $this->_patch($options); + return new AwsInstance( + $this->version, + $response->getContent(), + $this->solution['sid'] + ); + + } + + /** + * Patch the AwsInstance with Metadata + * + * @param array|Options $options Optional Arguments + * @return ResourceMetadata The Patchd Resource with Metadata + * @throws TwilioException When an HTTP error occurs. + */ + public function patchWithMetadata(array $options = []): ResourceMetadata + { + $response = $this->_patch($options); + $resource = new AwsInstance( + $this->version, + $response->getContent(), + $this->solution['sid'] + ); + return new ResourceMetadata( + $resource, + $response->getStatusCode(), + $response->getHeaders() + ); + } + + /** * Helper function for Update * diff --git a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsInstance.php b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsInstance.php index e137bab9e..9d5872457 100644 --- a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsInstance.php +++ b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsInstance.php @@ -99,6 +99,19 @@ public function fetch(): AwsInstance return $this->proxy()->fetch(); } + /** + * Patch the AwsInstance + * + * @param array|Options $options Optional Arguments + * @return AwsInstance Patchd AwsInstance + * @throws TwilioException When an HTTP error occurs. + */ + public function patch(array $options = []): AwsInstance + { + + return $this->proxy()->patch($options); + } + /** * Update the AwsInstance * diff --git a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsOptions.php b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsOptions.php index ce3b4f80d..7ec94a0ff 100644 --- a/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsOptions.php +++ b/examples/php/src/Twilio/Rest/FlexApi/V1/Credential/AwsOptions.php @@ -23,6 +23,24 @@ abstract class AwsOptions + /** + * @param string $testString + * @param bool $testBoolean + * @return PatchAwsOptions Options builder + */ + public static function patch( + + string $testString = Values::NONE, + bool $testBoolean = Values::BOOL_NONE + + ): PatchAwsOptions + { + return new PatchAwsOptions( + $testString, + $testBoolean + ); + } + /** * @param string $testString * @param bool $testBoolean @@ -46,6 +64,54 @@ public static function update( +class PatchAwsOptions extends Options + { + /** + * @param string $testString + * @param bool $testBoolean + */ + public function __construct( + + string $testString = Values::NONE, + bool $testBoolean = Values::BOOL_NONE + + ) { + $this->options['testString'] = $testString; + $this->options['testBoolean'] = $testBoolean; + } + + /** + * @param string $testString + * @return $this Fluent Builder + */ + public function setTestString(string $testString): self + { + $this->options['testString'] = $testString; + return $this; + } + + /** + * @param bool $testBoolean + * @return $this Fluent Builder + */ + public function setTestBoolean(bool $testBoolean): self + { + $this->options['testBoolean'] = $testBoolean; + return $this; + } + + /** + * Provide a friendly representation + * + * @return string Machine friendly representation + */ + public function __toString(): string + { + $options = \http_build_query(Values::of($this->options), '', ' '); + return '[Twilio.FlexApi.V1.PatchAwsOptions ' . $options . ']'; + } +} + class UpdateAwsOptions extends Options { /** diff --git a/examples/python/twilio/rest/api/v2010/account/__init__.py b/examples/python/twilio/rest/api/v2010/account/__init__.py index bdb557d8d..f01a040a7 100644 --- a/examples/python/twilio/rest/api/v2010/account/__init__.py +++ b/examples/python/twilio/rest/api/v2010/account/__init__.py @@ -300,6 +300,20 @@ def __init__(self, version: Version, sid: str): self._calls: Optional[CallList] = None + def _delete(self) -> tuple: + """ + Internal helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ + + headers = values.of({}) + + return self._version.delete_with_response_info( + method="DELETE", uri=self._uri, headers=headers + ) + def delete(self) -> bool: """ Deletes the AccountInstance @@ -307,10 +321,32 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = self._delete() + return success + + def delete_with_http_info(self) -> ApiResponse: + """ + Deletes the AccountInstance and return response metadata + + + :returns: ApiResponse with success boolean, status code, and headers + """ + success, status_code, headers = self._delete() + return ApiResponse(data=success, status_code=status_code, headers=headers) + + async def _delete_async(self) -> tuple: + """ + Internal async helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ headers = values.of({}) - return self._version.delete(method="DELETE", uri=self._uri, headers=headers) + return await self._version.delete_with_response_info_async( + method="DELETE", uri=self._uri, headers=headers + ) async def delete_async(self) -> bool: """ @@ -319,55 +355,109 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = await self._delete_async() + return success - headers = values.of({}) + async def delete_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine that deletes the AccountInstance and return response metadata - return await self._version.delete_async( - method="DELETE", uri=self._uri, headers=headers - ) - def fetch(self) -> AccountInstance: + :returns: ApiResponse with success boolean, status code, and headers """ - Fetch the AccountInstance + success, status_code, headers = await self._delete_async() + return ApiResponse(data=success, status_code=status_code, headers=headers) + def _fetch(self) -> tuple: + """ + Internal helper for fetch operation - :returns: The fetched AccountInstance + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) + return self._version.fetch_with_response_info( + method="GET", uri=self._uri, headers=headers + ) + + def fetch(self) -> AccountInstance: + """ + Fetch the AccountInstance + + :returns: The fetched AccountInstance + """ + payload, _, _ = self._fetch() return AccountInstance( self._version, payload, sid=self._solution["sid"], ) - async def fetch_async(self) -> AccountInstance: + def fetch_with_http_info(self) -> ApiResponse: """ - Asynchronous coroutine to fetch the AccountInstance + Fetch the AccountInstance and return response metadata - :returns: The fetched AccountInstance + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._fetch() + instance = AccountInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _fetch_async(self) -> tuple: + """ + Internal async helper for fetch operation + + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = await self._version.fetch_async( + return await self._version.fetch_with_response_info_async( method="GET", uri=self._uri, headers=headers ) + async def fetch_async(self) -> AccountInstance: + """ + Asynchronous coroutine to fetch the AccountInstance + + + :returns: The fetched AccountInstance + """ + payload, _, _ = await self._fetch_async() return AccountInstance( self._version, payload, sid=self._solution["sid"], ) + async def fetch_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine to fetch the AccountInstance and return response metadata + + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._fetch_async() + instance = AccountInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + def _update( self, status: "AccountInstance.Status", diff --git a/examples/python/twilio/rest/api/v2010/account/call/__init__.py b/examples/python/twilio/rest/api/v2010/account/call/__init__.py index c43126abc..64b845066 100644 --- a/examples/python/twilio/rest/api/v2010/account/call/__init__.py +++ b/examples/python/twilio/rest/api/v2010/account/call/__init__.py @@ -227,6 +227,20 @@ def __init__(self, version: Version, account_sid: str, test_integer: int): **self._solution ) + def _delete(self) -> tuple: + """ + Internal helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ + + headers = values.of({}) + + return self._version.delete_with_response_info( + method="DELETE", uri=self._uri, headers=headers + ) + def delete(self) -> bool: """ Deletes the CallInstance @@ -234,10 +248,32 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = self._delete() + return success + + def delete_with_http_info(self) -> ApiResponse: + """ + Deletes the CallInstance and return response metadata + + + :returns: ApiResponse with success boolean, status code, and headers + """ + success, status_code, headers = self._delete() + return ApiResponse(data=success, status_code=status_code, headers=headers) + + async def _delete_async(self) -> tuple: + """ + Internal async helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ headers = values.of({}) - return self._version.delete(method="DELETE", uri=self._uri, headers=headers) + return await self._version.delete_with_response_info_async( + method="DELETE", uri=self._uri, headers=headers + ) async def delete_async(self) -> bool: """ @@ -246,27 +282,43 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = await self._delete_async() + return success - headers = values.of({}) + async def delete_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine that deletes the CallInstance and return response metadata - return await self._version.delete_async( - method="DELETE", uri=self._uri, headers=headers - ) - def fetch(self) -> CallInstance: + :returns: ApiResponse with success boolean, status code, and headers """ - Fetch the CallInstance + success, status_code, headers = await self._delete_async() + return ApiResponse(data=success, status_code=status_code, headers=headers) + def _fetch(self) -> tuple: + """ + Internal helper for fetch operation - :returns: The fetched CallInstance + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) + return self._version.fetch_with_response_info( + method="GET", uri=self._uri, headers=headers + ) + + def fetch(self) -> CallInstance: + """ + Fetch the CallInstance + + :returns: The fetched CallInstance + """ + payload, _, _ = self._fetch() return CallInstance( self._version, payload, @@ -274,22 +326,46 @@ def fetch(self) -> CallInstance: test_integer=self._solution["test_integer"], ) - async def fetch_async(self) -> CallInstance: + def fetch_with_http_info(self) -> ApiResponse: """ - Asynchronous coroutine to fetch the CallInstance + Fetch the CallInstance and return response metadata - :returns: The fetched CallInstance + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._fetch() + instance = CallInstance( + self._version, + payload, + account_sid=self._solution["account_sid"], + test_integer=self._solution["test_integer"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _fetch_async(self) -> tuple: + """ + Internal async helper for fetch operation + + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = await self._version.fetch_async( + return await self._version.fetch_with_response_info_async( method="GET", uri=self._uri, headers=headers ) + async def fetch_async(self) -> CallInstance: + """ + Asynchronous coroutine to fetch the CallInstance + + + :returns: The fetched CallInstance + """ + payload, _, _ = await self._fetch_async() return CallInstance( self._version, payload, @@ -297,6 +373,22 @@ async def fetch_async(self) -> CallInstance: test_integer=self._solution["test_integer"], ) + async def fetch_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine to fetch the CallInstance and return response metadata + + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._fetch_async() + instance = CallInstance( + self._version, + payload, + account_sid=self._solution["account_sid"], + test_integer=self._solution["test_integer"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + def __repr__(self) -> str: """ Provide a friendly representation diff --git a/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py b/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py index ffa795126..29004ba8f 100644 --- a/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py +++ b/examples/python/twilio/rest/flex_api/v1/credential/aws/__init__.py @@ -137,6 +137,42 @@ async def fetch_with_http_info_async(self) -> ApiResponse: """ return await self._proxy.fetch_with_http_info_async() + def patch( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> "AwsInstance": + """ + Patch the AwsInstance + + :param test_string: + :param test_boolean: + + :returns: The patched AwsInstance + """ + return self._proxy.patch( + test_string=test_string, + test_boolean=test_boolean, + ) + + async def patch_async( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> "AwsInstance": + """ + Asynchronous coroutine to patch the AwsInstance + + :param test_string: + :param test_boolean: + + :returns: The patched AwsInstance + """ + return await self._proxy.patch_async( + test_string=test_string, + test_boolean=test_boolean, + ) + def update( self, test_string: Union[str, object] = values.unset, @@ -244,6 +280,20 @@ def __init__(self, version: Version, sid: str): self._history: Optional[HistoryList] = None + def _delete(self) -> tuple: + """ + Internal helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ + + headers = values.of({}) + + return self._version.delete_with_response_info( + method="DELETE", uri=self._uri, headers=headers + ) + def delete(self) -> bool: """ Deletes the AwsInstance @@ -251,10 +301,32 @@ def delete(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = self._delete() + return success + + def delete_with_http_info(self) -> ApiResponse: + """ + Deletes the AwsInstance and return response metadata + + + :returns: ApiResponse with success boolean, status code, and headers + """ + success, status_code, headers = self._delete() + return ApiResponse(data=success, status_code=status_code, headers=headers) + + async def _delete_async(self) -> tuple: + """ + Internal async helper for delete operation + + Returns: + tuple: (success_boolean, status_code, headers) + """ headers = values.of({}) - return self._version.delete(method="DELETE", uri=self._uri, headers=headers) + return await self._version.delete_with_response_info_async( + method="DELETE", uri=self._uri, headers=headers + ) async def delete_async(self) -> bool: """ @@ -263,55 +335,237 @@ async def delete_async(self) -> bool: :returns: True if delete succeeds, False otherwise """ + success, _, _ = await self._delete_async() + return success - headers = values.of({}) + async def delete_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine that deletes the AwsInstance and return response metadata - return await self._version.delete_async( - method="DELETE", uri=self._uri, headers=headers - ) - def fetch(self) -> AwsInstance: + :returns: ApiResponse with success boolean, status code, and headers """ - Fetch the AwsInstance + success, status_code, headers = await self._delete_async() + return ApiResponse(data=success, status_code=status_code, headers=headers) + def _fetch(self) -> tuple: + """ + Internal helper for fetch operation - :returns: The fetched AwsInstance + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) + return self._version.fetch_with_response_info( + method="GET", uri=self._uri, headers=headers + ) + def fetch(self) -> AwsInstance: + """ + Fetch the AwsInstance + + + :returns: The fetched AwsInstance + """ + payload, _, _ = self._fetch() return AwsInstance( self._version, payload, sid=self._solution["sid"], ) - async def fetch_async(self) -> AwsInstance: + def fetch_with_http_info(self) -> ApiResponse: """ - Asynchronous coroutine to fetch the AwsInstance + Fetch the AwsInstance and return response metadata - :returns: The fetched AwsInstance + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._fetch() + instance = AwsInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _fetch_async(self) -> tuple: + """ + Internal async helper for fetch operation + + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = await self._version.fetch_async( + return await self._version.fetch_with_response_info_async( method="GET", uri=self._uri, headers=headers ) + async def fetch_async(self) -> AwsInstance: + """ + Asynchronous coroutine to fetch the AwsInstance + + + :returns: The fetched AwsInstance + """ + payload, _, _ = await self._fetch_async() return AwsInstance( self._version, payload, sid=self._solution["sid"], ) + async def fetch_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine to fetch the AwsInstance and return response metadata + + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._fetch_async() + instance = AwsInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + def _patch( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> tuple: + """ + Internal helper for patch operation + + Returns: + tuple: (payload, status_code, headers) + """ + + data = values.of( + { + "TestString": test_string, + "TestBoolean": serialize.boolean_to_string(test_boolean), + } + ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + + return self._version.patch_with_response_info( + method="PATCH", uri=self._uri, data=data, headers=headers + ) + + def patch( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> AwsInstance: + """ + Patch the AwsInstance + + :param test_string: + :param test_boolean: + + :returns: The patched AwsInstance + """ + payload, _, _ = self._patch(test_string=test_string, test_boolean=test_boolean) + return AwsInstance(self._version, payload, sid=self._solution["sid"]) + + def patch_with_http_info( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> ApiResponse: + """ + Patch the AwsInstance and return response metadata + + :param test_string: + :param test_boolean: + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._patch( + test_string=test_string, test_boolean=test_boolean + ) + instance = AwsInstance(self._version, payload, sid=self._solution["sid"]) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _patch_async( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> tuple: + """ + Internal async helper for patch operation + + Returns: + tuple: (payload, status_code, headers) + """ + + data = values.of( + { + "TestString": test_string, + "TestBoolean": serialize.boolean_to_string(test_boolean), + } + ) + headers = values.of({}) + + headers["Content-Type"] = "application/x-www-form-urlencoded" + + headers["Accept"] = "application/json" + + return await self._version.patch_with_response_info_async( + method="PATCH", uri=self._uri, data=data, headers=headers + ) + + async def patch_async( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> AwsInstance: + """ + Asynchronous coroutine to patch the AwsInstance + + :param test_string: + :param test_boolean: + + :returns: The patched AwsInstance + """ + payload, _, _ = await self._patch_async( + test_string=test_string, test_boolean=test_boolean + ) + return AwsInstance(self._version, payload, sid=self._solution["sid"]) + + async def patch_with_http_info_async( + self, + test_string: Union[str, object] = values.unset, + test_boolean: Union[bool, object] = values.unset, + ) -> ApiResponse: + """ + Asynchronous coroutine to patch the AwsInstance and return response metadata + + :param test_string: + :param test_boolean: + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._patch_async( + test_string=test_string, test_boolean=test_boolean + ) + instance = AwsInstance(self._version, payload, sid=self._solution["sid"]) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + def _update( self, test_string: Union[str, object] = values.unset, diff --git a/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py b/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py index 0ebd19997..9118a58fb 100644 --- a/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py +++ b/examples/python/twilio/rest/flex_api/v1/credential/aws/history.py @@ -143,15 +143,14 @@ def __init__(self, version: Version, sid: str): } self._uri = "/Credentials/AWS/{sid}/History".format(**self._solution) - def fetch( + def _fetch( self, add_ons_data: Union[Dict[str, object], object] = values.unset - ) -> HistoryInstance: + ) -> tuple: """ - Fetch the HistoryInstance - - :param add_ons_data: + Internal helper for fetch operation - :returns: The fetched HistoryInstance + Returns: + tuple: (payload, status_code, headers) """ params = values.of({}) @@ -162,25 +161,53 @@ def fetch( headers["Accept"] = "application/json" - payload = self._version.fetch( + return self._version.fetch_with_response_info( method="GET", uri=self._uri, params=params, headers=headers ) + def fetch( + self, add_ons_data: Union[Dict[str, object], object] = values.unset + ) -> HistoryInstance: + """ + Fetch the HistoryInstance + + :param add_ons_data: + + :returns: The fetched HistoryInstance + """ + payload, _, _ = self._fetch(add_ons_data=add_ons_data) return HistoryInstance( self._version, payload, sid=self._solution["sid"], ) - async def fetch_async( + def fetch_with_http_info( self, add_ons_data: Union[Dict[str, object], object] = values.unset - ) -> HistoryInstance: + ) -> ApiResponse: """ - Asynchronous coroutine to fetch the HistoryInstance + Fetch the HistoryInstance and return response metadata :param add_ons_data: - :returns: The fetched HistoryInstance + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._fetch(add_ons_data=add_ons_data) + instance = HistoryInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _fetch_async( + self, add_ons_data: Union[Dict[str, object], object] = values.unset + ) -> tuple: + """ + Internal async helper for fetch operation + + Returns: + tuple: (payload, status_code, headers) """ params = values.of({}) @@ -191,16 +218,47 @@ async def fetch_async( headers["Accept"] = "application/json" - payload = await self._version.fetch_async( + return await self._version.fetch_with_response_info_async( method="GET", uri=self._uri, params=params, headers=headers ) + async def fetch_async( + self, add_ons_data: Union[Dict[str, object], object] = values.unset + ) -> HistoryInstance: + """ + Asynchronous coroutine to fetch the HistoryInstance + + :param add_ons_data: + + :returns: The fetched HistoryInstance + """ + payload, _, _ = await self._fetch_async(add_ons_data=add_ons_data) return HistoryInstance( self._version, payload, sid=self._solution["sid"], ) + async def fetch_with_http_info_async( + self, add_ons_data: Union[Dict[str, object], object] = values.unset + ) -> ApiResponse: + """ + Asynchronous coroutine to fetch the HistoryInstance and return response metadata + + :param add_ons_data: + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._fetch_async( + add_ons_data=add_ons_data + ) + instance = HistoryInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + def __repr__(self) -> str: """ Provide a friendly representation diff --git a/examples/python/twilio/rest/versionless/deployed_devices/fleet.py b/examples/python/twilio/rest/versionless/deployed_devices/fleet.py index 80d0ff025..980a0a81b 100644 --- a/examples/python/twilio/rest/versionless/deployed_devices/fleet.py +++ b/examples/python/twilio/rest/versionless/deployed_devices/fleet.py @@ -135,48 +135,96 @@ def __init__(self, version: Version, sid: str): } self._uri = "/Fleets/{sid}".format(**self._solution) - def fetch(self) -> FleetInstance: + def _fetch(self) -> tuple: """ - Fetch the FleetInstance + Internal helper for fetch operation - - :returns: The fetched FleetInstance + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = self._version.fetch(method="GET", uri=self._uri, headers=headers) + return self._version.fetch_with_response_info( + method="GET", uri=self._uri, headers=headers + ) + + def fetch(self) -> FleetInstance: + """ + Fetch the FleetInstance + + :returns: The fetched FleetInstance + """ + payload, _, _ = self._fetch() return FleetInstance( self._version, payload, sid=self._solution["sid"], ) - async def fetch_async(self) -> FleetInstance: + def fetch_with_http_info(self) -> ApiResponse: """ - Asynchronous coroutine to fetch the FleetInstance + Fetch the FleetInstance and return response metadata - :returns: The fetched FleetInstance + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._fetch() + instance = FleetInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _fetch_async(self) -> tuple: + """ + Internal async helper for fetch operation + + Returns: + tuple: (payload, status_code, headers) """ headers = values.of({}) headers["Accept"] = "application/json" - payload = await self._version.fetch_async( + return await self._version.fetch_with_response_info_async( method="GET", uri=self._uri, headers=headers ) + async def fetch_async(self) -> FleetInstance: + """ + Asynchronous coroutine to fetch the FleetInstance + + + :returns: The fetched FleetInstance + """ + payload, _, _ = await self._fetch_async() return FleetInstance( self._version, payload, sid=self._solution["sid"], ) + async def fetch_with_http_info_async(self) -> ApiResponse: + """ + Asynchronous coroutine to fetch the FleetInstance and return response metadata + + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._fetch_async() + instance = FleetInstance( + self._version, + payload, + sid=self._solution["sid"], + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + def __repr__(self) -> str: """ Provide a friendly representation diff --git a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb index 0143ee76c..2fbd37c19 100644 --- a/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb +++ b/examples/ruby/lib/twilio-ruby/rest/flex_api/v1/credential/aws.rb @@ -220,6 +220,60 @@ def fetch_with_metadata ) end + ## + # Patch the AwsInstance + # @param [String] test_string + # @param [Boolean] test_boolean + # @return [AwsInstance] Patched AwsInstance + def patch( + test_string: :unset, + test_boolean: :unset + ) + data = Twilio::Values.of({ + 'TestString' => test_string, + 'TestBoolean' => test_boolean, + }) + + headers = Twilio::Values.of({ 'Content-Type' => 'application/x-www-form-urlencoded', }) + + payload = @version.patch('PATCH', @uri, data: data, headers: headers) + AwsInstance.new( + @version, + payload, + sid: @solution[:sid], + ) + end + + ## + # Patch the AwsInstanceMetadata + # @param [String] test_string + # @param [Boolean] test_boolean + # @return [AwsInstance] Patchd AwsInstance + def patch_with_metadata( + test_string: :unset, + test_boolean: :unset + ) + data = Twilio::Values.of({ + 'TestString' => test_string, + 'TestBoolean' => test_boolean, + }) + + headers = Twilio::Values.of({ 'Content-Type' => 'application/x-www-form-urlencoded', }) + + response = @version.patch_with_metadata('PATCH', @uri, data: data, headers: headers) + aws_instance = AwsInstance.new( + @version, + response.body, + sid: @solution[:sid], + ) + AwsInstanceMetadata.new( + @version, + aws_instance, + response.headers, + response.status_code + ) + end + ## # Update the AwsInstance # @param [String] test_string @@ -511,6 +565,21 @@ def fetch context.fetch end + ## + # Patch the AwsInstance + # @param [String] test_string + # @param [Boolean] test_boolean + # @return [AwsInstance] Patched AwsInstance + def patch( + test_string: :unset, + test_boolean: :unset + ) + context.patch( + test_string: test_string, + test_boolean: test_boolean, + ) + end + ## # Update the AwsInstance # @param [String] test_string diff --git a/examples/spec/twilio_flex_v1.yaml b/examples/spec/twilio_flex_v1.yaml index 0d182b27a..902bbaff6 100644 --- a/examples/spec/twilio_flex_v1.yaml +++ b/examples/spec/twilio_flex_v1.yaml @@ -282,6 +282,37 @@ paths: description: OK security: - accountSid_authToken: [ ] + patch: + operationId: PatchCredentialAws + parameters: + - in: path + name: Sid + required: true + schema: + maxLength: 34 + minLength: 34 + pattern: ^CR[0-9a-fA-F]{32}$ + type: string + requestBody: + content: + application/x-www-form-urlencoded: + schema: + properties: + TestString: + type: string + TestBoolean: + type: boolean + title: UpdateCredentialAwsRequest + type: object + responses: + '200': + content: + application/json: + schema: + $ref: '#/components/schemas/test.response_object' + description: OK + security: + - accountSid_authToken: [ ] servers: - url: https://flex-api.twilio.com x-twilio: diff --git a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java index 3c05468d5..178935da4 100644 --- a/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/ApiResourceBuilder.java @@ -4,6 +4,7 @@ import com.twilio.oai.PathUtils; import com.twilio.oai.StringHelper; import com.twilio.oai.common.ApplicationConstants; +import com.twilio.oai.common.EnumConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; import com.twilio.oai.resource.Resource; @@ -224,6 +225,8 @@ protected Map mapOperation(CodegenOperation operation) { if (StringUtils.startsWithIgnoreCase(operation.operationId, "update")) { addOperationName(operation, Operation.UPDATE.getValue()); + } else if (StringUtils.startsWithIgnoreCase(operation.operationId, "patch")) { + addOperationName(operation, Operation.PATCH.getValue()); } else if (StringUtils.startsWithIgnoreCase(operation.operationId, "delete")) { addOperationName(operation, Operation.DELETE.getValue()); } else if (StringUtils.startsWithIgnoreCase(operation.operationId, "create")) { diff --git a/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java b/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java index d2b4efac0..650a06cf4 100644 --- a/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java +++ b/src/main/java/com/twilio/oai/api/FluentApiResourceBuilder.java @@ -2,6 +2,7 @@ import com.twilio.oai.DirectoryStructureService; import com.twilio.oai.PathUtils; +import com.twilio.oai.common.EnumConstants; import com.twilio.oai.common.Utility; import com.twilio.oai.resolver.Resolver; import com.twilio.oai.template.IApiActionTemplate; @@ -15,6 +16,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenParameter; diff --git a/src/main/java/com/twilio/oai/common/EnumConstants.java b/src/main/java/com/twilio/oai/common/EnumConstants.java index 606bc9be7..0bb662c2d 100644 --- a/src/main/java/com/twilio/oai/common/EnumConstants.java +++ b/src/main/java/com/twilio/oai/common/EnumConstants.java @@ -29,6 +29,7 @@ public enum Operation { CREATE("Create"), FETCH("Fetch"), UPDATE("Update"), + PATCH("Patch"), DELETE("Delete"), @@ -165,7 +166,8 @@ public enum SupportedOperation { X_LIST("x-list-operation"), X_UPDATE("x-update-operation"), X_FETCH("x-fetch-operation"), - X_DELETE("x-delete-operation"); + X_DELETE("x-delete-operation"), + X_PATCH("x-patch-operation"); private final String value; } diff --git a/src/main/java/com/twilio/oai/java/JavaTemplateUpdater.java b/src/main/java/com/twilio/oai/java/JavaTemplateUpdater.java index 97d618ca5..755dbee68 100644 --- a/src/main/java/com/twilio/oai/java/JavaTemplateUpdater.java +++ b/src/main/java/com/twilio/oai/java/JavaTemplateUpdater.java @@ -2,6 +2,7 @@ import com.twilio.oai.TwilioJavaGeneratorModern; import com.twilio.oai.common.EnumConstants; +import com.twilio.oai.common.EnumConstants.SupportedOperation; import com.twilio.oai.java.constants.MustacheConstants; import org.openapitools.codegen.CodegenOperation; @@ -12,9 +13,9 @@ import static com.twilio.oai.java.constants.MustacheConstants.ActionType; /* -The JavaTemplateFile class is responsible for managing template mappings for Java code generation. -It defines mappings between operation IDs (starting strings) -and corresponding template files (mustache files) along with their generated file extensions. +The JavaTemplateFile class is responsible for managing template mappings for Java code generation. +It defines mappings between operation IDs (starting strings) +and corresponding template files (mustache files) along with their generated file extensions. Example: Key: Represents the starting string of the operationId (e.g., "create", "fetch"). Value: Represents a mapping between the mustache template file and the generated file extension using AbstractMap.SimpleEntry. @@ -34,7 +35,8 @@ public JavaTemplateUpdater() { "fetch", new AbstractMap.SimpleEntry<>("fetcher.mustache", "Fetcher.java"), "delete", new AbstractMap.SimpleEntry<>("deleter.mustache", "Deleter.java"), "list", new AbstractMap.SimpleEntry<>("reader.mustache", "Reader.java"), - "update", new AbstractMap.SimpleEntry<>("updater.mustache", "Updater.java") + "update", new AbstractMap.SimpleEntry<>("updater.mustache", "Updater.java"), + "patch", new AbstractMap.SimpleEntry<>("patcher.mustache", "Patcher.java") ); apiTemplate = Map.of( API_TEMPLATE, new AbstractMap.SimpleEntry<>("api.mustache", ".java") @@ -61,6 +63,8 @@ public void addApiTemplate(TwilioJavaGeneratorModern twilioJavaGenerator, java.u Delete.add(twilioJavaGenerator, operation, apiOperationTemplate); } else if (Fetch.isFetch(operation)) { Fetch.add(twilioJavaGenerator, operation, apiOperationTemplate); + } else if (Patch.isPatch(operation)) { + Patch.add(twilioJavaGenerator, operation, apiOperationTemplate); } else { throw new RuntimeException("Unsupported operation type for operationId: " + operationId); } @@ -149,4 +153,19 @@ public static void add(TwilioJavaGeneratorModern twilioJavaGenerator, CodegenOpe public static boolean isFetch(CodegenOperation codegenOperation) { return codegenOperation.operationId.toLowerCase().startsWith("fetch"); } -} \ No newline at end of file +} + +class Patch { + public static void add(TwilioJavaGeneratorModern twilioJavaGenerator, CodegenOperation codegenOperation, Map apiOperationTemplate) { + codegenOperation.vendorExtensions.put(SupportedOperation.X_PATCH.getValue(), true); + String key = (String) apiOperationTemplate.get("patch").getKey(); + String value = (String) apiOperationTemplate.get("patch").getValue(); + twilioJavaGenerator.apiTemplateFiles().put(key, value); + + codegenOperation.vendorExtensions.put(MustacheConstants.ACTION_TYPE, ActionType.PATCHER.getValue()); + codegenOperation.vendorExtensions.put(MustacheConstants.ACTION_METHOD, ActionMethod.PATCH.getValue()); + } + public static boolean isPatch(CodegenOperation codegenOperation) { + return codegenOperation.operationId.toLowerCase().startsWith("patch"); + } +} diff --git a/src/main/java/com/twilio/oai/java/constants/MustacheConstants.java b/src/main/java/com/twilio/oai/java/constants/MustacheConstants.java index 6dce31699..945b418bd 100644 --- a/src/main/java/com/twilio/oai/java/constants/MustacheConstants.java +++ b/src/main/java/com/twilio/oai/java/constants/MustacheConstants.java @@ -34,7 +34,8 @@ public enum ActionType { READER("Reader"), UPDATER("Updater"), DELETER("Deleter"), - FETCHER("Fetcher"); + FETCHER("Fetcher"), + PATCHER("Patcher"); private final String value; } @@ -47,9 +48,10 @@ public enum ActionMethod { READ("read"), UPDATE("update"), DELETE("delete"), - FETCH("fetch"); + FETCH("fetch"), + PATCH("patch"); private final String value; } - + } diff --git a/src/main/java/com/twilio/oai/template/JavaApiActionTemplate.java b/src/main/java/com/twilio/oai/template/JavaApiActionTemplate.java index dfaab93ba..24d2b59d2 100644 --- a/src/main/java/com/twilio/oai/template/JavaApiActionTemplate.java +++ b/src/main/java/com/twilio/oai/template/JavaApiActionTemplate.java @@ -23,6 +23,8 @@ public Map> mapping() { Arrays.asList("reader.mustache", "Reader.java"), "update", Arrays.asList("updater.mustache", "Updater.java"), + "patch", + Arrays.asList("updater.mustache", "Updater.java"), API_TEMPLATE, Arrays.asList("api.mustache", ".java"), NESTED_MODELS, diff --git a/src/main/resources/twilio-java/common/imports.mustache b/src/main/resources/twilio-java/common/imports.mustache index 93c71be31..72f1f3fc5 100644 --- a/src/main/resources/twilio-java/common/imports.mustache +++ b/src/main/resources/twilio-java/common/imports.mustache @@ -11,6 +11,7 @@ import com.twilio.base.Deleter; import com.twilio.base.Fetcher; import com.twilio.base.Reader; import com.twilio.base.Updater; +import com.twilio.base.Patcher; import com.twilio.base.ResourceSetResponse; import com.twilio.base.TwilioResponse; import com.twilio.constant.EnumConstants; diff --git a/src/main/resources/twilio-java/patcher.mustache b/src/main/resources/twilio-java/patcher.mustache new file mode 100644 index 000000000..822f6179a --- /dev/null +++ b/src/main/resources/twilio-java/patcher.mustache @@ -0,0 +1,28 @@ +{{>licenseInfo}} +{{#resources}} +package com.twilio.rest.{{domainPackage}}.{{apiVersion}}{{namespaceSubPart}}; +{{>common/imports}} + +{{#operations}} +{{#vendorExtensions.x-patch-operation}} + public class {{resourceName}}Patcher extends Patcher<{{resourceName}}> { + {{>common/instanceVariables}} + {{>common/constructors}} + {{>patcher/setters}} + {{>patcher/operationMethod}} + {{#queryParams.0}} + {{>common/addQueryParams}} + {{/queryParams.0}} + {{#formParams.0}} + {{>common/addPostParams}} + {{/formParams.0}} + {{#headerParams.0}} + {{>common/addHeaderParams}} + {{/headerParams.0}} + {{#bodyParams.0}} + {{>common/addPostParamsJson}} + {{/bodyParams.0}} + } +{{/vendorExtensions.x-patch-operation}} +{{/operations}} +{{/resources}} diff --git a/src/main/resources/twilio-java/patcher/operationMethod.mustache b/src/main/resources/twilio-java/patcher/operationMethod.mustache new file mode 100644 index 000000000..4817dded3 --- /dev/null +++ b/src/main/resources/twilio-java/patcher/operationMethod.mustache @@ -0,0 +1,54 @@ +{{! +resourceName: Api Name as identified by Directory Structure service +x-common-action-method: used to define operation method and can have values: create, read, update, delete, fetch, patch + Example: https://github.com/twilio/twilio-java/blob/9c2ba4dbc185c5576e67fbeb82ec6f4899093e79/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java#L309 + +httpMethod: http method associated in the current operation. +domainName: example api, video, chat, etc. These can be found in Domains.java in twilio-java +vendorExtensions.x-content-type: content type of the request, example: application/json, application/x-www-form-urlencoded +}} + @Override + public {{resourceName}} {{vendorExtensions.x-common-action-method}}(final TwilioRestClient client) { + {{>common/generateUri}} + + Request request = new Request( + HttpMethod.{{httpMethod}}, + Domains.{{#lambda.uppercase}}{{domainName}}{{/lambda.uppercase}}.toString(), + path + ); + {{#vendorExtensions.x-request-content-type}} + request.setContentType(EnumConstants.ContentType.{{vendorExtensions.x-request-content-type}}); + {{/vendorExtensions.x-request-content-type}} + {{#vendorExtensions.x-no-auth}} + request.setAuth(NoAuthStrategy.getInstance()); + {{/vendorExtensions.x-no-auth}} + {{#queryParams.0}} + addQueryParams(request); + {{/queryParams.0}} + {{#headerParams.0}} + addHeaderParams(request); + {{/headerParams.0}} + {{#formParams.0}} + addPostParams(request); + {{/formParams.0}} + {{#bodyParams.0}} + addPostParams(request, client); + {{/bodyParams.0}} + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException("{{resourceName}} patch failed: Unable to connect to server"); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + RestException restException = RestException.fromJson( + response.getStream(), + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException("Server Error, no content", response.getStatusCode()); + } + throw new ApiException(restException); + } + + return {{resourceName}}.fromJson(response.getStream(), client.getObjectMapper()); + } diff --git a/src/main/resources/twilio-java/patcher/setters.mustache b/src/main/resources/twilio-java/patcher/setters.mustache new file mode 100644 index 000000000..3fd5bd68a --- /dev/null +++ b/src/main/resources/twilio-java/patcher/setters.mustache @@ -0,0 +1,20 @@ +{{#vendorExtensions.x-setter-methods}} + +public {{resourceName}}Patcher set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{{dataType}}} {{paramName}}){ + this.{{paramName}} = {{paramName}}; + return this; +} + +{{! Optional setter-- Ideally this shouldn't exists, keeping it for backward compatibility }} +{{#isArray}} +public {{resourceName}}Patcher set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final {{{baseType}}} {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(Promoter.listOfOne({{paramName}})); +} +{{/isArray}} +{{! Optional setter, vendorExtensions.x-promotion stores promotion method}} +{{#vendorExtensions.x-promotion}} +public {{resourceName}}Patcher set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}(final String {{paramName}}){ + return set{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{vendorExtensions.x-promotion}}); +} +{{/vendorExtensions.x-promotion}} +{{/vendorExtensions.x-setter-methods}} diff --git a/src/main/resources/twilio-python/context.handlebars b/src/main/resources/twilio-python/context.handlebars index e06fc93c0..0f2b8b8a5 100644 --- a/src/main/resources/twilio-python/context.handlebars +++ b/src/main/resources/twilio-python/context.handlebars @@ -143,14 +143,138 @@ class {{apiName}}Context(InstanceContext): {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} ) return ApiResponse(data=instance, status_code=status_code, headers=headers) - {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-patch-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} + def _{{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (payload, status_code, headers) + """ + {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} + {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} + '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/isFormParam}}{{/allParams}} + }){{/bodyParam}} + headers = values.of({}) + {{#allParams}}{{#isHeaderParam}} + {{^if required}} + if not ({{paramName}} is values.unset or (isinstance({{paramName}}, str) and not {{paramName}})):{{/if}} + headers['{{{baseName}}}'] = {{paramName}}{{/isHeaderParam}}{{/allParams}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}}{{#if queryParams}} + params = values.of({ {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} + '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/if}}{{/isQueryParam}}{{/allParams}} + }) + + {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.patch({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) + {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} + + return self._version.patch_with_response_info(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: """ - Fetch the {{instanceName}} + Patch the {{instanceName}} {{#allParams}} :param {{paramName}}: {{{description}}}{{/allParams}} - :returns: The fetched {{instanceName}} + :returns: The patched {{instanceName}} + """ + payload, _, _ = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + + def {{vendorExtensions.x-name-lower}}_with_http_info(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Patch the {{instanceName}} and return response metadata + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _{{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal async helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (payload, status_code, headers) + """ + {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} + {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} + '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/isFormParam}}{{/allParams}} + }){{/bodyParam}} + headers = values.of({}) + {{#allParams}}{{#isHeaderParam}} + {{^if required}} + if not ({{paramName}} is values.unset or (isinstance({{paramName}}, str) and not {{paramName}})):{{/if}} + headers['{{{baseName}}}'] = {{paramName}} + {{/isHeaderParam}}{{/allParams}} + {{#consumes}} + headers["Content-Type"] = "{{{mediaType}}}" + {{/consumes}} + {{#vendorExtensions.successProduce}} + headers["Accept"] = "{{{mediaType}}}" + {{/vendorExtensions.successProduce}}{{#if queryParams}} + params = values.of({ {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} + '{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/if}}{{/isQueryParam}}{{/allParams}} + }) + + {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.patch({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) + {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} + + return await self._version.patch_with_response_info_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + + async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + """ + Asynchronous coroutine to patch the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: The patched {{instanceName}} + """ + payload, _, _ = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + + async def {{vendorExtensions.x-name-lower}}_with_http_info_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Asynchronous coroutine to patch the {{instanceName}} and return response metadata + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-patch-operation}}{{#vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} + def _{{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (payload, status_code, headers) """ {{#if queryParams}} params = values.of({ {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} @@ -172,8 +296,17 @@ class {{apiName}}Context(InstanceContext): {{#vendorExtensions.successProduce}} headers["Accept"] = "{{{mediaType}}}" {{/vendorExtensions.successProduce}} - payload = self._version.fetch(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if queryParams}}, params=params{{/if}} , headers=headers) + return self._version.fetch_with_response_info(method='{{vendorExtensions.x-http-method}}', uri=self._uri{{#if queryParams}}, params=params{{/if}}, headers=headers) + + def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + """ + Fetch the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + :returns: The fetched {{instanceName}} + """ + payload, _, _ = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) return {{instanceName}}( self._version, payload, @@ -181,13 +314,29 @@ class {{apiName}}Context(InstanceContext): {{/instancePathParams}} ) - async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + def {{vendorExtensions.x-name-lower}}_with_http_info(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: """ - Asynchronous coroutine to fetch the {{instanceName}} + Fetch the {{instanceName}} and return response metadata {{#allParams}} :param {{paramName}}: {{{description}}}{{/allParams}} - :returns: The fetched {{instanceName}} + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload, + {{#instancePathParams}}{{paramName}}=self._solution['{{paramName}}'], + {{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _{{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal async helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (payload, status_code, headers) """ {{#if queryParams}} params = values.of({ {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}{{else}} @@ -209,22 +358,47 @@ class {{apiName}}Context(InstanceContext): {{#vendorExtensions.successProduce}} headers["Accept"] = "{{{mediaType}}}" {{/vendorExtensions.successProduce}} - payload = await self._version.fetch_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri {{#if queryParams}}, params=params{{/if}}, headers=headers) + return await self._version.fetch_with_response_info_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri{{#if queryParams}}, params=params{{/if}}, headers=headers) + async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + """ + Asynchronous coroutine to fetch the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: The fetched {{instanceName}} + """ + payload, _, _ = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) return {{instanceName}}( self._version, payload, {{#instancePathParams}}{{paramName}}=self._solution['{{paramName}}'], {{/instancePathParams}} ) + + async def {{vendorExtensions.x-name-lower}}_with_http_info_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Asynchronous coroutine to fetch the {{instanceName}} and return response metadata + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload, + {{#instancePathParams}}{{paramName}}=self._solution['{{paramName}}'], + {{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-fetch-operation}}{{#vendorExtensions.x-is-delete-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} - def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: + def _{{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: """ - Deletes the {{apiName}}Instance + Internal helper for {{vendorExtensions.x-name-lower}} operation - {{#allParams}}:param {{paramName}}: {{{description}}} - {{/allParams}} - :returns: True if delete succeeds, False otherwise + Returns: + tuple: (success_boolean, status_code, headers) """{{#if headerParams}} headers = values.of({{#allParams}}{{#isHeaderParam}}{'{{{baseName}}}': {{paramName}}, }{{/isHeaderParam}}{{/allParams}}) {{/if}} @@ -244,15 +418,36 @@ class {{apiName}}Context(InstanceContext): {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} - return self._version.delete(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers{{#if queryParams}}, params=params{{/if}}) + return self._version.delete_with_response_info(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers{{#if queryParams}}, params=params{{/if}}) - async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: + def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: """ - Asynchronous coroutine that deletes the {{apiName}}Instance + Deletes the {{apiName}}Instance {{#allParams}}:param {{paramName}}: {{{description}}} {{/allParams}} :returns: True if delete succeeds, False otherwise + """ + success, _, _ = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return success + + def {{vendorExtensions.x-name-lower}}_with_http_info(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Deletes the {{apiName}}Instance and return response metadata + + {{#allParams}}:param {{paramName}}: {{{description}}} + {{/allParams}} + :returns: ApiResponse with success boolean, status code, and headers + """ + success, status_code, headers = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return ApiResponse(data=success, status_code=status_code, headers=headers) + + async def _{{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal async helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (success_boolean, status_code, headers) """{{#if headerParams}} headers = values.of({{#allParams}}{{#isHeaderParam}}{'{{{baseName}}}': {{paramName}}, }{{/isHeaderParam}}{{/allParams}}) {{/if}} @@ -271,15 +466,36 @@ class {{apiName}}Context(InstanceContext): {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} - return await self._version.delete_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers{{#if queryParams}}, params=params{{/if}}) + return await self._version.delete_with_response_info_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, headers=headers{{#if queryParams}}, params=params{{/if}}) + + async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> bool: + """ + Asynchronous coroutine that deletes the {{apiName}}Instance + + {{#allParams}}:param {{paramName}}: {{{description}}} + {{/allParams}} + :returns: True if delete succeeds, False otherwise + """ + success, _, _ = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return success + + async def {{vendorExtensions.x-name-lower}}_with_http_info_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Asynchronous coroutine that deletes the {{apiName}}Instance and return response metadata + + {{#allParams}}:param {{paramName}}: {{{description}}} + {{/allParams}} + :returns: ApiResponse with success boolean, status code, and headers + """ + success, status_code, headers = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + return ApiResponse(data=success, status_code=status_code, headers=headers) {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-delete-operation}}{{#vendorExtensions.x-is-create-operation}}{{^vendorExtensions.x-twilio.ignoreOperation}} - def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + def _{{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: """ - Create the {{instanceName}} - {{#allParams}} - :param {{paramName}}: {{{description}}}{{/allParams}} + Internal helper for {{vendorExtensions.x-name-lower}} operation - :returns: The created {{instanceName}} + Returns: + tuple: (payload, status_code, headers) """ {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} @@ -303,21 +519,45 @@ class {{apiName}}Context(InstanceContext): {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} - payload = self._version.create(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + return self._version.create_with_response_info(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + """ + Create the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: The created {{instanceName}} + """ + payload, _, _ = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) return {{instanceName}}( self._version, payload{{#instancePathParams}}, {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} ) - async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + def {{vendorExtensions.x-name-lower}}_with_http_info(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: """ - Asynchronous coroutine to create the {{instanceName}} + Create the {{instanceName}} and return response metadata {{#allParams}} :param {{paramName}}: {{{description}}}{{/allParams}} - :returns: The created {{instanceName}} + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = self._{{vendorExtensions.x-name-lower}}({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) + + async def _{{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> tuple: + """ + Internal async helper for {{vendorExtensions.x-name-lower}} operation + + Returns: + tuple: (payload, status_code, headers) """ {{#bodyParam}}data = {{paramName}}.to_dict(){{/bodyParam}} {{^bodyParam}}data = values.of({ {{#allParams}}{{#isFormParam}} @@ -341,13 +581,38 @@ class {{apiName}}Context(InstanceContext): {{#allParams}}{{#isQueryParam}}{{#if vendorExtensions.x-prefixed-collapsible-map}}params.update({{vendorExtensions.x-serialize}}({{paramName}}, '{{vendorExtensions.x-prefixed-collapsible-map}}')) {{/if}}{{/isQueryParam}}{{/allParams}}{{/if}} - payload = await self._version.create_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + return await self._version.create_with_response_info_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, data=data, headers=headers{{#if queryParams}}, params=params{{/if}}) + + async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> {{instanceName}}: + """ + Asynchronous coroutine to create the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + :returns: The created {{instanceName}} + """ + payload, _, _ = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) return {{instanceName}}( self._version, payload{{#instancePathParams}}, {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} ) + + async def {{vendorExtensions.x-name-lower}}_with_http_info_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> ApiResponse: + """ + Asynchronous coroutine to create the {{instanceName}} and return response metadata + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: ApiResponse with instance, status code, and headers + """ + payload, status_code, headers = await self._{{vendorExtensions.x-name-lower}}_async({{#allParams}}{{paramName}}={{paramName}}{{#unless @last}}, {{/unless}}{{/allParams}}) + instance = {{instanceName}}( + self._version, + payload{{#instancePathParams}}, + {{paramName}}=self._solution['{{paramName}}']{{/instancePathParams}} + ) + return ApiResponse(data=instance, status_code=status_code, headers=headers) {{/vendorExtensions.x-twilio.ignoreOperation}}{{/vendorExtensions.x-is-create-operation}}{{/vendorExtensions.x-is-context-operation}}{{/operations}} {{#dependents}}{{#instanceDependent}} @property diff --git a/src/main/resources/twilio-python/instance.handlebars b/src/main/resources/twilio-python/instance.handlebars index 1a43e7228..6c013e519 100644 --- a/src/main/resources/twilio-python/instance.handlebars +++ b/src/main/resources/twilio-python/instance.handlebars @@ -69,7 +69,27 @@ class {{instanceName}}(InstanceResource): :returns: ApiResponse with instance, status code, and headers """ return await self._proxy.update_with_http_info_async({{#allParams}}{{paramName}}={{paramName}}, {{/allParams}}) - {{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-fetch-operation}} + {{/vendorExtensions.x-is-update-operation}}{{#vendorExtensions.x-is-patch-operation}} + def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> "{{instanceName}}": + """ + Patch the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: The patched {{instanceName}} + """ + return self._proxy.patch({{#allParams}}{{paramName}}={{paramName}}, {{/allParams}}) + + async def {{vendorExtensions.x-name-lower}}_async(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> "{{instanceName}}": + """ + Asynchronous coroutine to patch the {{instanceName}} + {{#allParams}} + :param {{paramName}}: {{{description}}}{{/allParams}} + + :returns: The patched {{instanceName}} + """ + return await self._proxy.patch_async({{#allParams}}{{paramName}}={{paramName}}, {{/allParams}}) + {{/vendorExtensions.x-is-patch-operation}}{{#vendorExtensions.x-is-fetch-operation}} def {{vendorExtensions.x-name-lower}}(self{{#allParams}}, {{paramName}}: {{#if required}}{{{dataType}}}{{else}}Union[{{{dataType}}}, object]=values.unset{{/if}}{{/allParams}}) -> "{{instanceName}}": """ Fetch the {{instanceName}} diff --git a/src/main/resources/twilio-ruby/methods.mustache b/src/main/resources/twilio-ruby/methods.mustache index a74bd8799..214567ecf 100644 --- a/src/main/resources/twilio-ruby/methods.mustache +++ b/src/main/resources/twilio-ruby/methods.mustache @@ -13,7 +13,7 @@ # @param [{{dataType}}] {{paramName}} {{{description}}} {{/bodyParams}} {{^vendorExtensions.x-is-delete-operation}} - # @return [{{apiName}}Instance] {{#vendorExtensions.x-is-fetch-operation}}{{vendorExtensions.x-name}}ed{{/vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-is-fetch-operation}}{{vendorExtensions.x-name}}d{{/vendorExtensions.x-is-fetch-operation}} {{apiName}}Instance + # @return [{{apiName}}Instance] {{#vendorExtensions.x-is-fetch-operation}}{{vendorExtensions.x-name}}ed{{/vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-is-fetch-operation}}{{^vendorExtensions.x-is-patch-operation}}{{vendorExtensions.x-name}}d{{/vendorExtensions.x-is-patch-operation}}{{#vendorExtensions.x-is-patch-operation}}{{vendorExtensions.x-name}}ed{{/vendorExtensions.x-is-patch-operation}}{{/vendorExtensions.x-is-fetch-operation}} {{apiName}}Instance {{/vendorExtensions.x-is-delete-operation}} {{#vendorExtensions.x-is-delete-operation}} # @return [Boolean] True if delete succeeds, false otherwise