Skip to content

Commit

Permalink
Merge pull request #1 from t27/master
Browse files Browse the repository at this point in the history
Added support for handling ConnectionError.

Thx for the commit.
  • Loading branch information
bliti committed Apr 15, 2014
2 parents 2629dfd + 18f2ded commit 3b40974
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions dweet.py
@@ -1,6 +1,6 @@
import requests


#A Class for using the Dweet.io servers for data communication between devices
class Dweet(object):

#dweet root domain and endpoints
Expand Down Expand Up @@ -37,7 +37,10 @@ def dweet(self, data):
is turned into:
/dweet?foo=bar
"""
return requests.get(self.DWEET, params=data).json()
try:
return requests.get(self.DWEET, params=data).json()
except requests.exceptions.ConnectionError, e:
raise e


def dweet_by_name(self, name, data):
Expand All @@ -56,9 +59,13 @@ def dweet_by_name(self, name, data):
/{name}?foo=bar
"""
return requests.get(self.DWEET_BY_NAME.format(name=name),
params=data).json()

try:
return requests.get(self.DWEET_BY_NAME.format(name=name),
params=data).json()
except requests.exceptions.ConnectionError, e:
raise e



def latest_dweet(self, name):
"""
Expand All @@ -67,14 +74,21 @@ def latest_dweet(self, name):
Returns dict type.
Parameter name is a string type.
"""
return requests.get(self.LATEST_DWEET.format(name=name)).json()
try:
return requests.get(self.LATEST_DWEET.format(name=name)).json()
except requests.exceptions.ConnectionError, e:
raise e



def all_dweets(self, name):
"""
Get dweets in last 24 hours by thing name.
Dweet limit currently is 500 dweets.
Returns dict type.
Parameter name is a string type.
"""
return requests.get(self.ALL_DWEETS.format(name=name)).json()
"""
Get dweets in last 24 hours by thing name.
Dweet limit currently is 500 dweets.
Returns dict type.
Parameter name is a string type.
"""
try:
return requests.get(self.ALL_DWEETS.format(name=name)).json()
except requests.exceptions.ConnectionError, e:
raise e

0 comments on commit 3b40974

Please sign in to comment.