github.com/yaegashi/msgraph.go@v0.1.4/beta/ActionNotebook.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  // NotebookCollectionGetNotebookFromWebURLRequestParameter undocumented
    15  type NotebookCollectionGetNotebookFromWebURLRequestParameter struct {
    16  	// WebURL undocumented
    17  	WebURL *string `json:"webUrl,omitempty"`
    18  }
    19  
    20  // NotebookCopyNotebookRequestParameter undocumented
    21  type NotebookCopyNotebookRequestParameter struct {
    22  	// GroupID undocumented
    23  	GroupID *string `json:"groupId,omitempty"`
    24  	// RenameAs undocumented
    25  	RenameAs *string `json:"renameAs,omitempty"`
    26  	// NotebookFolder undocumented
    27  	NotebookFolder *string `json:"notebookFolder,omitempty"`
    28  	// SiteCollectionID undocumented
    29  	SiteCollectionID *string `json:"siteCollectionId,omitempty"`
    30  	// SiteID undocumented
    31  	SiteID *string `json:"siteId,omitempty"`
    32  }
    33  
    34  // SectionGroups returns request builder for SectionGroup collection
    35  func (b *NotebookRequestBuilder) SectionGroups() *NotebookSectionGroupsCollectionRequestBuilder {
    36  	bb := &NotebookSectionGroupsCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    37  	bb.baseURL += "/sectionGroups"
    38  	return bb
    39  }
    40  
    41  // NotebookSectionGroupsCollectionRequestBuilder is request builder for SectionGroup collection
    42  type NotebookSectionGroupsCollectionRequestBuilder struct{ BaseRequestBuilder }
    43  
    44  // Request returns request for SectionGroup collection
    45  func (b *NotebookSectionGroupsCollectionRequestBuilder) Request() *NotebookSectionGroupsCollectionRequest {
    46  	return &NotebookSectionGroupsCollectionRequest{
    47  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
    48  	}
    49  }
    50  
    51  // ID returns request builder for SectionGroup item
    52  func (b *NotebookSectionGroupsCollectionRequestBuilder) ID(id string) *SectionGroupRequestBuilder {
    53  	bb := &SectionGroupRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
    54  	bb.baseURL += "/" + id
    55  	return bb
    56  }
    57  
    58  // NotebookSectionGroupsCollectionRequest is request for SectionGroup collection
    59  type NotebookSectionGroupsCollectionRequest struct{ BaseRequest }
    60  
    61  // Paging perfoms paging operation for SectionGroup collection
    62  func (r *NotebookSectionGroupsCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]SectionGroup, error) {
    63  	req, err := r.NewJSONRequest(method, path, obj)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  	if ctx != nil {
    68  		req = req.WithContext(ctx)
    69  	}
    70  	res, err := r.client.Do(req)
    71  	if err != nil {
    72  		return nil, err
    73  	}
    74  	var values []SectionGroup
    75  	for {
    76  		if res.StatusCode != http.StatusOK {
    77  			b, _ := ioutil.ReadAll(res.Body)
    78  			res.Body.Close()
    79  			errRes := &ErrorResponse{Response: res}
    80  			err := jsonx.Unmarshal(b, errRes)
    81  			if err != nil {
    82  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
    83  			}
    84  			return nil, errRes
    85  		}
    86  		var (
    87  			paging Paging
    88  			value  []SectionGroup
    89  		)
    90  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
    91  		res.Body.Close()
    92  		if err != nil {
    93  			return nil, err
    94  		}
    95  		err = jsonx.Unmarshal(paging.Value, &value)
    96  		if err != nil {
    97  			return nil, err
    98  		}
    99  		values = append(values, value...)
   100  		if n >= 0 {
   101  			n--
   102  		}
   103  		if n == 0 || len(paging.NextLink) == 0 {
   104  			return values, nil
   105  		}
   106  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   107  		if ctx != nil {
   108  			req = req.WithContext(ctx)
   109  		}
   110  		res, err = r.client.Do(req)
   111  		if err != nil {
   112  			return nil, err
   113  		}
   114  	}
   115  }
   116  
   117  // GetN performs GET request for SectionGroup collection, max N pages
   118  func (r *NotebookSectionGroupsCollectionRequest) GetN(ctx context.Context, n int) ([]SectionGroup, error) {
   119  	var query string
   120  	if r.query != nil {
   121  		query = "?" + r.query.Encode()
   122  	}
   123  	return r.Paging(ctx, "GET", query, nil, n)
   124  }
   125  
   126  // Get performs GET request for SectionGroup collection
   127  func (r *NotebookSectionGroupsCollectionRequest) Get(ctx context.Context) ([]SectionGroup, error) {
   128  	return r.GetN(ctx, 0)
   129  }
   130  
   131  // Add performs POST request for SectionGroup collection
   132  func (r *NotebookSectionGroupsCollectionRequest) Add(ctx context.Context, reqObj *SectionGroup) (resObj *SectionGroup, err error) {
   133  	err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj)
   134  	return
   135  }
   136  
   137  // Sections returns request builder for OnenoteSection collection
   138  func (b *NotebookRequestBuilder) Sections() *NotebookSectionsCollectionRequestBuilder {
   139  	bb := &NotebookSectionsCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   140  	bb.baseURL += "/sections"
   141  	return bb
   142  }
   143  
   144  // NotebookSectionsCollectionRequestBuilder is request builder for OnenoteSection collection
   145  type NotebookSectionsCollectionRequestBuilder struct{ BaseRequestBuilder }
   146  
   147  // Request returns request for OnenoteSection collection
   148  func (b *NotebookSectionsCollectionRequestBuilder) Request() *NotebookSectionsCollectionRequest {
   149  	return &NotebookSectionsCollectionRequest{
   150  		BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client},
   151  	}
   152  }
   153  
   154  // ID returns request builder for OnenoteSection item
   155  func (b *NotebookSectionsCollectionRequestBuilder) ID(id string) *OnenoteSectionRequestBuilder {
   156  	bb := &OnenoteSectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder}
   157  	bb.baseURL += "/" + id
   158  	return bb
   159  }
   160  
   161  // NotebookSectionsCollectionRequest is request for OnenoteSection collection
   162  type NotebookSectionsCollectionRequest struct{ BaseRequest }
   163  
   164  // Paging perfoms paging operation for OnenoteSection collection
   165  func (r *NotebookSectionsCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]OnenoteSection, error) {
   166  	req, err := r.NewJSONRequest(method, path, obj)
   167  	if err != nil {
   168  		return nil, err
   169  	}
   170  	if ctx != nil {
   171  		req = req.WithContext(ctx)
   172  	}
   173  	res, err := r.client.Do(req)
   174  	if err != nil {
   175  		return nil, err
   176  	}
   177  	var values []OnenoteSection
   178  	for {
   179  		if res.StatusCode != http.StatusOK {
   180  			b, _ := ioutil.ReadAll(res.Body)
   181  			res.Body.Close()
   182  			errRes := &ErrorResponse{Response: res}
   183  			err := jsonx.Unmarshal(b, errRes)
   184  			if err != nil {
   185  				return nil, fmt.Errorf("%s: %s", res.Status, string(b))
   186  			}
   187  			return nil, errRes
   188  		}
   189  		var (
   190  			paging Paging
   191  			value  []OnenoteSection
   192  		)
   193  		err := jsonx.NewDecoder(res.Body).Decode(&paging)
   194  		res.Body.Close()
   195  		if err != nil {
   196  			return nil, err
   197  		}
   198  		err = jsonx.Unmarshal(paging.Value, &value)
   199  		if err != nil {
   200  			return nil, err
   201  		}
   202  		values = append(values, value...)
   203  		if n >= 0 {
   204  			n--
   205  		}
   206  		if n == 0 || len(paging.NextLink) == 0 {
   207  			return values, nil
   208  		}
   209  		req, err = http.NewRequest("GET", paging.NextLink, nil)
   210  		if ctx != nil {
   211  			req = req.WithContext(ctx)
   212  		}
   213  		res, err = r.client.Do(req)
   214  		if err != nil {
   215  			return nil, err
   216  		}
   217  	}
   218  }
   219  
   220  // GetN performs GET request for OnenoteSection collection, max N pages
   221  func (r *NotebookSectionsCollectionRequest) GetN(ctx context.Context, n int) ([]OnenoteSection, error) {
   222  	var query string
   223  	if r.query != nil {
   224  		query = "?" + r.query.Encode()
   225  	}
   226  	return r.Paging(ctx, "GET", query, nil, n)
   227  }
   228  
   229  // Get performs GET request for OnenoteSection collection
   230  func (r *NotebookSectionsCollectionRequest) Get(ctx context.Context) ([]OnenoteSection, error) {
   231  	return r.GetN(ctx, 0)
   232  }
   233  
   234  // Add performs POST request for OnenoteSection collection
   235  func (r *NotebookSectionsCollectionRequest) Add(ctx context.Context, reqObj *OnenoteSection) (resObj *OnenoteSection, err error) {
   236  	err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj)
   237  	return
   238  }