Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding license, updated readme, and first scripts
- Loading branch information
Showing
4 changed files
with
512 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2012, Exosite LLC | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of Exosite LLC nor the names of its contributors may | ||
be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
================================================================================ | ||
UTILITY SCRIPTS | ||
================================================================================ | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Overview | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
These are examples of how to interact with Exosite's APIs. Generally as | ||
developers ask about different APIs and aspects of them, we try to build | ||
and example or test script that shows how it works. | ||
|
||
Generally these are all python scripts, but there is no specific reason that | ||
we wouldn't post other code using another language, if we feel it would be | ||
useful for developers to look. | ||
License is BSD, Copyright 2012, Exosite LLC (see LICENSE file) | ||
|
||
Python Scripts: Built/tested with Python 2.7 or will specifically call | ||
out the version in the script notes. | ||
|
||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
Quick Start | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
For Python (.py) scripts: | ||
* Install python | ||
* http://www.python.org/download/ | ||
* http://www.python.org/download/releases/2.7.2/ | ||
|
||
* Have an Exosite account (https://portals.exosite.com or other domain) | ||
|
||
* Most of these scripts require you use a hard-coded CIK for a device or for your | ||
account (https://portals.exosite.com/account/portals or similar domain). To get | ||
your device's CIK (https://portals.exosite.com/manage/devices) and click on the | ||
device. | ||
|
||
* Check the script output to get an understanding for how everything works. Most | ||
of these scripts will include a lot of usage notes. | ||
|
||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
More Information | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
* Exosite API -> http://exosite.com/api | ||
|
||
**Notes** | ||
* Support: | ||
** Email: support@exosite.com (reference the script you are using, etc) | ||
** Web: https://support.exosite.com (forums, knowledge base, ticket system) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
#============================================================================== | ||
# http_https_data_interface_read_write.py | ||
# Python script that tests https and http socket level calls | ||
# for basic data interface API to Exosite One Platform | ||
# | ||
#============================================================================== | ||
## Tested with python 2.6.5 | ||
## | ||
## Copyright (c) 2012, Exosite LLC | ||
## All rights reserved. | ||
## | ||
## | ||
## Redistribution and use in source and binary forms, with or without | ||
## modification, are permitted provided that the following conditions are met: | ||
## | ||
## * Redistributions of source code must retain the above copyright notice, | ||
## this list of conditions and the following disclaimer. | ||
## * Redistributions in binary form must reproduce the above copyright | ||
## notice, this list of conditions and the following disclaimer in the | ||
## documentation and/or other materials provided with the distribution. | ||
## * Neither the name of Exosite LLC nor the names of its contributors may | ||
## be used to endorse or promote products derived from this software | ||
## without specific prior written permission. | ||
## | ||
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
## POSSIBILITY OF SUCH DAMAGE. | ||
|
||
""" | ||
Exosite HTTP and HTTPS POST/GET REST API example (HELLO WORLD!) using http | ||
level calls | ||
""" | ||
|
||
""" | ||
Directions: | ||
1) Have an Exosite Portals account | ||
2) Add a new Device client to your portal. Click on it to get it's CIK (KEY) | ||
3) Add the CIK below where it says 'PUTYOURCIKHERE'. (inside of the quotes) | ||
4) On your portal, add two data sources. This script does not auto-create the data sources. | ||
Data Source 1 should be called 'message', type is string, resource is 'message' | ||
Data Source 2 should be called 'number', type is integer, resource is 'number' | ||
5) Run this python script in Python 2.6.5 or higher. | ||
6) Assuming your computer has an active network connection, you should see data sent to | ||
these data sources on your portal. The script runs only once. It should also print out | ||
what it sent, since it is doing a 'read' after the 'write'. | ||
""" | ||
|
||
import urllib | ||
import httplib | ||
|
||
cik = 'PUTYOURCIKHERE' | ||
server = 'm2.exosite.com' | ||
SHOW_DEBUG = 0 #Set to 1 for verbose debug output of connection or set to 0 to disable | ||
|
||
print '========================================================================' | ||
print 'HTTP REST API DEMO. Using CIK ', cik | ||
if SHOW_DEBUG == 1: | ||
print 'DEBUG CONNECTION OUTPUT ENABLED' | ||
print '========================================================================' | ||
print '\r\n' | ||
|
||
http_port = 80 | ||
url = '/api:v1/stack/alias' | ||
params = urllib.urlencode({'message': 'hello world!', 'number': 1 }) #Dataport have alias 'message' and 'number' | ||
headers = {'X-Exosite-CIK': cik, 'content-type': 'application/x-www-form-urlencoded; charset=utf-8'} | ||
|
||
|
||
print '==================' | ||
print 'POST' | ||
print '==================' | ||
print 'Server:', server | ||
print 'Port:', http_port | ||
print 'URL: ', url | ||
print 'Data: ', params | ||
print ' ' | ||
conn = httplib.HTTPConnection(server,http_port) | ||
|
||
if SHOW_DEBUG == 1: | ||
conn.set_debuglevel(1) | ||
print 'DEBUG OUTPUT:' | ||
print '------------------------' | ||
print '--DEBUG MESSAGE OUTPUT--' | ||
|
||
conn.request("POST",url,params,headers) | ||
|
||
if SHOW_DEBUG == 1: | ||
print '--DEBUG RESPONSE OUTPUT--' | ||
|
||
response = conn.getresponse(); | ||
|
||
if SHOW_DEBUG == 1: | ||
print '------------------------' | ||
|
||
print 'response: ',response.status,response.reason | ||
data = response.read() #Expected Resposne is 204 No Content (since you are writing data, nothing to return) | ||
end = data.find('<') | ||
if -1 == end: end = len(data) | ||
print '(Note: You should see a response of "204 No Content" if this works correctly)' | ||
conn.close() | ||
|
||
print '\r\n\r\n' | ||
url = '/api:v1/stack/alias?message&number' | ||
headers = {'Accept':'application/x-www-form-urlencoded; charset=utf-8','X-Exosite-CIK':cik} | ||
print '==================' | ||
print 'GET' | ||
print '==================' | ||
print 'Server:', server | ||
print 'Port:', http_port | ||
print 'URL: ', url | ||
print ' ' | ||
|
||
conn = httplib.HTTPConnection(server,http_port) | ||
|
||
if SHOW_DEBUG == 1: | ||
conn.set_debuglevel(1) | ||
print 'DEBUG OUTPUT:' | ||
print '------------------------' | ||
print '--DEBUG MESSAGE OUTPUT--' | ||
|
||
conn.request("GET",url,"",headers) | ||
|
||
if SHOW_DEBUG == 1: | ||
print '--DEBUG RESPONSE OUTPUT--' | ||
|
||
response = conn.getresponse(); | ||
|
||
if SHOW_DEBUG == 1: | ||
print '------------------------' | ||
|
||
print 'response: ',response.status,response.reason | ||
data = response.read() | ||
print 'response data:', urllib.unquote(data) | ||
|
||
|
||
conn.close() | ||
|
||
print '\r\n' | ||
print '\r\n' | ||
|
||
print '========================================================================' | ||
print 'HTTPS REST API DEMO. Using CIK ', cik | ||
if SHOW_DEBUG == 1: | ||
print 'DEBUG CONNECTION OUTPUT ENABLED' | ||
print '========================================================================' | ||
print '\r\n' | ||
|
||
https_port = 443 | ||
url = '/api:v1/stack/alias' | ||
params = urllib.urlencode({'message': 'hello world!', 'number': 1 }) #Dataport have alias 'message' and 'number' | ||
headers = {'X-Exosite-CIK': cik, 'content-type': 'application/x-www-form-urlencoded; charset=utf-8'} | ||
|
||
|
||
print '==================' | ||
print 'POST' | ||
print '==================' | ||
print 'Server:', server | ||
print 'Port:', https_port | ||
print 'URL: ', url | ||
print 'Data: ', params | ||
print ' ' | ||
conn = httplib.HTTPSConnection(server,https_port) | ||
|
||
if SHOW_DEBUG == 1: | ||
conn.set_debuglevel(1) | ||
print 'DEBUG OUTPUT:' | ||
print '------------------------' | ||
print '--DEBUG MESSAGE OUTPUT--' | ||
|
||
conn.request("POST",url,params,headers) | ||
|
||
if SHOW_DEBUG == 1: | ||
print '--DEBUG RESPONSE OUTPUT--' | ||
|
||
response = conn.getresponse(); | ||
|
||
if SHOW_DEBUG == 1: | ||
print '------------------------' | ||
|
||
print 'response: ',response.status,response.reason | ||
data = response.read() #Expected Resposne is 204 No Content (since you are writing data, nothing to return) | ||
end = data.find('<') | ||
if -1 == end: end = len(data) | ||
print '(Note: You should see a response of "204 No Content" if this works correctly)' | ||
|
||
conn.close() | ||
|
||
print '\r\n\r\n' | ||
url = '/api:v1/stack/alias?message&number' | ||
headers = {'Accept':'application/x-www-form-urlencoded; charset=utf-8','X-Exosite-CIK':cik} | ||
print '==================' | ||
print 'GET' | ||
print '==================' | ||
print 'Server:', server | ||
print 'Port:', https_port | ||
print 'URL: ', url | ||
print ' ' | ||
|
||
conn = httplib.HTTPSConnection(server,https_port) | ||
|
||
if SHOW_DEBUG == 1: | ||
conn.set_debuglevel(1) | ||
print 'DEBUG OUTPUT:' | ||
print '------------------------' | ||
print '--DEBUG MESSAGE OUTPUT--' | ||
|
||
conn.request("GET",url,"",headers) | ||
|
||
if SHOW_DEBUG == 1: | ||
print '--DEBUG RESPONSE OUTPUT--' | ||
|
||
response = conn.getresponse(); | ||
|
||
if SHOW_DEBUG == 1: | ||
print '------------------------' | ||
|
||
print 'response: ',response.status,response.reason | ||
data = response.read() | ||
print 'response data:', urllib.unquote(data) | ||
|
||
|
||
conn.close() | ||
|
Oops, something went wrong.