genesluder / python-apns

A library for interacting with APNs using HTTP/2 and token-based authentication.
MIT License
90 stars 50 forks source link

Returning response in the method, APNsClient._send_push_request() instead of True #14

Closed SanghoYang closed 3 years ago

SanghoYang commented 6 years ago

Hi,

I wonder there is any reason why it returns True instead of response in the method, _send_push_request() in the class, APNsClient.

def _send_push_request(self, connection, registration_id, json_data, request_headers):
    connection.request(
        'POST', 
        '/3/device/{0}'.format(registration_id), 
        json_data, 
        headers=request_headers
    )
    response = connection.get_response()

    if response.status != APNSResponse.Success:
        identifier = response.headers['apns-id']
        body = json.loads(response.read().decode('utf-8'))
        reason = body["reason"] if "reason" in body else None

        if reason:
            exceptions_module = importlib.import_module("gobiko.apns.exceptions")
            ExceptionClass = None
            try:
                ExceptionClass = getattr(exceptions_module, reason)
            except AttributeError:
                ExceptionClass = InternalException
            raise ExceptionClass()

    return True

And, how about changing it into returning response?

Thanks.

genesluder commented 3 years ago

Done: https://github.com/genesluder/python-apns/commit/215b9f8880d15c53e3bbab2dc8f388a482dc6d7f