|
| 1 | +# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import logging |
| 6 | +from dataclasses import dataclass |
| 7 | +from typing import Any, Dict, List, Optional |
| 8 | + |
| 9 | +_LOG = logging.getLogger("databricks.sdk") |
| 10 | + |
| 11 | + |
| 12 | +# all definitions in this file are in alphabetical order |
| 13 | + |
| 14 | + |
| 15 | +@dataclass |
| 16 | +class ComplexQueryParam: |
| 17 | + nested_optional_query_param: Optional[str] = None |
| 18 | + |
| 19 | + nested_repeated_query_param: Optional[List[str]] = None |
| 20 | + |
| 21 | + def as_dict(self) -> dict: |
| 22 | + """Serializes the ComplexQueryParam into a dictionary suitable for use as a JSON request body.""" |
| 23 | + body = {} |
| 24 | + if self.nested_optional_query_param is not None: |
| 25 | + body["nested_optional_query_param"] = self.nested_optional_query_param |
| 26 | + if self.nested_repeated_query_param: |
| 27 | + body["nested_repeated_query_param"] = [v for v in self.nested_repeated_query_param] |
| 28 | + return body |
| 29 | + |
| 30 | + def as_shallow_dict(self) -> dict: |
| 31 | + """Serializes the ComplexQueryParam into a shallow dictionary of its immediate attributes.""" |
| 32 | + body = {} |
| 33 | + if self.nested_optional_query_param is not None: |
| 34 | + body["nested_optional_query_param"] = self.nested_optional_query_param |
| 35 | + if self.nested_repeated_query_param: |
| 36 | + body["nested_repeated_query_param"] = self.nested_repeated_query_param |
| 37 | + return body |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def from_dict(cls, d: Dict[str, Any]) -> ComplexQueryParam: |
| 41 | + """Deserializes the ComplexQueryParam from a dictionary.""" |
| 42 | + return cls( |
| 43 | + nested_optional_query_param=d.get("nested_optional_query_param", None), |
| 44 | + nested_repeated_query_param=d.get("nested_repeated_query_param", None), |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +@dataclass |
| 49 | +class Resource: |
| 50 | + any_field: Optional[dict] = None |
| 51 | + |
| 52 | + body_field: Optional[str] = None |
| 53 | + |
| 54 | + nested_path_param_bool: Optional[bool] = None |
| 55 | + |
| 56 | + nested_path_param_int: Optional[int] = None |
| 57 | + |
| 58 | + nested_path_param_string: Optional[str] = None |
| 59 | + |
| 60 | + def as_dict(self) -> dict: |
| 61 | + """Serializes the Resource into a dictionary suitable for use as a JSON request body.""" |
| 62 | + body = {} |
| 63 | + if self.any_field: |
| 64 | + body["any_field"] = self.any_field |
| 65 | + if self.body_field is not None: |
| 66 | + body["body_field"] = self.body_field |
| 67 | + if self.nested_path_param_bool is not None: |
| 68 | + body["nested_path_param_bool"] = self.nested_path_param_bool |
| 69 | + if self.nested_path_param_int is not None: |
| 70 | + body["nested_path_param_int"] = self.nested_path_param_int |
| 71 | + if self.nested_path_param_string is not None: |
| 72 | + body["nested_path_param_string"] = self.nested_path_param_string |
| 73 | + return body |
| 74 | + |
| 75 | + def as_shallow_dict(self) -> dict: |
| 76 | + """Serializes the Resource into a shallow dictionary of its immediate attributes.""" |
| 77 | + body = {} |
| 78 | + if self.any_field: |
| 79 | + body["any_field"] = self.any_field |
| 80 | + if self.body_field is not None: |
| 81 | + body["body_field"] = self.body_field |
| 82 | + if self.nested_path_param_bool is not None: |
| 83 | + body["nested_path_param_bool"] = self.nested_path_param_bool |
| 84 | + if self.nested_path_param_int is not None: |
| 85 | + body["nested_path_param_int"] = self.nested_path_param_int |
| 86 | + if self.nested_path_param_string is not None: |
| 87 | + body["nested_path_param_string"] = self.nested_path_param_string |
| 88 | + return body |
| 89 | + |
| 90 | + @classmethod |
| 91 | + def from_dict(cls, d: Dict[str, Any]) -> Resource: |
| 92 | + """Deserializes the Resource from a dictionary.""" |
| 93 | + return cls( |
| 94 | + any_field=d.get("any_field", None), |
| 95 | + body_field=d.get("body_field", None), |
| 96 | + nested_path_param_bool=d.get("nested_path_param_bool", None), |
| 97 | + nested_path_param_int=d.get("nested_path_param_int", None), |
| 98 | + nested_path_param_string=d.get("nested_path_param_string", None), |
| 99 | + ) |
| 100 | + |
| 101 | + |
| 102 | +class HttpCallV2API: |
| 103 | + """Lorem Ipsum""" |
| 104 | + |
| 105 | + def __init__(self, api_client): |
| 106 | + self._api = api_client |
| 107 | + |
| 108 | + def create_resource( |
| 109 | + self, path_param_string: str, path_param_int: int, path_param_bool: bool, *, body_field: Optional[str] = None |
| 110 | + ) -> Resource: |
| 111 | + """This mimics "old" style post requests which have the resource inlined. |
| 112 | +
|
| 113 | + :param path_param_string: str |
| 114 | + :param path_param_int: int |
| 115 | + :param path_param_bool: bool |
| 116 | + :param body_field: str (optional) |
| 117 | + Body element |
| 118 | +
|
| 119 | + :returns: :class:`Resource` |
| 120 | + """ |
| 121 | + body = {} |
| 122 | + if body_field is not None: |
| 123 | + body["body_field"] = body_field |
| 124 | + headers = { |
| 125 | + "Accept": "application/json", |
| 126 | + "Content-Type": "application/json", |
| 127 | + } |
| 128 | + |
| 129 | + res = self._api.do( |
| 130 | + "POST", |
| 131 | + f"/api/2.0/http-call/{path_param_string}/{path_param_int}/{path_param_bool}", |
| 132 | + body=body, |
| 133 | + headers=headers, |
| 134 | + ) |
| 135 | + return Resource.from_dict(res) |
| 136 | + |
| 137 | + def get_resource( |
| 138 | + self, |
| 139 | + path_param_string: str, |
| 140 | + path_param_int: int, |
| 141 | + path_param_bool: bool, |
| 142 | + *, |
| 143 | + field_mask: Optional[str] = None, |
| 144 | + optional_complex_query_param: Optional[ComplexQueryParam] = None, |
| 145 | + query_param_bool: Optional[bool] = None, |
| 146 | + query_param_int: Optional[int] = None, |
| 147 | + query_param_string: Optional[str] = None, |
| 148 | + repeated_complex_query_param: Optional[List[ComplexQueryParam]] = None, |
| 149 | + repeated_query_param: Optional[List[str]] = None, |
| 150 | + ) -> Resource: |
| 151 | + |
| 152 | + query = {} |
| 153 | + if field_mask is not None: |
| 154 | + query["field_mask"] = field_mask |
| 155 | + if optional_complex_query_param is not None: |
| 156 | + query["optional_complex_query_param"] = optional_complex_query_param.as_dict() |
| 157 | + if query_param_bool is not None: |
| 158 | + query["query_param_bool"] = query_param_bool |
| 159 | + if query_param_int is not None: |
| 160 | + query["query_param_int"] = query_param_int |
| 161 | + if query_param_string is not None: |
| 162 | + query["query_param_string"] = query_param_string |
| 163 | + if repeated_complex_query_param is not None: |
| 164 | + query["repeated_complex_query_param"] = [v.as_dict() for v in repeated_complex_query_param] |
| 165 | + if repeated_query_param is not None: |
| 166 | + query["repeated_query_param"] = [v for v in repeated_query_param] |
| 167 | + headers = { |
| 168 | + "Accept": "application/json", |
| 169 | + } |
| 170 | + |
| 171 | + res = self._api.do( |
| 172 | + "GET", |
| 173 | + f"/api/2.0/http-call/{path_param_string}/{path_param_int}/{path_param_bool}", |
| 174 | + query=query, |
| 175 | + headers=headers, |
| 176 | + ) |
| 177 | + return Resource.from_dict(res) |
| 178 | + |
| 179 | + def update_resource( |
| 180 | + self, |
| 181 | + nested_path_param_string: str, |
| 182 | + nested_path_param_int: int, |
| 183 | + nested_path_param_bool: bool, |
| 184 | + resource: Resource, |
| 185 | + *, |
| 186 | + field_mask: Optional[str] = None, |
| 187 | + optional_complex_query_param: Optional[ComplexQueryParam] = None, |
| 188 | + query_param_bool: Optional[bool] = None, |
| 189 | + query_param_int: Optional[int] = None, |
| 190 | + query_param_string: Optional[str] = None, |
| 191 | + repeated_complex_query_param: Optional[List[ComplexQueryParam]] = None, |
| 192 | + repeated_query_param: Optional[List[str]] = None, |
| 193 | + ) -> Resource: |
| 194 | + """This mimics "new" style post requests which have a body field. |
| 195 | +
|
| 196 | + :param nested_path_param_string: str |
| 197 | + :param nested_path_param_int: int |
| 198 | + :param nested_path_param_bool: bool |
| 199 | + :param resource: :class:`Resource` |
| 200 | + Body element |
| 201 | + :param field_mask: str (optional) |
| 202 | + The field mask must be a single string, with multiple fields separated by commas (no spaces). The |
| 203 | + field path is relative to the resource object, using a dot (`.`) to navigate sub-fields (e.g., |
| 204 | + `author.given_name`). Specification of elements in sequence or map fields is not allowed, as only |
| 205 | + the entire collection field can be specified. Field names must exactly match the resource field |
| 206 | + names. |
| 207 | + :param optional_complex_query_param: :class:`ComplexQueryParam` (optional) |
| 208 | + :param query_param_bool: bool (optional) |
| 209 | + :param query_param_int: int (optional) |
| 210 | + :param query_param_string: str (optional) |
| 211 | + :param repeated_complex_query_param: List[:class:`ComplexQueryParam`] (optional) |
| 212 | + :param repeated_query_param: List[str] (optional) |
| 213 | +
|
| 214 | + :returns: :class:`Resource` |
| 215 | + """ |
| 216 | + body = resource.as_dict() |
| 217 | + query = {} |
| 218 | + if field_mask is not None: |
| 219 | + query["field_mask"] = field_mask |
| 220 | + if optional_complex_query_param is not None: |
| 221 | + query["optional_complex_query_param"] = optional_complex_query_param.as_dict() |
| 222 | + if query_param_bool is not None: |
| 223 | + query["query_param_bool"] = query_param_bool |
| 224 | + if query_param_int is not None: |
| 225 | + query["query_param_int"] = query_param_int |
| 226 | + if query_param_string is not None: |
| 227 | + query["query_param_string"] = query_param_string |
| 228 | + if repeated_complex_query_param is not None: |
| 229 | + query["repeated_complex_query_param"] = [v.as_dict() for v in repeated_complex_query_param] |
| 230 | + if repeated_query_param is not None: |
| 231 | + query["repeated_query_param"] = [v for v in repeated_query_param] |
| 232 | + headers = { |
| 233 | + "Accept": "application/json", |
| 234 | + "Content-Type": "application/json", |
| 235 | + } |
| 236 | + |
| 237 | + res = self._api.do( |
| 238 | + "PATCH", |
| 239 | + f"/api/2.0/http-call/{nested_path_param_string}/{nested_path_param_int}/{nested_path_param_bool}", |
| 240 | + query=query, |
| 241 | + body=body, |
| 242 | + headers=headers, |
| 243 | + ) |
| 244 | + return Resource.from_dict(res) |
0 commit comments