From 692eb072eac1a3eb67e1ab9d2a62431ccddf919f Mon Sep 17 00:00:00 2001 From: Sunayana Ghosh Date: Sat, 28 Aug 2021 09:59:55 +0200 Subject: [PATCH] #3 Initial work on getting the CategoryResponse object from eonet api --- apps/retrieve_category.py | 14 +- swagger_client/__init__.py | 3 +- swagger_client/api/__init__.py | 2 +- swagger_client/api/categories_api.py | 128 ---------------- swagger_client/api/default_api.py | 150 +++++++++++++++++++ swagger_client/models/__init__.py | 1 + swagger_client/models/category.py | 88 ++++++++++- swagger_client/models/category_response.py | 162 +++++++++++++++++++++ 8 files changed, 408 insertions(+), 140 deletions(-) delete mode 100644 swagger_client/api/categories_api.py create mode 100644 swagger_client/api/default_api.py create mode 100644 swagger_client/models/category_response.py diff --git a/apps/retrieve_category.py b/apps/retrieve_category.py index 0a94404..97d3684 100644 --- a/apps/retrieve_category.py +++ b/apps/retrieve_category.py @@ -1,10 +1,14 @@ -import os +import swagger_client +from swagger_client.api.default_api import DefaultApi +from swagger_client.rest import ApiException -print(os.getcwd()) +def main(): + api = DefaultApi() + wildfire_response = api.categories_category_id_get("wildfires") -from swagger_client.api.categories_api import CategoriesApi + print(wildfire_response) -api = CategoriesApi() -api.get_category_by_id(1) +if __name__ == "__main__": + main() diff --git a/swagger_client/__init__.py b/swagger_client/__init__.py index eb148ec..1110912 100644 --- a/swagger_client/__init__.py +++ b/swagger_client/__init__.py @@ -15,9 +15,10 @@ from __future__ import absolute_import # import apis into sdk package -from swagger_client.api.categories_api import CategoriesApi +from swagger_client.api.default_api import DefaultApi # import ApiClient from swagger_client.api_client import ApiClient from swagger_client.configuration import Configuration # import models into sdk package from swagger_client.models.category import Category +from swagger_client.models.category_response import CategoryResponse diff --git a/swagger_client/api/__init__.py b/swagger_client/api/__init__.py index 68aee13..447bb1c 100644 --- a/swagger_client/api/__init__.py +++ b/swagger_client/api/__init__.py @@ -3,4 +3,4 @@ # flake8: noqa # import apis into api package -from swagger_client.api.categories_api import CategoriesApi +from swagger_client.api.default_api import DefaultApi diff --git a/swagger_client/api/categories_api.py b/swagger_client/api/categories_api.py deleted file mode 100644 index d28c4f8..0000000 --- a/swagger_client/api/categories_api.py +++ /dev/null @@ -1,128 +0,0 @@ -# coding: utf-8 - -""" - The Earth Observatory Natural Event Tracker ([EONET](https://eonet.sci.gsfc.nasa.gov/what-is-eonet)) - - No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 - - OpenAPI spec version: 3.0.0 - - Generated by: https://github.com/swagger-api/swagger-codegen.git -""" - -from __future__ import absolute_import - -import re # noqa: F401 - -# python 2 and python 3 compatibility library -import six - -from swagger_client.api_client import ApiClient - - -class CategoriesApi(object): - """NOTE: This class is auto generated by the swagger code generator program. - - Do not edit the class manually. - Ref: https://github.com/swagger-api/swagger-codegen - """ - - def __init__(self, api_client=None): - if api_client is None: - api_client = ApiClient() - self.api_client = api_client - - def get_category_by_id(self, category_id, **kwargs): # noqa: E501 - """Categories are the types of events by which individual events are cataloged # noqa: E501 - - Returns a single category # noqa: E501 - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please pass async_req=True - >>> thread = api.get_category_by_id(category_id, async_req=True) - >>> result = thread.get() - - :param async_req bool - :param int category_id: ID of category to return (required) - :return: Category - If the method is called asynchronously, - returns the request thread. - """ - kwargs['_return_http_data_only'] = True - if kwargs.get('async_req'): - return self.get_category_by_id_with_http_info(category_id, **kwargs) # noqa: E501 - else: - (data) = self.get_category_by_id_with_http_info(category_id, **kwargs) # noqa: E501 - return data - - def get_category_by_id_with_http_info(self, category_id, **kwargs): # noqa: E501 - """Categories are the types of events by which individual events are cataloged # noqa: E501 - - Returns a single category # noqa: E501 - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please pass async_req=True - >>> thread = api.get_category_by_id_with_http_info(category_id, async_req=True) - >>> result = thread.get() - - :param async_req bool - :param int category_id: ID of category to return (required) - :return: Category - If the method is called asynchronously, - returns the request thread. - """ - - all_params = ['category_id'] # noqa: E501 - all_params.append('async_req') - all_params.append('_return_http_data_only') - all_params.append('_preload_content') - all_params.append('_request_timeout') - - params = locals() - for key, val in six.iteritems(params['kwargs']): - if key not in all_params: - raise TypeError( - "Got an unexpected keyword argument '%s'" - " to method get_category_by_id" % key - ) - params[key] = val - del params['kwargs'] - # verify the required parameter 'category_id' is set - if ('category_id' not in params or - params['category_id'] is None): - raise ValueError("Missing the required parameter `category_id` when calling `get_category_by_id`") # noqa: E501 - - collection_formats = {} - - path_params = {} - if 'category_id' in params: - path_params['categoryId'] = params['category_id'] # noqa: E501 - - query_params = [] - - header_params = {} - - form_params = [] - local_var_files = {} - - body_params = None - # HTTP header `Accept` - header_params['Accept'] = self.api_client.select_header_accept( - ['application/json']) # noqa: E501 - - # Authentication setting - auth_settings = [] # noqa: E501 - - return self.api_client.call_api( - '/categories/{categoryId}', 'GET', - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_type='Category', # noqa: E501 - auth_settings=auth_settings, - async_req=params.get('async_req'), - _return_http_data_only=params.get('_return_http_data_only'), - _preload_content=params.get('_preload_content', True), - _request_timeout=params.get('_request_timeout'), - collection_formats=collection_formats) diff --git a/swagger_client/api/default_api.py b/swagger_client/api/default_api.py new file mode 100644 index 0000000..b0a6ba6 --- /dev/null +++ b/swagger_client/api/default_api.py @@ -0,0 +1,150 @@ +# coding: utf-8 + +""" + The Earth Observatory Natural Event Tracker ([EONET](https://eonet.sci.gsfc.nasa.gov/what-is-eonet)) + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: 3.0.0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from swagger_client.api_client import ApiClient + + +class DefaultApi(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + Ref: https://github.com/swagger-api/swagger-codegen + """ + + def __init__(self, api_client=None): + if api_client is None: + api_client = ApiClient() + self.api_client = api_client + + def categories_category_id_get(self, category_id, **kwargs): # noqa: E501 + """Returns a json object of categories. # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.categories_category_id_get(category_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str category_id: Filter the events by the Category. (required) + :param str source: Filter the topically-constrained events by the Source. Multiple sources can be included in the parameter, comma separated, operates as a boolean OR. + :param str status: Events that have ended are assigned a closed date and the existence of that date will allow you to filter for only-open or only-closed events. Omitting the status parameter will return only the currently open events. + :param int limit: Limits the number of events returned. + :param int days: Limit the number of prior days (including today) from which events will be returned. + :param str start: Select a starting date for the events. To be used together with end parameter. + :param str end: Select an ending date for the events. To be used together with start parameter for defining a range. + :return: CategoryResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs['_return_http_data_only'] = True + if kwargs.get('async_req'): + return self.categories_category_id_get_with_http_info(category_id, **kwargs) # noqa: E501 + else: + (data) = self.categories_category_id_get_with_http_info(category_id, **kwargs) # noqa: E501 + return data + + def categories_category_id_get_with_http_info(self, category_id, **kwargs): # noqa: E501 + """Returns a json object of categories. # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.categories_category_id_get_with_http_info(category_id, async_req=True) + >>> result = thread.get() + + :param async_req bool + :param str category_id: Filter the events by the Category. (required) + :param str source: Filter the topically-constrained events by the Source. Multiple sources can be included in the parameter, comma separated, operates as a boolean OR. + :param str status: Events that have ended are assigned a closed date and the existence of that date will allow you to filter for only-open or only-closed events. Omitting the status parameter will return only the currently open events. + :param int limit: Limits the number of events returned. + :param int days: Limit the number of prior days (including today) from which events will be returned. + :param str start: Select a starting date for the events. To be used together with end parameter. + :param str end: Select an ending date for the events. To be used together with start parameter for defining a range. + :return: CategoryResponse + If the method is called asynchronously, + returns the request thread. + """ + + all_params = ['category_id', 'source', 'status', 'limit', 'days', 'start', 'end'] # noqa: E501 + all_params.append('async_req') + all_params.append('_return_http_data_only') + all_params.append('_preload_content') + all_params.append('_request_timeout') + + params = locals() + for key, val in six.iteritems(params['kwargs']): + if key not in all_params: + raise TypeError( + "Got an unexpected keyword argument '%s'" + " to method categories_category_id_get" % key + ) + params[key] = val + del params['kwargs'] + # verify the required parameter 'category_id' is set + if ('category_id' not in params or + params['category_id'] is None): + raise ValueError("Missing the required parameter `category_id` when calling `categories_category_id_get`") # noqa: E501 + + collection_formats = {} + + path_params = {} + if 'category_id' in params: + path_params['categoryId'] = params['category_id'] # noqa: E501 + + query_params = [] + if 'source' in params: + query_params.append(('source', params['source'])) # noqa: E501 + if 'status' in params: + query_params.append(('status', params['status'])) # noqa: E501 + if 'limit' in params: + query_params.append(('limit', params['limit'])) # noqa: E501 + if 'days' in params: + query_params.append(('days', params['days'])) # noqa: E501 + if 'start' in params: + query_params.append(('start', params['start'])) # noqa: E501 + if 'end' in params: + query_params.append(('end', params['end'])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # Authentication setting + auth_settings = [] # noqa: E501 + + return self.api_client.call_api( + '/categories/{categoryId}', 'GET', + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type='CategoryResponse', # noqa: E501 + auth_settings=auth_settings, + async_req=params.get('async_req'), + _return_http_data_only=params.get('_return_http_data_only'), + _preload_content=params.get('_preload_content', True), + _request_timeout=params.get('_request_timeout'), + collection_formats=collection_formats) diff --git a/swagger_client/models/__init__.py b/swagger_client/models/__init__.py index 68ef2b2..8a43909 100644 --- a/swagger_client/models/__init__.py +++ b/swagger_client/models/__init__.py @@ -15,3 +15,4 @@ # import models into model package from swagger_client.models.category import Category +from swagger_client.models.category_response import CategoryResponse diff --git a/swagger_client/models/category.py b/swagger_client/models/category.py index 86024b0..ff76dc9 100644 --- a/swagger_client/models/category.py +++ b/swagger_client/models/category.py @@ -28,19 +28,34 @@ class Category(object): and the value is json key in definition. """ swagger_types = { - 'id': 'int' + 'id': 'str', + 'title': 'str', + 'description': 'str', + 'link': 'str' } attribute_map = { - 'id': 'id' + 'id': 'id', + 'title': 'title', + 'description': 'description', + 'link': 'link' } - def __init__(self, id=None): # noqa: E501 + def __init__(self, id=None, title=None, description=None, link=None): # noqa: E501 """Category - a model defined in Swagger""" # noqa: E501 self._id = None + self._title = None + self._description = None + self._link = None self.discriminator = None if id is not None: self.id = id + if title is not None: + self.title = title + if description is not None: + self.description = description + if link is not None: + self.link = link @property def id(self): @@ -48,7 +63,7 @@ def id(self): :return: The id of this Category. # noqa: E501 - :rtype: int + :rtype: str """ return self._id @@ -58,11 +73,74 @@ def id(self, id): :param id: The id of this Category. # noqa: E501 - :type: int + :type: str """ self._id = id + @property + def title(self): + """Gets the title of this Category. # noqa: E501 + + + :return: The title of this Category. # noqa: E501 + :rtype: str + """ + return self._title + + @title.setter + def title(self, title): + """Sets the title of this Category. + + + :param title: The title of this Category. # noqa: E501 + :type: str + """ + + self._title = title + + @property + def description(self): + """Gets the description of this Category. # noqa: E501 + + + :return: The description of this Category. # noqa: E501 + :rtype: str + """ + return self._description + + @description.setter + def description(self, description): + """Sets the description of this Category. + + + :param description: The description of this Category. # noqa: E501 + :type: str + """ + + self._description = description + + @property + def link(self): + """Gets the link of this Category. # noqa: E501 + + + :return: The link of this Category. # noqa: E501 + :rtype: str + """ + return self._link + + @link.setter + def link(self, link): + """Sets the link of this Category. + + + :param link: The link of this Category. # noqa: E501 + :type: str + """ + + self._link = link + def to_dict(self): """Returns the model properties as a dict""" result = {} diff --git a/swagger_client/models/category_response.py b/swagger_client/models/category_response.py new file mode 100644 index 0000000..223f409 --- /dev/null +++ b/swagger_client/models/category_response.py @@ -0,0 +1,162 @@ +# coding: utf-8 + +""" + The Earth Observatory Natural Event Tracker ([EONET](https://eonet.sci.gsfc.nasa.gov/what-is-eonet)) + + No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) # noqa: E501 + + OpenAPI spec version: 3.0.0 + + Generated by: https://github.com/swagger-api/swagger-codegen.git +""" + +import pprint +import re # noqa: F401 + +import six + +class CategoryResponse(object): + """NOTE: This class is auto generated by the swagger code generator program. + + Do not edit the class manually. + """ + """ + Attributes: + swagger_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + swagger_types = { + 'title': 'str', + 'description': 'str', + 'link': 'str' + } + + attribute_map = { + 'title': 'title', + 'description': 'description', + 'link': 'link' + } + + def __init__(self, title=None, description=None, link=None): # noqa: E501 + """CategoryResponse - a model defined in Swagger""" # noqa: E501 + self._title = None + self._description = None + self._link = None + self.discriminator = None + if title is not None: + self.title = title + if description is not None: + self.description = description + if link is not None: + self.link = link + + @property + def title(self): + """Gets the title of this CategoryResponse. # noqa: E501 + + + :return: The title of this CategoryResponse. # noqa: E501 + :rtype: str + """ + return self._title + + @title.setter + def title(self, title): + """Sets the title of this CategoryResponse. + + + :param title: The title of this CategoryResponse. # noqa: E501 + :type: str + """ + + self._title = title + + @property + def description(self): + """Gets the description of this CategoryResponse. # noqa: E501 + + + :return: The description of this CategoryResponse. # noqa: E501 + :rtype: str + """ + return self._description + + @description.setter + def description(self, description): + """Sets the description of this CategoryResponse. + + + :param description: The description of this CategoryResponse. # noqa: E501 + :type: str + """ + + self._description = description + + @property + def link(self): + """Gets the link of this CategoryResponse. # noqa: E501 + + + :return: The link of this CategoryResponse. # noqa: E501 + :rtype: str + """ + return self._link + + @link.setter + def link(self, link): + """Sets the link of this CategoryResponse. + + + :param link: The link of this CategoryResponse. # noqa: E501 + :type: str + """ + + self._link = link + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.swagger_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else x, + value + )) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else item, + value.items() + )) + else: + result[attr] = value + if issubclass(CategoryResponse, dict): + for key, value in self.items(): + result[key] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, CategoryResponse): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + """Returns true if both objects are not equal""" + return not self == other