github.com/yaegashi/msgraph.go@v0.1.4/beta/RequestTi.go (about)

     1  // Code generated by msgraph.go/gen DO NOT EDIT.
     2  
     3  package msgraph
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  	"io/ioutil"
     9  	"net/http"
    10  
    11  	"github.com/yaegashi/msgraph.go/jsonx"
    12  )
    13  
    14  // TiIndicatorRequestBuilder is request builder for TiIndicator
    15  type TiIndicatorRequestBuilder struct{ BaseRequestBuilder }
    16  
    17  // Request returns TiIndicatorRequest
    18  func (b *TiIndicatorRequestBuilder) Request() *TiIndicatorRequest {
    19  	return &TiIndicatorRequest{
    20  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
    21  	}
    22  }
    23  
    24  // TiIndicatorRequest is request for TiIndicator
    25  type TiIndicatorRequest struct{ BaseRequest }
    26  
    27  // Get performs GET request for TiIndicator
    28  func (r *TiIndicatorRequest) Get(ctx context.Context) (resObj *TiIndicator, err error) {
    29  	var query string
    30  	if r.query != nil {
    31  		query = "?" + r.query.Encode()
    32  	}
    33  	err = r.JSONRequest(ctx, "GET", query, nil, &resObj)
    34  	return
    35  }
    36  
    37  // Update performs PATCH request for TiIndicator
    38  func (r *TiIndicatorRequest) Update(ctx context.Context, reqObj *TiIndicator) error {
    39  	return r.JSONRequest(ctx, "PATCH", "", reqObj, nil)
    40  }
    41  
    42  // Delete performs DELETE request for TiIndicator
    43  func (r *TiIndicatorRequest) Delete(ctx context.Context) error {
    44  	return r.JSONRequest(ctx, "DELETE", "", nil, nil)
    45  }
    46  
    47  //
    48  type TiIndicatorCollectionSubmitTiIndicatorsRequestBuilder struct{ BaseRequestBuilder }
    49  
    50  // SubmitTiIndicators action undocumented
    51  func (b *SecurityTiIndicatorsCollectionRequestBuilder) SubmitTiIndicators(reqObj *TiIndicatorCollectionSubmitTiIndicatorsRequestParameter) *TiIndicatorCollectionSubmitTiIndicatorsRequestBuilder {
    52  	bb := &TiIndicatorCollectionSubmitTiIndicatorsRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    53  	bb.BaseRequestBuilder.baseURL += "/submitTiIndicators"
    54  	bb.BaseRequestBuilder.requestObject = reqObj
    55  	return bb
    56  }
    57  
    58  //
    59  type TiIndicatorCollectionSubmitTiIndicatorsRequest struct{ BaseRequest }
    60  
    61  //
    62  func (b *TiIndicatorCollectionSubmitTiIndicatorsRequestBuilder) Request() *TiIndicatorCollectionSubmitTiIndicatorsRequest {
    63  	return &TiIndicatorCollectionSubmitTiIndicatorsRequest{
    64  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
    65  	}
    66  }
    67  
    68  //
    69  func (r *TiIndicatorCollectionSubmitTiIndicatorsRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]TiIndicator, error) {
    70  	req, err := r.NewJSONRequest(method, path, obj)
    71  	if err != nil {
    72  		return nil, err
    73  	}
    74  	if ctx != nil {
    75  		req = req.WithContext(ctx)
    76  	}
    77  	res, err := r.client.Do(req)
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  	var values []TiIndicator
    82  	for {
    83  		if res.StatusCode != http.StatusOK {
    84  			b, _ := ioutil.ReadAll(res.Body)
    85  			res.Body.Close()
    86  			errRes := &ErrorResponse{Response: res}
    87  			err := jsonx.Unmarshal(b, errRes)
    88  			if err != nil {
    89  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
    90  			}
    91  			return nil, errRes
    92  		}
    93  		var (
    94  			paging Paging
    95  			value  []TiIndicator
    96  		)
    97  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
    98  		res.Body.Close()
    99  		if err != nil {
   100  			return nil, err
   101  		}
   102  		err = jsonx.Unmarshal(paging.Value, &value)
   103  		if err != nil {
   104  			return nil, err
   105  		}
   106  		values = append(values, value...)
   107  		if n >= 0 {
   108  			n--
   109  		}
   110  		if n == 0 || len(paging.NextLink) == 0 {
   111  			return values, nil
   112  		}
   113  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   114  		if ctx != nil {
   115  			req = req.WithContext(ctx)
   116  		}
   117  		res, err = r.client.Do(req)
   118  		if err != nil {
   119  			return nil, err
   120  		}
   121  	}
   122  }
   123  
   124  //
   125  func (r *TiIndicatorCollectionSubmitTiIndicatorsRequest) PostN(ctx context.Context, n int) ([]TiIndicator, error) {
   126  	return r.Paging(ctx, "POST", "", r.requestObject, n)
   127  }
   128  
   129  //
   130  func (r *TiIndicatorCollectionSubmitTiIndicatorsRequest) Post(ctx context.Context) ([]TiIndicator, error) {
   131  	return r.Paging(ctx, "POST", "", r.requestObject, 0)
   132  }
   133  
   134  //
   135  type TiIndicatorCollectionUpdateTiIndicatorsRequestBuilder struct{ BaseRequestBuilder }
   136  
   137  // UpdateTiIndicators action undocumented
   138  func (b *SecurityTiIndicatorsCollectionRequestBuilder) UpdateTiIndicators(reqObj *TiIndicatorCollectionUpdateTiIndicatorsRequestParameter) *TiIndicatorCollectionUpdateTiIndicatorsRequestBuilder {
   139  	bb := &TiIndicatorCollectionUpdateTiIndicatorsRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   140  	bb.BaseRequestBuilder.baseURL += "/updateTiIndicators"
   141  	bb.BaseRequestBuilder.requestObject = reqObj
   142  	return bb
   143  }
   144  
   145  //
   146  type TiIndicatorCollectionUpdateTiIndicatorsRequest struct{ BaseRequest }
   147  
   148  //
   149  func (b *TiIndicatorCollectionUpdateTiIndicatorsRequestBuilder) Request() *TiIndicatorCollectionUpdateTiIndicatorsRequest {
   150  	return &TiIndicatorCollectionUpdateTiIndicatorsRequest{
   151  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
   152  	}
   153  }
   154  
   155  //
   156  func (r *TiIndicatorCollectionUpdateTiIndicatorsRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]TiIndicator, error) {
   157  	req, err := r.NewJSONRequest(method, path, obj)
   158  	if err != nil {
   159  		return nil, err
   160  	}
   161  	if ctx != nil {
   162  		req = req.WithContext(ctx)
   163  	}
   164  	res, err := r.client.Do(req)
   165  	if err != nil {
   166  		return nil, err
   167  	}
   168  	var values []TiIndicator
   169  	for {
   170  		if res.StatusCode != http.StatusOK {
   171  			b, _ := ioutil.ReadAll(res.Body)
   172  			res.Body.Close()
   173  			errRes := &ErrorResponse{Response: res}
   174  			err := jsonx.Unmarshal(b, errRes)
   175  			if err != nil {
   176  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
   177  			}
   178  			return nil, errRes
   179  		}
   180  		var (
   181  			paging Paging
   182  			value  []TiIndicator
   183  		)
   184  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
   185  		res.Body.Close()
   186  		if err != nil {
   187  			return nil, err
   188  		}
   189  		err = jsonx.Unmarshal(paging.Value, &value)
   190  		if err != nil {
   191  			return nil, err
   192  		}
   193  		values = append(values, value...)
   194  		if n >= 0 {
   195  			n--
   196  		}
   197  		if n == 0 || len(paging.NextLink) == 0 {
   198  			return values, nil
   199  		}
   200  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   201  		if ctx != nil {
   202  			req = req.WithContext(ctx)
   203  		}
   204  		res, err = r.client.Do(req)
   205  		if err != nil {
   206  			return nil, err
   207  		}
   208  	}
   209  }
   210  
   211  //
   212  func (r *TiIndicatorCollectionUpdateTiIndicatorsRequest) PostN(ctx context.Context, n int) ([]TiIndicator, error) {
   213  	return r.Paging(ctx, "POST", "", r.requestObject, n)
   214  }
   215  
   216  //
   217  func (r *TiIndicatorCollectionUpdateTiIndicatorsRequest) Post(ctx context.Context) ([]TiIndicator, error) {
   218  	return r.Paging(ctx, "POST", "", r.requestObject, 0)
   219  }
   220  
   221  //
   222  type TiIndicatorCollectionDeleteTiIndicatorsRequestBuilder struct{ BaseRequestBuilder }
   223  
   224  // DeleteTiIndicators action undocumented
   225  func (b *SecurityTiIndicatorsCollectionRequestBuilder) DeleteTiIndicators(reqObj *TiIndicatorCollectionDeleteTiIndicatorsRequestParameter) *TiIndicatorCollectionDeleteTiIndicatorsRequestBuilder {
   226  	bb := &TiIndicatorCollectionDeleteTiIndicatorsRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   227  	bb.BaseRequestBuilder.baseURL += "/deleteTiIndicators"
   228  	bb.BaseRequestBuilder.requestObject = reqObj
   229  	return bb
   230  }
   231  
   232  //
   233  type TiIndicatorCollectionDeleteTiIndicatorsRequest struct{ BaseRequest }
   234  
   235  //
   236  func (b *TiIndicatorCollectionDeleteTiIndicatorsRequestBuilder) Request() *TiIndicatorCollectionDeleteTiIndicatorsRequest {
   237  	return &TiIndicatorCollectionDeleteTiIndicatorsRequest{
   238  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
   239  	}
   240  }
   241  
   242  //
   243  func (r *TiIndicatorCollectionDeleteTiIndicatorsRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ResultInfo, error) {
   244  	req, err := r.NewJSONRequest(method, path, obj)
   245  	if err != nil {
   246  		return nil, err
   247  	}
   248  	if ctx != nil {
   249  		req = req.WithContext(ctx)
   250  	}
   251  	res, err := r.client.Do(req)
   252  	if err != nil {
   253  		return nil, err
   254  	}
   255  	var values []ResultInfo
   256  	for {
   257  		if res.StatusCode != http.StatusOK {
   258  			b, _ := ioutil.ReadAll(res.Body)
   259  			res.Body.Close()
   260  			errRes := &ErrorResponse{Response: res}
   261  			err := jsonx.Unmarshal(b, errRes)
   262  			if err != nil {
   263  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
   264  			}
   265  			return nil, errRes
   266  		}
   267  		var (
   268  			paging Paging
   269  			value  []ResultInfo
   270  		)
   271  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
   272  		res.Body.Close()
   273  		if err != nil {
   274  			return nil, err
   275  		}
   276  		err = jsonx.Unmarshal(paging.Value, &value)
   277  		if err != nil {
   278  			return nil, err
   279  		}
   280  		values = append(values, value...)
   281  		if n >= 0 {
   282  			n--
   283  		}
   284  		if n == 0 || len(paging.NextLink) == 0 {
   285  			return values, nil
   286  		}
   287  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   288  		if ctx != nil {
   289  			req = req.WithContext(ctx)
   290  		}
   291  		res, err = r.client.Do(req)
   292  		if err != nil {
   293  			return nil, err
   294  		}
   295  	}
   296  }
   297  
   298  //
   299  func (r *TiIndicatorCollectionDeleteTiIndicatorsRequest) PostN(ctx context.Context, n int) ([]ResultInfo, error) {
   300  	return r.Paging(ctx, "POST", "", r.requestObject, n)
   301  }
   302  
   303  //
   304  func (r *TiIndicatorCollectionDeleteTiIndicatorsRequest) Post(ctx context.Context) ([]ResultInfo, error) {
   305  	return r.Paging(ctx, "POST", "", r.requestObject, 0)
   306  }
   307  
   308  //
   309  type TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequestBuilder struct{ BaseRequestBuilder }
   310  
   311  // DeleteTiIndicatorsByExternalID action undocumented
   312  func (b *SecurityTiIndicatorsCollectionRequestBuilder) DeleteTiIndicatorsByExternalID(reqObj *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequestParameter) *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequestBuilder {
   313  	bb := &TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   314  	bb.BaseRequestBuilder.baseURL += "/deleteTiIndicatorsByExternalId"
   315  	bb.BaseRequestBuilder.requestObject = reqObj
   316  	return bb
   317  }
   318  
   319  //
   320  type TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest struct{ BaseRequest }
   321  
   322  //
   323  func (b *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequestBuilder) Request() *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest {
   324  	return &TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest{
   325  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client, requestObject: b.requestObject},
   326  	}
   327  }
   328  
   329  //
   330  func (r *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ResultInfo, error) {
   331  	req, err := r.NewJSONRequest(method, path, obj)
   332  	if err != nil {
   333  		return nil, err
   334  	}
   335  	if ctx != nil {
   336  		req = req.WithContext(ctx)
   337  	}
   338  	res, err := r.client.Do(req)
   339  	if err != nil {
   340  		return nil, err
   341  	}
   342  	var values []ResultInfo
   343  	for {
   344  		if res.StatusCode != http.StatusOK {
   345  			b, _ := ioutil.ReadAll(res.Body)
   346  			res.Body.Close()
   347  			errRes := &ErrorResponse{Response: res}
   348  			err := jsonx.Unmarshal(b, errRes)
   349  			if err != nil {
   350  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
   351  			}
   352  			return nil, errRes
   353  		}
   354  		var (
   355  			paging Paging
   356  			value  []ResultInfo
   357  		)
   358  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
   359  		res.Body.Close()
   360  		if err != nil {
   361  			return nil, err
   362  		}
   363  		err = jsonx.Unmarshal(paging.Value, &value)
   364  		if err != nil {
   365  			return nil, err
   366  		}
   367  		values = append(values, value...)
   368  		if n >= 0 {
   369  			n--
   370  		}
   371  		if n == 0 || len(paging.NextLink) == 0 {
   372  			return values, nil
   373  		}
   374  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   375  		if ctx != nil {
   376  			req = req.WithContext(ctx)
   377  		}
   378  		res, err = r.client.Do(req)
   379  		if err != nil {
   380  			return nil, err
   381  		}
   382  	}
   383  }
   384  
   385  //
   386  func (r *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest) PostN(ctx context.Context, n int) ([]ResultInfo, error) {
   387  	return r.Paging(ctx, "POST", "", r.requestObject, n)
   388  }
   389  
   390  //
   391  func (r *TiIndicatorCollectionDeleteTiIndicatorsByExternalIDRequest) Post(ctx context.Context) ([]ResultInfo, error) {
   392  	return r.Paging(ctx, "POST", "", r.requestObject, 0)
   393  }