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