github.com/yaegashi/msgraph.go@v0.1.4/beta/ActionCustomer.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  // Currency is navigation property
    15  func (b *CustomerRequestBuilder) Currency() *CurrencyRequestBuilder {
    16  	bb := &CurrencyRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    17  	bb.baseURL += "/currency"
    18  	return bb
    19  }
    20  
    21  // PaymentMethod is navigation property
    22  func (b *CustomerRequestBuilder) PaymentMethod() *PaymentMethodRequestBuilder {
    23  	bb := &PaymentMethodRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    24  	bb.baseURL += "/paymentMethod"
    25  	return bb
    26  }
    27  
    28  // PaymentTerm is navigation property
    29  func (b *CustomerRequestBuilder) PaymentTerm() *PaymentTermRequestBuilder {
    30  	bb := &PaymentTermRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    31  	bb.baseURL += "/paymentTerm"
    32  	return bb
    33  }
    34  
    35  // Picture returns request builder for Picture collection
    36  func (b *CustomerRequestBuilder) Picture() *CustomerPictureCollectionRequestBuilder {
    37  	bb := &CustomerPictureCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    38  	bb.baseURL += "/picture"
    39  	return bb
    40  }
    41  
    42  // CustomerPictureCollectionRequestBuilder is request builder for Picture collection
    43  type CustomerPictureCollectionRequestBuilder struct{ BaseRequestBuilder }
    44  
    45  // Request returns request for Picture collection
    46  func (b *CustomerPictureCollectionRequestBuilder) Request() *CustomerPictureCollectionRequest {
    47  	return &CustomerPictureCollectionRequest{
    48  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
    49  	}
    50  }
    51  
    52  // ID returns request builder for Picture item
    53  func (b *CustomerPictureCollectionRequestBuilder) ID(id string) *PictureRequestBuilder {
    54  	bb := &PictureRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    55  	bb.baseURL += "/" + id
    56  	return bb
    57  }
    58  
    59  // CustomerPictureCollectionRequest is request for Picture collection
    60  type CustomerPictureCollectionRequest struct{ BaseRequest }
    61  
    62  // Paging perfoms paging operation for Picture collection
    63  func (r *CustomerPictureCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]Picture, error) {
    64  	req, err := r.NewJSONRequest(method, path, obj)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  	if ctx != nil {
    69  		req = req.WithContext(ctx)
    70  	}
    71  	res, err := r.client.Do(req)
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  	var values []Picture
    76  	for {
    77  		if res.StatusCode != http.StatusOK {
    78  			b, _ := ioutil.ReadAll(res.Body)
    79  			res.Body.Close()
    80  			errRes := &ErrorResponse{Response: res}
    81  			err := jsonx.Unmarshal(b, errRes)
    82  			if err != nil {
    83  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
    84  			}
    85  			return nil, errRes
    86  		}
    87  		var (
    88  			paging Paging
    89  			value  []Picture
    90  		)
    91  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
    92  		res.Body.Close()
    93  		if err != nil {
    94  			return nil, err
    95  		}
    96  		err = jsonx.Unmarshal(paging.Value, &value)
    97  		if err != nil {
    98  			return nil, err
    99  		}
   100  		values = append(values, value...)
   101  		if n >= 0 {
   102  			n--
   103  		}
   104  		if n == 0 || len(paging.NextLink) == 0 {
   105  			return values, nil
   106  		}
   107  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   108  		if ctx != nil {
   109  			req = req.WithContext(ctx)
   110  		}
   111  		res, err = r.client.Do(req)
   112  		if err != nil {
   113  			return nil, err
   114  		}
   115  	}
   116  }
   117  
   118  // GetN performs GET request for Picture collection, max N pages
   119  func (r *CustomerPictureCollectionRequest) GetN(ctx context.Context, n int) ([]Picture, error) {
   120  	var query string
   121  	if r.query != nil {
   122  		query = "?" + r.query.Encode()
   123  	}
   124  	return r.Paging(ctx, "GET", query, nil, n)
   125  }
   126  
   127  // Get performs GET request for Picture collection
   128  func (r *CustomerPictureCollectionRequest) Get(ctx context.Context) ([]Picture, error) {
   129  	return r.GetN(ctx, 0)
   130  }
   131  
   132  // Add performs POST request for Picture collection
   133  func (r *CustomerPictureCollectionRequest) Add(ctx context.Context, reqObj *Picture) (resObj *Picture, err error) {
   134  	err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj)
   135  	return
   136  }
   137  
   138  // ShipmentMethod is navigation property
   139  func (b *CustomerRequestBuilder) ShipmentMethod() *ShipmentMethodRequestBuilder {
   140  	bb := &ShipmentMethodRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   141  	bb.baseURL += "/shipmentMethod"
   142  	return bb
   143  }
   144  
   145  // Customer is navigation property
   146  func (b *CustomerPaymentRequestBuilder) Customer() *CustomerRequestBuilder {
   147  	bb := &CustomerRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   148  	bb.baseURL += "/customer"
   149  	return bb
   150  }
   151  
   152  // Account is navigation property
   153  func (b *CustomerPaymentJournalRequestBuilder) Account() *AccountRequestBuilder {
   154  	bb := &AccountRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   155  	bb.baseURL += "/account"
   156  	return bb
   157  }
   158  
   159  // CustomerPayments returns request builder for CustomerPayment collection
   160  func (b *CustomerPaymentJournalRequestBuilder) CustomerPayments() *CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder {
   161  	bb := &CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   162  	bb.baseURL += "/customerPayments"
   163  	return bb
   164  }
   165  
   166  // CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder is request builder for CustomerPayment collection
   167  type CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder struct{ BaseRequestBuilder }
   168  
   169  // Request returns request for CustomerPayment collection
   170  func (b *CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder) Request() *CustomerPaymentJournalCustomerPaymentsCollectionRequest {
   171  	return &CustomerPaymentJournalCustomerPaymentsCollectionRequest{
   172  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
   173  	}
   174  }
   175  
   176  // ID returns request builder for CustomerPayment item
   177  func (b *CustomerPaymentJournalCustomerPaymentsCollectionRequestBuilder) ID(id string) *CustomerPaymentRequestBuilder {
   178  	bb := &CustomerPaymentRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   179  	bb.baseURL += "/" + id
   180  	return bb
   181  }
   182  
   183  // CustomerPaymentJournalCustomerPaymentsCollectionRequest is request for CustomerPayment collection
   184  type CustomerPaymentJournalCustomerPaymentsCollectionRequest struct{ BaseRequest }
   185  
   186  // Paging perfoms paging operation for CustomerPayment collection
   187  func (r *CustomerPaymentJournalCustomerPaymentsCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]CustomerPayment, error) {
   188  	req, err := r.NewJSONRequest(method, path, obj)
   189  	if err != nil {
   190  		return nil, err
   191  	}
   192  	if ctx != nil {
   193  		req = req.WithContext(ctx)
   194  	}
   195  	res, err := r.client.Do(req)
   196  	if err != nil {
   197  		return nil, err
   198  	}
   199  	var values []CustomerPayment
   200  	for {
   201  		if res.StatusCode != http.StatusOK {
   202  			b, _ := ioutil.ReadAll(res.Body)
   203  			res.Body.Close()
   204  			errRes := &ErrorResponse{Response: res}
   205  			err := jsonx.Unmarshal(b, errRes)
   206  			if err != nil {
   207  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
   208  			}
   209  			return nil, errRes
   210  		}
   211  		var (
   212  			paging Paging
   213  			value  []CustomerPayment
   214  		)
   215  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
   216  		res.Body.Close()
   217  		if err != nil {
   218  			return nil, err
   219  		}
   220  		err = jsonx.Unmarshal(paging.Value, &value)
   221  		if err != nil {
   222  			return nil, err
   223  		}
   224  		values = append(values, value...)
   225  		if n >= 0 {
   226  			n--
   227  		}
   228  		if n == 0 || len(paging.NextLink) == 0 {
   229  			return values, nil
   230  		}
   231  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   232  		if ctx != nil {
   233  			req = req.WithContext(ctx)
   234  		}
   235  		res, err = r.client.Do(req)
   236  		if err != nil {
   237  			return nil, err
   238  		}
   239  	}
   240  }
   241  
   242  // GetN performs GET request for CustomerPayment collection, max N pages
   243  func (r *CustomerPaymentJournalCustomerPaymentsCollectionRequest) GetN(ctx context.Context, n int) ([]CustomerPayment, error) {
   244  	var query string
   245  	if r.query != nil {
   246  		query = "?" + r.query.Encode()
   247  	}
   248  	return r.Paging(ctx, "GET", query, nil, n)
   249  }
   250  
   251  // Get performs GET request for CustomerPayment collection
   252  func (r *CustomerPaymentJournalCustomerPaymentsCollectionRequest) Get(ctx context.Context) ([]CustomerPayment, error) {
   253  	return r.GetN(ctx, 0)
   254  }
   255  
   256  // Add performs POST request for CustomerPayment collection
   257  func (r *CustomerPaymentJournalCustomerPaymentsCollectionRequest) Add(ctx context.Context, reqObj *CustomerPayment) (resObj *CustomerPayment, err error) {
   258  	err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj)
   259  	return
   260  }