From d91c5f7b8e4215b3e5ddba9a61a6b87a99f97659 Mon Sep 17 00:00:00 2001 From: Yujing Wu Date: Fri, 17 Apr 2015 11:55:43 -0700 Subject: [PATCH 1/4] Add blog link to README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 51b20e3..3585fce 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ If you are not familiar with SAMI we have extensive documentation at http://deve The full SAMI API specification with examples can be found at http://developer.samsungsami.io/sami/api-spec.html +We blog about advanced sample applications at http://blog.samsungsami.io/ + To create and manage your services and devices on SAMI visit developer portal at http://devportal.samsungsami.io Licence and Copyright From 4b5a8a323ceec78fffa8ba724d770dd7fbad2d74 Mon Sep 17 00:00:00 2001 From: Maneesh Sahu Date: Fri, 29 May 2015 11:35:35 -0700 Subject: [PATCH 2/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3585fce..b001867 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ SAMI Python SDK ================ -This SDK helps you connect your Python scripts to SAMI. The SDK helps authenticating with SAMI, exposes a number of methods to easily execute REST API calls to SAMI and supports WebSockets. +This SDK helps you connect your Python scripts to SAMI. The SDK helps authenticating with SAMI, exposes a number of methods to easily execute REST API calls to SAMI. Prerequisites ------------- From 5033c1f827515a14dd26823978b436f72c77f56b Mon Sep 17 00:00:00 2001 From: Maneesh Sahu-SSI Date: Tue, 15 Sep 2015 15:12:31 -0700 Subject: [PATCH 3/4] Updated README --- MessagesApi.py | 55 +++++++++++++++--------------------- README.md | 35 ++++++++++++++++++++++- models/Device.py | 5 ++-- models/ManifestProperties.py | 5 ++-- models/Message.py | 3 +- models/NormalizedMessage.py | 5 ++-- samiio.py | 4 +-- 7 files changed, 65 insertions(+), 47 deletions(-) diff --git a/MessagesApi.py b/MessagesApi.py index d7ab293..3058f65 100644 --- a/MessagesApi.py +++ b/MessagesApi.py @@ -28,7 +28,7 @@ class MessagesApi(object): def __init__(self, apiClient): self.apiClient = apiClient - + def getNormalizedMessages(self, **kwargs): """Get the messages normalized @@ -52,7 +52,7 @@ def getNormalizedMessages(self, **kwargs): order, str: Desired sort order: 'asc' or 'desc' (optional) - + Returns: NormalizedMessagesEnvelope """ @@ -101,9 +101,9 @@ def getNormalizedMessages(self, **kwargs): responseObject = self.apiClient.deserialize(response, 'NormalizedMessagesEnvelope') return responseObject - - + + def postMessage(self, body, **kwargs): """POST a message @@ -111,7 +111,7 @@ def postMessage(self, body, **kwargs): Args: body, Message: Message (required) - + Returns: MessageIDEnvelope """ @@ -142,9 +142,9 @@ def postMessage(self, body, **kwargs): responseObject = self.apiClient.deserialize(response, 'MessageIDEnvelope') return responseObject - - + + def getNormalizedMessagesLast(self, sdids, count, **kwargs): """Get the last few Normalized messages @@ -156,7 +156,7 @@ def getNormalizedMessagesLast(self, sdids, count, **kwargs): count, integer: count (required) - + Returns: NormalizedMessagesEnvelope """ @@ -193,9 +193,9 @@ def getNormalizedMessagesLast(self, sdids, count, **kwargs): responseObject = self.apiClient.deserialize(response, 'NormalizedMessagesEnvelope') return responseObject - - + + def getNormalizedMessagesAggregates(self, sdid, field, **kwargs): """Get aggregates on normalized messages on a field @@ -209,7 +209,7 @@ def getNormalizedMessagesAggregates(self, sdid, field, **kwargs): endDate, long: endDate (optional) - + Returns: AggregatesEnvelope """ @@ -248,9 +248,9 @@ def getNormalizedMessagesAggregates(self, sdid, field, **kwargs): responseObject = self.apiClient.deserialize(response, 'AggregatesEnvelope') return responseObject - - + + def getNormalizedMessagesPresence(self, sdid, fieldPresence, interval, **kwargs): """Get the presence of a field @@ -266,7 +266,7 @@ def getNormalizedMessagesPresence(self, sdid, fieldPresence, interval, **kwargs) endDate, long: endDate (optional) - + Returns: FieldPresenceEnvelope """ @@ -307,9 +307,9 @@ def getNormalizedMessagesPresence(self, sdid, fieldPresence, interval, **kwargs) responseObject = self.apiClient.deserialize(response, 'FieldPresenceEnvelope') return responseObject - - + + def getRawMessages(self, **kwargs): """Get raw messages @@ -327,7 +327,7 @@ def getRawMessages(self, **kwargs): order, str: Desired sort order: 'asc' or 'desc' (optional) - + Returns: RawMessagesEnvelope """ @@ -370,9 +370,9 @@ def getRawMessages(self, **kwargs): responseObject = self.apiClient.deserialize(response, 'RawMessagesEnvelope') return responseObject - - + + def exportNormalizedMessages(self, **kwargs): """Export Normalized messages @@ -388,7 +388,7 @@ def exportNormalizedMessages(self, **kwargs): format, str: Format the export will be returned as. (optional) - + Returns: ExportEnvelope """ @@ -429,9 +429,9 @@ def exportNormalizedMessages(self, **kwargs): responseObject = self.apiClient.deserialize(response, 'ExportEnvelope') return responseObject - - + + def checkExportStatus(self, exportId, **kwargs): """Check status of the export query. @@ -439,7 +439,7 @@ def checkExportStatus(self, exportId, **kwargs): Args: exportId, str: exportId (required) - + Returns: ExportStatusEnvelope """ @@ -474,12 +474,3 @@ def checkExportStatus(self, exportId, **kwargs): responseObject = self.apiClient.deserialize(response, 'ExportStatusEnvelope') return responseObject - - - - - - - - - diff --git a/README.md b/README.md index b001867..2e34d9d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ SAMI Python SDK ================ -This SDK helps you connect your Python scripts to SAMI. The SDK helps authenticating with SAMI, exposes a number of methods to easily execute REST API calls to SAMI. +This SDK helps you connect your Python scripts to SAMI. The SDK helps authenticating with SAMI, exposes a number of methods to easily execute REST API calls to SAMI. Prerequisites ------------- @@ -14,6 +14,39 @@ Installation Once you have installed the required libraries add the scripts to your project. +``` +#!/usr/bin/env python + +accessToken = "" + +print 'SAMI Python Demo Client' +print '-----------------------' + +from samiio import ApiClient +apiClient = ApiClient(apiKey=accessToken, apiServer = "https://api.samsungsami.io/v1.1") + +from MessagesApi import MessagesApi +messagesApi = MessagesApi(apiClient) + +from models import * +message = Message.Message() + +message.sdid = "" +message.type = "message" + +# message.data contains the device JSON message +# Data below is JSON for the SAMI Pedometer +message.data = {'numberOfSteps':2000, 'distance': 1.1, 'floorsAscended': 2, 'floorsDescended': 0} + +print 'Sending message:' +print message.data + +messageIDEnvelope = messagesApi.sendMessageAction(body=message) + +print 'Sent.' +print ' Message ID: ' + messageIDEnvelope.data.mid +``` + For a more complete list of examples see our demo application at https://github.com/samsungsamiio/sami-python-demo More about SAMI diff --git a/models/Device.py b/models/Device.py index 6f1ac47..1db3398 100644 --- a/models/Device.py +++ b/models/Device.py @@ -28,7 +28,7 @@ def __init__(self): 'manifestVersion': 'long', 'manifestVersionPolicy': 'str', 'needProviderAuth': 'bool', - 'properties': 'str', + 'properties': 'object', 'providerCredentials': 'str' } @@ -39,8 +39,7 @@ def __init__(self): self.dtid = None # str self.name = None # str self.manifestVersion = None # long - self.manifestVersionPolicy = None # str + self.manifestVersionPolicy = None # object self.needProviderAuth = None # bool self.properties = None # str self.providerCredentials = None # str - diff --git a/models/ManifestProperties.py b/models/ManifestProperties.py index fc753db..2a9c066 100644 --- a/models/ManifestProperties.py +++ b/models/ManifestProperties.py @@ -21,10 +21,9 @@ class ManifestProperties: def __init__(self): self.swaggerTypes = { - 'properties': 'str' + 'properties': 'object' } - self.properties = None # str - + self.properties = None # object diff --git a/models/Message.py b/models/Message.py index 166928d..ba7fc86 100644 --- a/models/Message.py +++ b/models/Message.py @@ -24,7 +24,7 @@ def __init__(self): 'sdid': 'str', 'ddid': 'str', 'ts': 'long', - 'data': 'str' + 'data': 'object' } @@ -33,4 +33,3 @@ def __init__(self): self.ddid = None # str self.ts = None # long self.data = None # str - diff --git a/models/NormalizedMessage.py b/models/NormalizedMessage.py index a99c6e6..56085e6 100644 --- a/models/NormalizedMessage.py +++ b/models/NormalizedMessage.py @@ -28,7 +28,7 @@ def __init__(self): 'stdid': 'str', 'uid': 'str', 'mv': 'long', - 'data': 'str' + 'data': 'object' } @@ -40,5 +40,4 @@ def __init__(self): self.stdid = None # str self.uid = None # str self.mv = None # long - self.data = None # str - + self.data = None # object diff --git a/samiio.py b/samiio.py index 4ec664d..3550260 100644 --- a/samiio.py +++ b/samiio.py @@ -101,7 +101,7 @@ def sanitizeForSerialization(self, obj): if type(obj) == type(None): return None - elif type(obj) in [str, int, long, float, bool]: + elif type(obj) in [str, int, long, float, bool, object]: return obj elif type(obj) == list: return [self.sanitizeForSerialization(subObj) for subObj in obj] @@ -206,5 +206,3 @@ def __init__(self, *args, **kwargs): def get_method(self): return getattr(self, 'method', urllib2.Request.get_method(self)) - - From 643f4eda84b39e09bb67d9a17d347a59a0ee9dd1 Mon Sep 17 00:00:00 2001 From: Koen Smets Date: Thu, 8 Oct 2015 08:40:43 +0200 Subject: [PATCH 4/4] Fix issue with deserializing objects --- samiio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samiio.py b/samiio.py index 3550260..8df8373 100644 --- a/samiio.py +++ b/samiio.py @@ -143,7 +143,7 @@ def deserialize(self, obj, objClass): subClass = match.group(1) return [self.deserialize(subObj, subClass) for subObj in obj] - if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']): + if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime', 'object']): objClass = eval(objClass) else: # not a native type, must be model class objClass = eval(objClass + '.' + objClass) @@ -156,6 +156,8 @@ def deserialize(self, obj, objClass): # last 5 characters. return datetime.datetime.strptime(obj[:-5], "%Y-%m-%dT%H:%M:%S.%f") + elif objClass == object: + return obj instance = objClass()