def test_resolve_file_arg(self): """ Run the "resolve" method with just a filename and check if all info is loaded. """ test_utils.generate_test_config_file() conf = gnippy_config.resolve({"config_file_path": test_utils.test_config_path}) self.assertEqual(conf['auth'][0], test_utils.test_username) self.assertEqual(conf['auth'][1], test_utils.test_password) self.assertEqual(conf['url'], test_utils.test_powertrack_url)
def __init__(self, callback, **kwargs): c = config.resolve(kwargs) self.callback = callback self.url = c['url'] self.auth = c['auth'] self.worker = None
def delete_rule(rule_dict, **kwargs): """ Synchronously delete a single rule from GNIP PowerTrack. """ conf = config.resolve(kwargs) rules_list = [ rule_dict, ] _delete(conf, rules_list)
def test_resolve_conf_from_environment_variables(self): """ Run the "resolve" method providing env vars and check if all info is loaded. """ test_utils.delete_test_config() test_utils.set_environment_config_vars() conf = gnippy_config.resolve({}) self.assertEqual(conf['url'], test_utils.test_powertrack_url) self.assertEqual(conf['auth'][0], test_utils.test_username) self.assertEqual(conf['auth'][1], test_utils.test_password)
def add_rule(rule_string, tag=None, **kwargs): """ Synchronously add a single rule to GNIP PowerTrack. """ conf = config.resolve(kwargs) rule = build(rule_string, tag) rules_list = [ rule, ] _post(conf, rules_list)
def test_resolve_file_arg(self): """ Run the "resolve" method with just a filename and check if all info is loaded. """ test_utils.generate_test_config_file() conf = gnippy_config.resolve( {"config_file_path": test_utils.test_config_path}) self.assertEqual(conf['auth'][0], test_utils.test_username) self.assertEqual(conf['auth'][1], test_utils.test_password) self.assertEqual(conf['url'], test_utils.test_powertrack_url)
def test_resolve_conf_from_kwargs2(self): """ Run the "resolve" method providing kwargs and check if all info is loaded. """ test_utils.delete_test_config() url = 'http://gnip.url' username = '******' password = '******' conf = gnippy_config.resolve({ 'url': url, 'auth': (username, password) }) self.assertEqual(conf['url'], url) self.assertEqual(conf['auth'][0], username) self.assertEqual(conf['auth'][1], password)
def get_rules(**kwargs): """ Get all the rules currently applied to PowerTrack. Optional Args: url: Specify this arg if you're working with a PowerTrack connection that's not listed in your .gnippy file. auth: Specify this arg if you want to override the credentials in your .gnippy file. Returns: A list of currently applied rules in the form: [ { "value": "(Hello OR World) AND lang:en" }, { "value": "Hello", "tag": "mytag" } ] """ conf = config.resolve(kwargs) rules_url = _generate_rules_url(conf['url']) def fail(reason): raise RulesGetFailedException( "Could not get current rules for '%s'. Reason: '%s'" % (rules_url, reason)) try: r = requests.get(rules_url, auth=conf['auth']) except Exception as e: fail(str(e)) if r.status_code not in range(200, 300): fail("HTTP Status Code: %s" % r.status_code) try: rules_json = r.json() except: fail("GNIP API returned malformed JSON") if "rules" in rules_json: return rules_json['rules'] else: fail("GNIP API response did not return a rules object")
def get_rules(**kwargs): """ Get all the rules currently applied to PowerTrack. Optional Args: url: Specify this arg if you're working with a PowerTrack connection that's not listed in your .gnippy file. auth: Specify this arg if you want to override the credentials in your .gnippy file. Returns: A list of currently applied rules in the form: [ { "value": "(Hello OR World) AND lang:en" }, { "value": "Hello", "tag": "mytag" } ] """ conf = config.resolve(kwargs) rules_url = _generate_rules_url(conf['url']) def fail(reason): raise RulesGetFailedException("Could not get current rules for '%s'. Reason: '%s'" % (rules_url, reason)) try: r = requests.get(rules_url, auth=conf['auth']) except Exception as e: fail(str(e)) if r.status_code not in range(200,300): fail("HTTP Status Code: %s" % r.status_code) try: rules_json = r.json() except: fail("GNIP API returned malformed JSON") if "rules" in rules_json: return rules_json['rules'] else: fail("GNIP API response did not return a rules object")
def __init__(self, callback, exception_callback=None, **kwargs): self.callback = callback self.exception_callback = exception_callback c = config.resolve(kwargs) self.url = c['url'] self.auth = c['auth']
def add_rules(rules_list, **kwargs): """ Synchronously add multiple rules to GNIP PowerTrack in one go. """ conf = config.resolve(kwargs) _post(conf, rules_list)
def add_rule(rule_string, tag=None, **kwargs): """ Synchronously add a single rule to GNIP PowerTrack. """ conf = config.resolve(kwargs) rule = build(rule_string, tag) rules_list = [rule,] _post(conf, rules_list)
def delete_rules(rules_list, **kwargs): """ Synchronously delete multiple rules from GNIP PowerTrack. """ conf = config.resolve(kwargs) _delete(conf, rules_list)
def delete_rule(rule_dict, **kwargs): """ Synchronously delete a single rule from GNIP PowerTrack. """ conf = config.resolve(kwargs) rules_list = [rule_dict,] _delete(conf, rules_list)