github.com/yaegashi/msgraph.go@v0.1.4/v1.0/ActionOffice.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 // Shared returns request builder for SharedInsight collection 15 func (b *OfficeGraphInsightsRequestBuilder) Shared() *OfficeGraphInsightsSharedCollectionRequestBuilder { 16 bb := &OfficeGraphInsightsSharedCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 17 bb.baseURL += "/shared" 18 return bb 19 } 20 21 // OfficeGraphInsightsSharedCollectionRequestBuilder is request builder for SharedInsight collection 22 type OfficeGraphInsightsSharedCollectionRequestBuilder struct{ BaseRequestBuilder } 23 24 // Request returns request for SharedInsight collection 25 func (b *OfficeGraphInsightsSharedCollectionRequestBuilder) Request() *OfficeGraphInsightsSharedCollectionRequest { 26 return &OfficeGraphInsightsSharedCollectionRequest{ 27 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 28 } 29 } 30 31 // ID returns request builder for SharedInsight item 32 func (b *OfficeGraphInsightsSharedCollectionRequestBuilder) ID(id string) *SharedInsightRequestBuilder { 33 bb := &SharedInsightRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 34 bb.baseURL += "/" + id 35 return bb 36 } 37 38 // OfficeGraphInsightsSharedCollectionRequest is request for SharedInsight collection 39 type OfficeGraphInsightsSharedCollectionRequest struct{ BaseRequest } 40 41 // Paging perfoms paging operation for SharedInsight collection 42 func (r *OfficeGraphInsightsSharedCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]SharedInsight, error) { 43 req, err := r.NewJSONRequest(method, path, obj) 44 if err != nil { 45 return nil, err 46 } 47 if ctx != nil { 48 req = req.WithContext(ctx) 49 } 50 res, err := r.client.Do(req) 51 if err != nil { 52 return nil, err 53 } 54 var values []SharedInsight 55 for { 56 if res.StatusCode != http.StatusOK { 57 b, _ := ioutil.ReadAll(res.Body) 58 res.Body.Close() 59 errRes := &ErrorResponse{Response: res} 60 err := jsonx.Unmarshal(b, errRes) 61 if err != nil { 62 return nil, fmt.Errorf("%s: %s", res.Status, string(b)) 63 } 64 return nil, errRes 65 } 66 var ( 67 paging Paging 68 value []SharedInsight 69 ) 70 err := jsonx.NewDecoder(res.Body).Decode(&paging) 71 res.Body.Close() 72 if err != nil { 73 return nil, err 74 } 75 err = jsonx.Unmarshal(paging.Value, &value) 76 if err != nil { 77 return nil, err 78 } 79 values = append(values, value...) 80 if n >= 0 { 81 n-- 82 } 83 if n == 0 || len(paging.NextLink) == 0 { 84 return values, nil 85 } 86 req, err = http.NewRequest("GET", paging.NextLink, nil) 87 if ctx != nil { 88 req = req.WithContext(ctx) 89 } 90 res, err = r.client.Do(req) 91 if err != nil { 92 return nil, err 93 } 94 } 95 } 96 97 // GetN performs GET request for SharedInsight collection, max N pages 98 func (r *OfficeGraphInsightsSharedCollectionRequest) GetN(ctx context.Context, n int) ([]SharedInsight, error) { 99 var query string 100 if r.query != nil { 101 query = "?" + r.query.Encode() 102 } 103 return r.Paging(ctx, "GET", query, nil, n) 104 } 105 106 // Get performs GET request for SharedInsight collection 107 func (r *OfficeGraphInsightsSharedCollectionRequest) Get(ctx context.Context) ([]SharedInsight, error) { 108 return r.GetN(ctx, 0) 109 } 110 111 // Add performs POST request for SharedInsight collection 112 func (r *OfficeGraphInsightsSharedCollectionRequest) Add(ctx context.Context, reqObj *SharedInsight) (resObj *SharedInsight, err error) { 113 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 114 return 115 } 116 117 // Trending returns request builder for Trending collection 118 func (b *OfficeGraphInsightsRequestBuilder) Trending() *OfficeGraphInsightsTrendingCollectionRequestBuilder { 119 bb := &OfficeGraphInsightsTrendingCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 120 bb.baseURL += "/trending" 121 return bb 122 } 123 124 // OfficeGraphInsightsTrendingCollectionRequestBuilder is request builder for Trending collection 125 type OfficeGraphInsightsTrendingCollectionRequestBuilder struct{ BaseRequestBuilder } 126 127 // Request returns request for Trending collection 128 func (b *OfficeGraphInsightsTrendingCollectionRequestBuilder) Request() *OfficeGraphInsightsTrendingCollectionRequest { 129 return &OfficeGraphInsightsTrendingCollectionRequest{ 130 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 131 } 132 } 133 134 // ID returns request builder for Trending item 135 func (b *OfficeGraphInsightsTrendingCollectionRequestBuilder) ID(id string) *TrendingRequestBuilder { 136 bb := &TrendingRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 137 bb.baseURL += "/" + id 138 return bb 139 } 140 141 // OfficeGraphInsightsTrendingCollectionRequest is request for Trending collection 142 type OfficeGraphInsightsTrendingCollectionRequest struct{ BaseRequest } 143 144 // Paging perfoms paging operation for Trending collection 145 func (r *OfficeGraphInsightsTrendingCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]Trending, error) { 146 req, err := r.NewJSONRequest(method, path, obj) 147 if err != nil { 148 return nil, err 149 } 150 if ctx != nil { 151 req = req.WithContext(ctx) 152 } 153 res, err := r.client.Do(req) 154 if err != nil { 155 return nil, err 156 } 157 var values []Trending 158 for { 159 if res.StatusCode != http.StatusOK { 160 b, _ := ioutil.ReadAll(res.Body) 161 res.Body.Close() 162 errRes := &ErrorResponse{Response: res} 163 err := jsonx.Unmarshal(b, errRes) 164 if err != nil { 165 return nil, fmt.Errorf("%s: %s", res.Status, string(b)) 166 } 167 return nil, errRes 168 } 169 var ( 170 paging Paging 171 value []Trending 172 ) 173 err := jsonx.NewDecoder(res.Body).Decode(&paging) 174 res.Body.Close() 175 if err != nil { 176 return nil, err 177 } 178 err = jsonx.Unmarshal(paging.Value, &value) 179 if err != nil { 180 return nil, err 181 } 182 values = append(values, value...) 183 if n >= 0 { 184 n-- 185 } 186 if n == 0 || len(paging.NextLink) == 0 { 187 return values, nil 188 } 189 req, err = http.NewRequest("GET", paging.NextLink, nil) 190 if ctx != nil { 191 req = req.WithContext(ctx) 192 } 193 res, err = r.client.Do(req) 194 if err != nil { 195 return nil, err 196 } 197 } 198 } 199 200 // GetN performs GET request for Trending collection, max N pages 201 func (r *OfficeGraphInsightsTrendingCollectionRequest) GetN(ctx context.Context, n int) ([]Trending, error) { 202 var query string 203 if r.query != nil { 204 query = "?" + r.query.Encode() 205 } 206 return r.Paging(ctx, "GET", query, nil, n) 207 } 208 209 // Get performs GET request for Trending collection 210 func (r *OfficeGraphInsightsTrendingCollectionRequest) Get(ctx context.Context) ([]Trending, error) { 211 return r.GetN(ctx, 0) 212 } 213 214 // Add performs POST request for Trending collection 215 func (r *OfficeGraphInsightsTrendingCollectionRequest) Add(ctx context.Context, reqObj *Trending) (resObj *Trending, err error) { 216 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 217 return 218 } 219 220 // Used returns request builder for UsedInsight collection 221 func (b *OfficeGraphInsightsRequestBuilder) Used() *OfficeGraphInsightsUsedCollectionRequestBuilder { 222 bb := &OfficeGraphInsightsUsedCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 223 bb.baseURL += "/used" 224 return bb 225 } 226 227 // OfficeGraphInsightsUsedCollectionRequestBuilder is request builder for UsedInsight collection 228 type OfficeGraphInsightsUsedCollectionRequestBuilder struct{ BaseRequestBuilder } 229 230 // Request returns request for UsedInsight collection 231 func (b *OfficeGraphInsightsUsedCollectionRequestBuilder) Request() *OfficeGraphInsightsUsedCollectionRequest { 232 return &OfficeGraphInsightsUsedCollectionRequest{ 233 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 234 } 235 } 236 237 // ID returns request builder for UsedInsight item 238 func (b *OfficeGraphInsightsUsedCollectionRequestBuilder) ID(id string) *UsedInsightRequestBuilder { 239 bb := &UsedInsightRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 240 bb.baseURL += "/" + id 241 return bb 242 } 243 244 // OfficeGraphInsightsUsedCollectionRequest is request for UsedInsight collection 245 type OfficeGraphInsightsUsedCollectionRequest struct{ BaseRequest } 246 247 // Paging perfoms paging operation for UsedInsight collection 248 func (r *OfficeGraphInsightsUsedCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]UsedInsight, error) { 249 req, err := r.NewJSONRequest(method, path, obj) 250 if err != nil { 251 return nil, err 252 } 253 if ctx != nil { 254 req = req.WithContext(ctx) 255 } 256 res, err := r.client.Do(req) 257 if err != nil { 258 return nil, err 259 } 260 var values []UsedInsight 261 for { 262 if res.StatusCode != http.StatusOK { 263 b, _ := ioutil.ReadAll(res.Body) 264 res.Body.Close() 265 errRes := &ErrorResponse{Response: res} 266 err := jsonx.Unmarshal(b, errRes) 267 if err != nil { 268 return nil, fmt.Errorf("%s: %s", res.Status, string(b)) 269 } 270 return nil, errRes 271 } 272 var ( 273 paging Paging 274 value []UsedInsight 275 ) 276 err := jsonx.NewDecoder(res.Body).Decode(&paging) 277 res.Body.Close() 278 if err != nil { 279 return nil, err 280 } 281 err = jsonx.Unmarshal(paging.Value, &value) 282 if err != nil { 283 return nil, err 284 } 285 values = append(values, value...) 286 if n >= 0 { 287 n-- 288 } 289 if n == 0 || len(paging.NextLink) == 0 { 290 return values, nil 291 } 292 req, err = http.NewRequest("GET", paging.NextLink, nil) 293 if ctx != nil { 294 req = req.WithContext(ctx) 295 } 296 res, err = r.client.Do(req) 297 if err != nil { 298 return nil, err 299 } 300 } 301 } 302 303 // GetN performs GET request for UsedInsight collection, max N pages 304 func (r *OfficeGraphInsightsUsedCollectionRequest) GetN(ctx context.Context, n int) ([]UsedInsight, error) { 305 var query string 306 if r.query != nil { 307 query = "?" + r.query.Encode() 308 } 309 return r.Paging(ctx, "GET", query, nil, n) 310 } 311 312 // Get performs GET request for UsedInsight collection 313 func (r *OfficeGraphInsightsUsedCollectionRequest) Get(ctx context.Context) ([]UsedInsight, error) { 314 return r.GetN(ctx, 0) 315 } 316 317 // Add performs POST request for UsedInsight collection 318 func (r *OfficeGraphInsightsUsedCollectionRequest) Add(ctx context.Context, reqObj *UsedInsight) (resObj *UsedInsight, err error) { 319 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 320 return 321 }