Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
updating devices if they already exist and one is trying to register …
Browse files Browse the repository at this point in the history
…the,
  • Loading branch information
melbic committed Apr 27, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e9266a7 commit 97a76f3
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
v1.0, 2015/01/05 -- Initial release.
v1.0.1, 2015/01/06 -- Updated Documentation, added logging settings, Python 3 support
v1.0.2, 2015/01/06 -- The PushMessage model allows now more null values
v1.0.2, 2015/01/06 -- The PushMessage model allows now more null values
v1.0.3, 2015/04/27 -- Improving the create_or_update SNSDevice method: If the device is already registered with other attributes, the given error gets parsed an updated with the new attributes.
13 changes: 12 additions & 1 deletion scarface/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import ABCMeta, abstractproperty, abstractmethod
import json
from boto.exception import BotoServerError
from django.conf import settings
import re
from .utils import DefaultConnection, PushLogger, APP_PREFIX
from django.db import models

@@ -99,7 +101,16 @@ def register_or_update(self, new_token=None, custom_user_data=u"", connection=No
if self.is_registered:
result = self.update(new_token, custom_user_data, connection)
else:
result = self.register(custom_user_data, connection)
try:
result = self.register(custom_user_data, connection)
# Heavily inspired by http://stackoverflow.com/a/28316993/270265
except BotoServerError as err:
result_re = re.compile(r'Endpoint(.*)already', re.IGNORECASE)
result = result_re.search(err.message)
if result:
arn = result.group(0).replace('Endpoint ','').replace(' already','')
self.arn = arn
self.update(new_token, custom_user_data, connection)
return result

@DefaultConnection
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

setup(
name='django-scarface',
version='1.0.2',
version='1.0.3',
packages=['scarface'],
include_package_data=True,
license='MIT License',

0 comments on commit 97a76f3

Please sign in to comment.