Skip to content

Commit 5d88f1a

Browse files
committed
Fixes #48 Push implementation of twitter data to push api endpoint
1 parent e353a97 commit 5d88f1a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

loklak.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,34 @@ def peers(self):
133133
return_to_user = {}
134134
return json.dumps(return_to_user)
135135

136+
def push(self, data=None):
137+
"""Push servlet for twitter like messages"""
138+
push_application = 'api/push.json'
139+
url_to_give = self.baseUrl + push_application
140+
headers = {
141+
'User-Agent': ('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0)'
142+
' Gecko/41.0 Firefox/41.0'),
143+
144+
}
145+
if data:
146+
self.data = data
147+
params = {}
148+
params['data'] = json.dumps(self.data)
149+
return_to_user = requests.post(url_to_give, data=params)
150+
if return_to_user:
151+
return return_to_user.json()
152+
else:
153+
return_to_user = {}
154+
return_to_user['error'] = ('Something went wrong,'
155+
' looks like the query is wrong.')
156+
return json.dumps(return_to_user)
157+
else:
158+
return_to_user = {}
159+
return_to_user['error'] = ('Something went wrong,'
160+
' looks like the data is not correct.')
161+
return json.dumps(return_to_user)
162+
163+
136164
def user(self, name=None, followers=None, following=None):
137165
"""User information, including who they are following, and
138166
who follows them"""

tests/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ def test_peers(self):
7777
self.assertTrue(len(result['peers']) >= 1)
7878
self.assertEqual(len(result['peers']), result['count'])
7979

80+
def test_push(self):
81+
"""Test for push data to index"""
82+
data={ "statuses": [ { "id_str": "yourmessageid_1234", "screen_name": "testuser", "created_at": "2016-07-22T07:53:24.000Z", "text": "The rain is spain stays always in the plain", "source_type": "GENERIC", "place_name": "Georgia, USA", "location_point": [3.058579854228782,50.63296878274201], "location_radius": 0, "user": { "user_id": "youruserid_5678", "name": "Mr. Bob", } } ] }
83+
result = self.loklak.push(data)
84+
self.assertTrue('status' in result)
85+
8086
def test_user(self):
8187
"""test user"""
8288
result = self.loklak.user('dhruvRamani98')

0 commit comments

Comments
 (0)