github.com/yaegashi/msgraph.go@v0.1.4/beta/ActionConditional.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 // NamedLocations returns request builder for NamedLocation collection 15 func (b *ConditionalAccessRootRequestBuilder) NamedLocations() *ConditionalAccessRootNamedLocationsCollectionRequestBuilder { 16 bb := &ConditionalAccessRootNamedLocationsCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 17 bb.baseURL += "/namedLocations" 18 return bb 19 } 20 21 // ConditionalAccessRootNamedLocationsCollectionRequestBuilder is request builder for NamedLocation collection 22 type ConditionalAccessRootNamedLocationsCollectionRequestBuilder struct{ BaseRequestBuilder } 23 24 // Request returns request for NamedLocation collection 25 func (b *ConditionalAccessRootNamedLocationsCollectionRequestBuilder) Request() *ConditionalAccessRootNamedLocationsCollectionRequest { 26 return &ConditionalAccessRootNamedLocationsCollectionRequest{ 27 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 28 } 29 } 30 31 // ID returns request builder for NamedLocation item 32 func (b *ConditionalAccessRootNamedLocationsCollectionRequestBuilder) ID(id string) *NamedLocationRequestBuilder { 33 bb := &NamedLocationRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 34 bb.baseURL += "/" + id 35 return bb 36 } 37 38 // ConditionalAccessRootNamedLocationsCollectionRequest is request for NamedLocation collection 39 type ConditionalAccessRootNamedLocationsCollectionRequest struct{ BaseRequest } 40 41 // Paging perfoms paging operation for NamedLocation collection 42 func (r *ConditionalAccessRootNamedLocationsCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]NamedLocation, 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 []NamedLocation 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 []NamedLocation 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 NamedLocation collection, max N pages 98 func (r *ConditionalAccessRootNamedLocationsCollectionRequest) GetN(ctx context.Context, n int) ([]NamedLocation, 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 NamedLocation collection 107 func (r *ConditionalAccessRootNamedLocationsCollectionRequest) Get(ctx context.Context) ([]NamedLocation, error) { 108 return r.GetN(ctx, 0) 109 } 110 111 // Add performs POST request for NamedLocation collection 112 func (r *ConditionalAccessRootNamedLocationsCollectionRequest) Add(ctx context.Context, reqObj *NamedLocation) (resObj *NamedLocation, err error) { 113 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 114 return 115 } 116 117 // Policies returns request builder for ConditionalAccessPolicy collection 118 func (b *ConditionalAccessRootRequestBuilder) Policies() *ConditionalAccessRootPoliciesCollectionRequestBuilder { 119 bb := &ConditionalAccessRootPoliciesCollectionRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 120 bb.baseURL += "/policies" 121 return bb 122 } 123 124 // ConditionalAccessRootPoliciesCollectionRequestBuilder is request builder for ConditionalAccessPolicy collection 125 type ConditionalAccessRootPoliciesCollectionRequestBuilder struct{ BaseRequestBuilder } 126 127 // Request returns request for ConditionalAccessPolicy collection 128 func (b *ConditionalAccessRootPoliciesCollectionRequestBuilder) Request() *ConditionalAccessRootPoliciesCollectionRequest { 129 return &ConditionalAccessRootPoliciesCollectionRequest{ 130 BaseRequest: BaseRequest{baseURL: b.baseURL, client: b.client}, 131 } 132 } 133 134 // ID returns request builder for ConditionalAccessPolicy item 135 func (b *ConditionalAccessRootPoliciesCollectionRequestBuilder) ID(id string) *ConditionalAccessPolicyRequestBuilder { 136 bb := &ConditionalAccessPolicyRequestBuilder{BaseRequestBuilder: b.BaseRequestBuilder} 137 bb.baseURL += "/" + id 138 return bb 139 } 140 141 // ConditionalAccessRootPoliciesCollectionRequest is request for ConditionalAccessPolicy collection 142 type ConditionalAccessRootPoliciesCollectionRequest struct{ BaseRequest } 143 144 // Paging perfoms paging operation for ConditionalAccessPolicy collection 145 func (r *ConditionalAccessRootPoliciesCollectionRequest) Paging(ctx context.Context, method, path string, obj interface{}, n int) ([]ConditionalAccessPolicy, 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 []ConditionalAccessPolicy 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 []ConditionalAccessPolicy 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 ConditionalAccessPolicy collection, max N pages 201 func (r *ConditionalAccessRootPoliciesCollectionRequest) GetN(ctx context.Context, n int) ([]ConditionalAccessPolicy, 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 ConditionalAccessPolicy collection 210 func (r *ConditionalAccessRootPoliciesCollectionRequest) Get(ctx context.Context) ([]ConditionalAccessPolicy, error) { 211 return r.GetN(ctx, 0) 212 } 213 214 // Add performs POST request for ConditionalAccessPolicy collection 215 func (r *ConditionalAccessRootPoliciesCollectionRequest) Add(ctx context.Context, reqObj *ConditionalAccessPolicy) (resObj *ConditionalAccessPolicy, err error) { 216 err = r.JSONRequest(ctx, "POST", "", reqObj, &resObj) 217 return 218 }