Skip to content

Commit

Permalink
fix sms retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail.gubenko committed Feb 6, 2024
1 parent eec1474 commit 9c75c4e
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 185 deletions.
27 changes: 17 additions & 10 deletions docs/examples/local_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,29 @@ def get_iterator_length(iterator):
return len(list(iterator))

# Execute a command against desired API
devices = emnify.devices.get_devices_list()


## print first 100 devices
for i, device in enumerate(devices):
if i >= 100:
break
print(device)
# devices = emnify.devices.get_devices_list()
#
#
# ## print first 100 devices
# for i, device in enumerate(devices):
# if i >= 100:
# break
# print(device)

# Count remaining devices
print(get_iterator_length(devices))
# print(get_iterator_length(devices))


# Get list of sims
sims = emnify.sim.get_sim_list()

# Count sims
print(get_iterator_length(sims))
# print(get_iterator_length(sims))

# sms_list = emnify.devices.get_device_sms_list(device=11379224)
# print(list(sms_list))
# print(sms_list)

# Get list of events
events = emnify.devices.get_device_events_list(device=11379224)
print(list(events))
5 changes: 5 additions & 0 deletions emnify/modules/device/api_call_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class GetAllDevicesApiCall(BaseApiManager):
class GetEventsByDevice(BaseApiManager):
request_url_prefix = '/v1/endpoint/{endpoint_id}/event'
request_method_name = RequestsType.GET.value
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.response_handlers = self.response_handlers.copy() | {
200: 'return_paginator'
}


class CreateDevice(BaseApiManager):
Expand Down
6 changes: 3 additions & 3 deletions emnify/modules/device/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_device_filter_model(self) -> typing.Type[device_models.FilterDeviceModel

def get_device_sms_list(self, *, device: typing.Union[device_models.Device, int]) -> device_models.ListSms:
device_id = self.validate_device(device)
sms_response = device_call_managers.GetEventsByDevice().call_api(
sms_response = device_call_managers.GetAllSmsFromDevice().call_api(
client=self.client, path_params={'endpoint_id': device_id}
)
for sms in sms_response:
Expand Down Expand Up @@ -199,8 +199,8 @@ def get_device_events_list(self, device: typing.Union[device_models.Device, int]
events_response = device_call_managers.GetEventsByDevice().call_api(
client=self.client, path_params={'endpoint_id': device_id}
)
for event in events_response:
yield device_models.DeviceEvent(**event)

return (device_models.DeviceEvent(**i) for i in events_response)

def change_status(
self, device: typing.Union[
Expand Down
2 changes: 1 addition & 1 deletion emnify/modules/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SmsCreateModel(generated_models.SubmitMTSMSrequest):
dcs: Optional[int] = None


class ListSms(generated_models.RetrieveEventsresponse5):
class ListSms(generated_models.ListofSMSresponse):
"""
Renamed generated model
"""
Expand Down
Loading

0 comments on commit 9c75c4e

Please sign in to comment.