api: Implement GET /messages.
This commit is contained in:
		
							parent
							
								
									b28cfcac3d
								
							
						
					
					
						commit
						36566c26c1
					
				
					 2 changed files with 43 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -686,6 +686,17 @@ class Client(object):
 | 
			
		|||
                callback(event['message'])
 | 
			
		||||
        self.call_on_each_event(event_callback, ['message'])
 | 
			
		||||
 | 
			
		||||
    def get_messages(self, message_filters):
 | 
			
		||||
        # type: (Dict[str, Any]) -> Dict[str, Any]
 | 
			
		||||
        '''
 | 
			
		||||
            See examples/get-messages for example usage
 | 
			
		||||
        '''
 | 
			
		||||
        return self.call_endpoint(
 | 
			
		||||
            url='messages',
 | 
			
		||||
            method='GET',
 | 
			
		||||
            request=message_filters
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def send_message(self, message_data):
 | 
			
		||||
        # type: (Dict[str, Any]) -> Dict[str, Any]
 | 
			
		||||
        '''
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										32
									
								
								zulip/zulip/examples/get-messages
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								zulip/zulip/examples/get-messages
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
#!/usr/bin/env python
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
 | 
			
		||||
import argparse
 | 
			
		||||
 | 
			
		||||
import zulip
 | 
			
		||||
 | 
			
		||||
usage = """ get-messages (--anchor <message_id> | --use-first-unread-anchor) \
 | 
			
		||||
--num-before <amount> --num-after <amount> [--narrow <narrow_dict>]
 | 
			
		||||
 | 
			
		||||
Example: get-messages --anchor=42 --num-before=3 --num-after=14 --narrow=\
 | 
			
		||||
'[{"operator": "sender", "operand": "iago@zulip.com"}]'
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
 | 
			
		||||
parser.add_argument('--anchor', type=int)
 | 
			
		||||
parser.add_argument('--use-first-unread-anchor', action='store_true')
 | 
			
		||||
parser.add_argument('--num-before', type=int, required=True)
 | 
			
		||||
parser.add_argument('--num-after', type=int, required=True)
 | 
			
		||||
parser.add_argument('--narrow')
 | 
			
		||||
options = parser.parse_args()
 | 
			
		||||
 | 
			
		||||
client = zulip.init_from_options(options)
 | 
			
		||||
 | 
			
		||||
print(client.get_messages({
 | 
			
		||||
    'anchor': options.anchor,
 | 
			
		||||
    'use_first_unread_anchor': options.use_first_unread_anchor,
 | 
			
		||||
    'num_before': options.num_before,
 | 
			
		||||
    'num_after': options.num_after,
 | 
			
		||||
    'narrow': options.narrow,
 | 
			
		||||
}))
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue