Exemplo n.º 1
0
    def __init__(self, response: Any) -> None:
        if response.status in TypeResponse.okay_codes:
            super(TypeResponse, self).__init__(get_expire_time(response),
                                               response.status, None)
            self.description = response.data['description']
            self.group_id = response.data['group_id']
            self.name = response.data['name']
            self.type_id = response.data['type_id']
            if 'market_group_id' in response.data:
                self.market_group_id = response.data['market_group_id']
            else:
                self.market_group_id = None

            if 'dogma_attributes' in response.data:
                self.dogma_attributes = response.data['dogma_attributes']
            else:
                self.dogma_attributes = None
            if 'dogma_effects' in response.data:
                self.dogma_effects = response.data['dogma_effects']
            else:
                self.dogma_effects = None
        else:
            error_msg = get_error_msg_from_response(response)
            super(TypeResponse, self).__init__(get_expire_time(response),
                                               response.status, error_msg)
Exemplo n.º 2
0
 def __init__(self, response: Any) -> None:
     if response.status in GroupsResponse.okay_codes:
         super(GroupsResponse, self).__init__(get_expire_time(response),
                                              response.status, None)
         self.__ids = response.data
     else:
         error_msg = get_error_msg_from_response(response)
         super(GroupsResponse, self).__init__(get_expire_time(response),
                                              response.status, error_msg)
Exemplo n.º 3
0
    def create_squad(self, wing_id: int) -> SquadCreated:
        response = self.__client.request(
            self.__api.op['post_fleets_fleet_id_wings_wing_id_squads'](
                fleet_id=self.__fleetID, wing_id=wing_id))
        if response.status == 201:
            return SquadCreated(get_expire_time(response), response.status,
                                None, wing_id, response.data['squad_id'])

        return SquadCreated(get_expire_time(response), response.status, None,
                            None, None)
Exemplo n.º 4
0
 def __init__(self, response: Any) -> None:
     if response.status in ResolveIdsResponse.okay_codes:
         super(ResolveIdsResponse, self).__init__(get_expire_time(response),
                                                  response.status, None)
         self.__data: Dict[int, NameItem] = set()
         self.__set_data(response.data)
     else:
         error_msg = get_error_msg_from_response(response)
         super(ResolveIdsResponse,
               self).__init__(get_expire_time(response), response.status,
                              error_msg)
Exemplo n.º 5
0
 def __init__(self, response: Any) -> None:
     if response.status in CategoryResponse.okay_codes:
         super(CategoryResponse, self).__init__(get_expire_time(response),
                                                response.status, None)
         self.id = response.data['category_id']
         self.groups = response.data['groups']
         self.name = response.data['name']
         self.published = response.data['published']
     else:
         error_msg = get_error_msg_from_response(response)
         super(CategoryResponse, self).__init__(get_expire_time(response),
                                                response.status, error_msg)
Exemplo n.º 6
0
 def create_wing(self) -> WingCreated:
     response = self.__client.request(
         self.__api.op['post_fleets_fleet_id_wings'](
             fleet_id=self.__fleetID))
     if response.status == 201:
         return WingCreated(get_expire_time(response), response.status,
                            None, response.data['wing_id'])
     return make_error_response(response)
Exemplo n.º 7
0
def open_information(target_id: int) -> ESIResponse:
    api_v1: App = get_api()
    client: EsiClient = get_esi_client()

    resp = client.request(api_v1.op['post_ui_openwindow_information'](target_id=target_id))
    if resp.status == 204:
        return ESIResponse(get_expire_time(resp), resp.status, None)
    return make_error_response(resp)
Exemplo n.º 8
0
 def get_member(self) -> ESIResponse:
     response = self.__client.request(
         self.__api.op['get_fleets_fleet_id_members'](
             fleet_id=self.__fleetID))
     logger.debug("Got ESI Response with status[%d]", response.status)
     if response.status == 200:
         return EveFleetMembers(get_expire_time(response), response.status,
                                None, response.data)
     return make_error_response(response)
Exemplo n.º 9
0
    def set_wing_name(self, wing_id: int, name: str) -> ESIResponse:
        # type: (int, str) -> ESIResponse
        data = {'name': name}
        response = self.__client.request(
            self.__api.op['put_fleets_fleet_id_wings_wing_id'](
                fleet_id=self.__fleetID, wing_id=wing_id, naming=data))

        if response.status == 204:
            return ESIResponse(get_expire_time(response), response.status,
                               None)

        return make_error_response(response)
Exemplo n.º 10
0
 def get_fleet_info(self, char_id: int) -> Union[FleetInfo, ESIResponse]:
     authed_esi_client = get_esi_client()
     try:
         resp = authed_esi_client.request(self._api().op['get_characters_character_id_fleet'](character_id=char_id))
         if resp.status == 200:
             return FleetInfo(get_expire_time(resp), resp.status, None, resp.data)
         else:
             logger.error(f'Got error requesting fleet info for character={char_id}')
             return make_error_response(resp)
     except ReadTimeoutError as e:
         logger.error(f'ESI Read Timeout on get_characters_character_id {e}')
         raise e
Exemplo n.º 11
0
    def set_squad_name(self, squad_id: int, name: str) -> ESIResponse:
        response = self.__client.request(
            self.__api.op['put_fleets_fleet_id_squads_squad_id'](
                fleet_id=self.__fleetID,
                squad_id=squad_id,
                naming={
                    'name': name
                }))

        if response.status == 204:
            return ESIResponse(get_expire_time(response), response.status,
                               None)
        return make_error_response(response)
Exemplo n.º 12
0
    def get_corporation_info(self, corp_id: int) -> Union[CorporationInfo, ESIResponse]:

        try:
            resp = self.esi_client.request(self._api()
                                           .op['get_corporations_corporation_id'](corporation_id=corp_id))
            if resp.status == 200:
                return CorporationInfo(get_expire_time(resp), resp.status, None, resp.data)
            else:
                logger.error(f'Failed to get corp info for id={corp_id}')
                return make_error_response(resp)

        except ReadTimeoutError as e:
            logger.error(f'ESI Read Timeout on get_corporation_info {e}')
            raise e
Exemplo n.º 13
0
    def set_fleet_settings(self, is_free_move: bool, motd: str) -> ESIResponse:
        settings = FleetSettings(is_free_move, motd)
        logger.info(
            f"Changing Fleetsetting to for fleet={self.__fleetID} to {settings.get_esi_data()}"
        )
        request = self.__api.op['put_fleets_fleet_id'](
            fleet_id=self.__fleetID, new_settings=settings.get_esi_data())
        response = self.__client.request(request)
        if response.status == 204:
            logger.info("Got 204 back")
            return ESIResponse(get_expire_time(response), response.status,
                               None)

        return make_error_response(response)
Exemplo n.º 14
0
def open_mail(token: SSOToken,
              recipients: Sequence[int],
              body: str,
              subject: str,
              to_corp_or_alliance_id: int = None,
              to_mailing_list_id: int = None) -> ESIResponse:
    """
    {
        "body": "string",
        "recipients": [
            0 # min 1 item
        ],
        "subject": "string",
        "to_corp_or_alliance_id": 0, # optional
        "to_mailing_list_id": 0 # optional
        # max 1 of the 2 optimal values
    }
    """

    payload: Dict[str, Any] = {}
    if to_corp_or_alliance_id is not None and to_mailing_list_id is not None:
        raise ValueError(
            "Only to_mailing_list_id or to_corp_or_alliance_id can have a value, not both!"
        )

    payload['body'] = body
    payload['subject'] = subject
    if to_mailing_list_id is not None:
        payload['to_mailing_list_id'] = to_mailing_list_id

    if to_corp_or_alliance_id is not None:
        payload['to_corp_or_alliance_id'] = to_corp_or_alliance_id

    payload['recipients'] = []

    for charID in recipients:
        payload['recipients'].append(charID)

    if len(payload['recipients']) <= 0:
        payload['recipients'] = [0]

    client = get_esi_client(token, False)
    api: App = get_api()
    response = client.request(
        api.op['post_ui_openwindow_newmail'](new_mail=payload))
    if response.status == 204:
        return ESIResponse(get_expire_time(response), response.status, None)

    return make_error_response(response)
Exemplo n.º 15
0
    def public_search(self, search: str, type_names: Sequence[str], strict: bool = True)\
            -> Union[SearchResponse, ESIResponse]:

        try:
            resp = self.esi_client.request(self._api().op['get_search'](
                categories=type_names, search=search, strict=strict))
            if resp.status == 200:
                return SearchResponse(get_expire_time(resp), resp.status, None,
                                      resp.data)
            else:
                return make_error_response(resp)

        except ReadTimeoutError as e:
            logger.error(f'ESI Read Timeout on public_search {e}')
            raise e
Exemplo n.º 16
0
    def get_alliance_info(self,
                          all_id: int) -> Union[AllianceInfo, ESIResponse]:

        try:
            resp = self.esi_client.request(
                self._api().op['get_alliances_alliance_id'](
                    alliance_id=all_id))
            if resp.status == 200:
                return AllianceInfo(get_expire_time(resp), resp.status, None,
                                    resp.data)
            else:
                logger.error(f'Failed to get alliance info for id={all_id}')
                return make_error_response(resp)

        except ReadTimeoutError as e:
            logger.error(f'ESI Read Timeout on get_alliance_info {e}')
            raise e
Exemplo n.º 17
0
    def invite(self, character_id: int, role: str, squad_id: int,
               wing_id: int) -> ESIResponse:
        """
        'fleet_commander', 'wing_commander', 'squad_commander', 'squad_member'
        """
        invite: Dict[str, Any] = {'character_id': character_id, 'role': role}
        if squad_id is not None:
            invite['squad_id'] = squad_id
        if wing_id is not None:
            invite['wing_id'] = wing_id
        response = self.__client.request(
            self.__api.op['post_fleets_fleet_id_members'](
                fleet_id=self.__fleetID, invitation=invite))

        if response.status == 204:
            return ESIResponse(get_expire_time(response), response.status,
                               None)
        return make_error_response(response)
Exemplo n.º 18
0
def open_information(target_id: int) -> ESIResponse:
    """
    Tries to open an ingame information window for the given id.
    :param target_id: id to open ingame information window for
    :return: ESIResponse
    :raises APIException if there is something wrong with tokens
    """
    token: Optional[SSOToken] = current_user.get_a_sso_token_with_scopes(esi_scopes.open_ui_window)
    if token is None:
        return ESIResponse(datetime.datetime.utcnow(), 403, f"No token with the required scopes:"
                                                            f" {''.join(esi_scopes.open_ui_window)} exists.")
    api_v1: App = get_api()
    client: EsiClient = get_esi_client(token)

    resp = client.request(api_v1.op['post_ui_openwindow_information'](target_id=target_id))
    if resp.status == 204:
        return ESIResponse(get_expire_time(resp), resp.status, None)
    return make_error_response(resp)
Exemplo n.º 19
0
    def get_wings(self) -> EveFleetWings:
        response = self.__client.request(
            self.__api.op['get_fleets_fleet_id_wings'](
                fleet_id=self.__fleetID))
        if response.status == 200:
            wings = []
            for wing in response.data:
                wing_id = wing['id']
                wing_name = wing['name']
                squads = []
                for squad in wing['squads']:
                    squad = EveFleetSquad(squad['id'], squad['name'])
                    squads.append(squad)
                fleet_wing = EveFleetWing(wing_id, wing_name, squads)
                wings.append(fleet_wing)

            return EveFleetWings(get_expire_time(response), response.status,
                                 None, wings)
        return make_error_response(response)
Exemplo n.º 20
0
 def get_fleet_settings(self) -> EveFleet:
     # type: () -> EveFleet
     """
     Get fleet information
     get_fleets_fleet_id_ok {
         is_free_move (boolean):
         Is free-move enabled ,
         is_registered (boolean):
         Does the fleet have an active fleet advertisement ,
         is_voice_enabled (boolean):
         Is EVE Voice enabled ,
         motd (string):
         Fleet MOTD in CCP flavoured HTML
     }
     """
     response = self.__client.request(
         self.__api.op['get_fleets_fleet_id'](fleet_id=self.__fleetID))
     if response.status == 200:
         return EveFleet(get_expire_time(response), response.status, None,
                         response.data['is_free_move'],
                         response.data['is_registered'],
                         response.data['is_voice_enabled'],
                         response.data['motd'])
     return make_error_response(response)