Ejemplo n.º 1
0
    def test_app_stream(self):
        app_access_token, token = get_app_access_token(self.client_id, self.client_secret)
        self.api.add_authorization_token(app_access_token)
        # Reset
        self.api.delete_all_streams()

        stream_def = {
            "object_types": [
                "post"
            ],
            "type": "long_poll",
            "key": "rollout_stream"
        }

        app_stream, meta = self.api.create_stream(data=stream_def)
        app_stream, meta = self.api.get_stream(app_stream)

        stream_def['object_types'] += ["star"]

        app_stream, meta = self.api.update_stream(app_stream, data=stream_def)
        self.assertEquals(len(app_stream.object_types), 2)
        app_stream, meta = self.api.delete_stream(app_stream)
        app_stream, meta = self.api.create_stream(data=stream_def)
        stream_def['key'] = "rollout_stream_2"
        app_stream, meta = self.api.create_stream(data=stream_def)
        app_streams, meta = self.api.get_streams()
        self.assertEquals(len(app_streams), 2)
        app_streams, meta = self.api.delete_all_streams()
        app_streams, meta = self.api.get_streams()
        self.assertEquals(len(app_streams), 0)
Ejemplo n.º 2
0
    def test_app_stream(self):
        app_access_token, token = get_app_access_token(self.client_id,
                                                       self.client_secret)
        self.api.add_authorization_token(app_access_token)
        # Reset
        self.api.delete_all_streams()

        stream_def = {
            "object_types": ["post"],
            "type": "long_poll",
            "key": "rollout_stream"
        }

        app_stream, meta = self.api.create_stream(data=stream_def)
        app_stream, meta = self.api.get_stream(app_stream)

        stream_def['object_types'] += ["star"]

        app_stream, meta = self.api.update_stream(app_stream, data=stream_def)
        self.assertEquals(len(app_stream.object_types), 2)
        app_stream, meta = self.api.delete_stream(app_stream)
        app_stream, meta = self.api.create_stream(data=stream_def)
        stream_def['key'] = "rollout_stream_2"
        app_stream, meta = self.api.create_stream(data=stream_def)
        app_streams, meta = self.api.get_streams()
        self.assertEquals(len(app_streams), 2)
        app_streams, meta = self.api.delete_all_streams()
        app_streams, meta = self.api.get_streams()
        self.assertEquals(len(app_streams), 0)
Ejemplo n.º 3
0
import os

import adnpy
from adnpy.stream import Stream, StreamListener
from adnpy.utils import get_app_access_token

client_id = os.environ.get('ADN_TEST_APP_CLIENT_ID')
client_secret = os.environ.get('ADN_TEST_CLIENT_SECRET')

app_access_token, token = get_app_access_token(client_id, client_secret)

# Define a stream
stream_def = {
    "object_types": [
        "post"
    ],
    "type": "long_poll",
    "key": "post_stream"
}


# Create a stream
class MyStreamListener(StreamListener):
    def on_post(self, post, meta):
        if meta.is_deleted:
            return

        print(post.text)

my_api = adnpy.API.build_api(access_token=app_access_token)
stream = Stream(my_api, stream_def, MyStreamListener)
Ejemplo n.º 4
0
import os

import adnpy
from adnpy.stream import Stream, StreamListener
from adnpy.utils import get_app_access_token

client_id = os.environ.get('ADN_TEST_APP_CLIENT_ID')
client_secret = os.environ.get('ADN_TEST_CLIENT_SECRET')

app_access_token, token = get_app_access_token(client_id, client_secret)

# Define a stream
stream_def = {
    "object_types": ["post"],
    "type": "long_poll",
    "key": "post_stream"
}


# Create a stream
class MyStreamListener(StreamListener):
    def on_post(self, post, meta):
        if meta.is_deleted:
            return

        print post.text


my_api = adnpy.API.build_api(access_token=app_access_token)
stream = Stream(my_api, stream_def, MyStreamListener)
stream.start()