github.com/yaegashi/msgraph.go@v0.1.4/beta/ActionPublished.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 // AgentGroups returns request builder for OnPremisesAgentGroup collection 15 func (b *PublishedResourceRequestBuilder) AgentGroups() *PublishedResourceAgentGroupsCollectionRequestBuilder { 16 bb := &PublishedResourceAgentGroupsCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 17 bb.baseURL += "/agentGroups" 18 return bb 19 } 20 21 // PublishedResourceAgentGroupsCollectionRequestBuilder is request builder for OnPremisesAgentGroup collection 22 type PublishedResourceAgentGroupsCollectionRequestBuilder struct{ BaseRequestBuilder } 23 24 // Request returns request for OnPremisesAgentGroup collection 25 func (b *PublishedResourceAgentGroupsCollectionRequestBuilder) Request() *PublishedResourceAgentGroupsCollectionRequest { 26 return &PublishedResourceAgentGroupsCollectionRequest{ 27 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 28 } 29 } 30 31 // ID returns request builder for OnPremisesAgentGroup item 32 func (b *PublishedResourceAgentGroupsCollectionRequestBuilder) ID(id string) *OnPremisesAgentGroupRequestBuilder { 33 bb := &OnPremisesAgentGroupRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 34 bb.baseURL += "/" + id 35 return bb 36 } 37 38 // PublishedResourceAgentGroupsCollectionRequest is request for OnPremisesAgentGroup collection 39 type PublishedResourceAgentGroupsCollectionRequest struct{ BaseRequest } 40 41 // Paging perfoms paging operation for OnPremisesAgentGroup collection 42 func (r *PublishedResourceAgentGroupsCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]OnPremisesAgentGroup, 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 []OnPremisesAgentGroup 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 []OnPremisesAgentGroup 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 OnPremisesAgentGroup collection, max N pages 98 func (r *PublishedResourceAgentGroupsCollectionRequest) GetN(ctx context.Context, n int) ([]OnPremisesAgentGroup, 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 OnPremisesAgentGroup collection 107 func (r *PublishedResourceAgentGroupsCollectionRequest) Get(ctx context.Context) ([]OnPremisesAgentGroup, error) { 108 return r.GetN(ctx, 0) 109 } 110 111 // Add performs POST request for OnPremisesAgentGroup collection 112 func (r *PublishedResourceAgentGroupsCollectionRequest) Add(ctx context.Context, reqObj *OnPremisesAgentGroup) (resObj *OnPremisesAgentGroup, err error) { 113 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 114 return 115 }