示例#1
0
def main():
    """ main function """
    # get options and arguments
    (parser, options, args) = init_parser()

    # initialize result variable
    result = None

    # check for values which are always needed
    if not options.user:
        parser.error("No user given.")
    if not options.secret:
        parser.error("No API secret given.")
    if not options.name:
        parser.error("No recipient given.")

    if not options.message_type:
        options.message_type = "notification"

    if len(args) < 1:
        result = notifo.subscribe_user(options.user, options.secret, options.name)
    else:
        params = {}
        params["to"] = options.name
        m = ''
        for a in args:
            m = "%s %s" %(m, a)
        params["msg"] = m
        
        if options.message_type == "message":
            result = notifo.send_message(options.user, options.secret, **params)
        elif options.message_type == "notification":
            if options.label:
                params["label"] = options.label
            if options.title:
                params["title"] = options.title
            if options.callback:
                params["uri"] = options.callback
            result = notifo.send_notification(options.user,options.secret, **params)


    if result is None:
        print "Something went wrong. Check parameters and try again."
示例#2
0
def main():
    """ main function """
    # get options and arguments
    (parser, options, args) = init_parser()

    # initialize result variable
    result = None

    # check for values which are always needed
    if not options.user:
        parser.error("No user given.")
    if not options.secret:
        parser.error("No API secret given.")
    if not options.name:
        parser.error("No recipient given.")

    # If there is no message, we probably want to subscribe a user
    if len(args) < 1:
        result = notifo.subscribe_user(options.user, options.secret,
                                       options.name)
    else:
        params = {}
        params["to"] = options.name
        m = ''
        for a in args:
            m = "%s %s" % (m, a)
        params["msg"] = m

        if options.message == True:
            result = notifo.send_message(options.user, options.secret,
                                         **params)
        else:
            if options.label:
                params["label"] = options.label
            if options.title:
                params["title"] = options.title
            if options.callback:
                params["uri"] = options.callback
            result = notifo.send_notification(options.user, options.secret,
                                              **params)

    if result is None:
        print "Something went wrong. Check parameters and try again."
示例#3
0
 def test_message_provider_banned(self):
     res = send_message(self.provider_banned, self.provider_banned_token,
                             to=self.user, msg="foo test")
     self.assertEqual(403, res["response_code"])
示例#4
0
 def test_message_provider(self):
     res = send_message(self.provider, self.provider_token,
                             to=self.user, msg="foo test")
     self.assertEqual(2201, res["response_code"])
示例#5
0
 def test_message_with_plain_args(self):
     res = send_message(self.user, self.user_token,
                             self.user, "foo test")
     self.assertEqual(2201, res["response_code"])