from client import SWAPIClient from exceptions import SWAPIClientError from settings import BASE_URL #from starwars_api.client import SWAPIClient #from starwars_api.exceptions import SWAPIClientError #from starwars_api.settings import BASE_URL api_client = SWAPIClient() class BaseModel(object): def __init__(self, json_data): """ Dynamically assign all attributes in `json_data` as instance attributes of the Model. """ self.json_data = json_data for k, v in json_data.items(): setattr(self, k, v) @classmethod def get(cls, resource_id): """ Returns an object of current Model requesting data to SWAPI using the api_client. """ get_method_name = "get_{resource_name}".format( resource_name = cls.RESOURCE_NAME) data = getattr(api_client, get_method_name)(resource_id) return cls(data)
from client import SWAPIClient from exceptions import SWAPIClientError from settings import BASE_URL #from starwars_api.client import SWAPIClient #from starwars_api.exceptions import SWAPIClientError #from starwars_api.settings import BASE_URL api_client = SWAPIClient() class BaseModel(object): def __init__(self, json_data): """ Dynamically assign all attributes in `json_data` as instance attributes of the Model. """ self.json_data = json_da for k, v in json_data.items(): setattr(self, k, v) @classmethod def get(cls, resource_id): """ Returns an object of current Model requesting data to SWAPI using the api_client. """ # example-> luke = People.get(1) #result = api_client._call_swapi("%s/%s/%s" % (BASE_URL, if RESOURCE_NAME = #return api_client.get_people(resource_id)
from client import SWAPIClient from exceptions import SWAPIClientError from settings import BASE_URL #from starwars_api.client import SWAPIClient #from starwars_api.exceptions import SWAPIClientError #from starwars_api.settings import BASE_URL api_client = SWAPIClient() class BaseModel(object): def __init__(self, json_data): """ Dynamically assign all attributes in `json_data` as instance attributes of the Model. """ self.json_data = json_da for k, v in json_data.items(): setattr(self, k, v) @classmethod def get(cls, resource_id): """ Returns an object of current Model requesting data to SWAPI using the api_client. """ # example-> luke = People.get(1) #result = api_client._call_swapi("%s/%s/%s" % (BASE_URL, #cls, str(resource_id))) #return api_client.get_people(resource_id)