function testGetUrl() { $pubRuleTypes = array(); $filterRules = array(); $publisher = new Services_Gnip_Publisher('name', $pubRuleTypes); $filter = new Services_Gnip_Filter("myFilter", 'false', '', $filterRules); $rule = new Services_Gnip_Rule("actor", "you"); $expected_url = "/publishers/" . $publisher->name . "/filters/" . $filter->name . "/rules.xml"; $this->assertEquals($expected_url, $rule->getUrl($publisher->name, $filter->name)); }
/** * Create new Gnip Publisher -- with XML values -- then validate against returned string values. * * @access public * @param void * @return void */ function testFromXml() { $xml = '<rule type="actor" value="testActor"/>'; $rule = Services_Gnip_Rule::fromXml(new SimpleXMLElement($xml)); $this->assertEquals("actor", $rule->type); $this->assertEquals("testActor", $rule->value); }
/** * Converts XML formatted filter to Services_Gnip_Filter object. * * @param string $xml XML data * @return object Services_Gnip_Filter */ public function fromXML($xml) { $xml_element = new SimpleXMLElement($xml); $f = new Services_Gnip_Filter($xml_element["name"], $xml_element["fullData"]); $f->postURL = strval($xml_element->postURL); foreach ($xml_element->rule as $rule_node) { $f->rules[] = Services_Gnip_Rule::fromXML($rule_node->asXML()); } return $f; }
/** * Gets a rule given an existing valid publisher/filter combination. Used * mostly for verification that the rule does exist. * * @param string $publisherName name of the publisher that contains the filter * @param string $filterName name of filter that contains rules * @param object $rule Service_Gnip_Rule object * @param string $scope publisher scope (my or gnip) default is gnip * @return Service_Gnip_Rule object */ function getRule($publisherName, $filterName, $rule, $scope = "gnip") { $scope = $this->_scopeprep($scope); try { $xml = $this->helper->doHttpGet($scope . $rule->getUrl($publisherName, $filterName) . "?type={$rule->type}&value={$rule->value}"); return Services_Gnip_Rule::fromXML($xml); } catch (Exception $e) { $message = "There was a problem when calling getRule on publisher {$publisherName} and filter {$filterName} with rule type {$rule->type} and value {$rule->value}. Status message: "; $this->_handleDebug($message, $this->debug, $e); } }
/** * Instantiates Services_Gnip_Filter with current class data values * * @access public * @param XMLElement $xml XML Filter * @return Services_Gnip_Filter Services_Gnip_Filter object */ public static function fromXML(SimpleXMLElement $xml) { $f = new Services_Gnip_Filter($xml["name"], $xml["fullData"]); $f->postUrl = strval($xml->postUrl); $f->jid = strval($xml->jid); foreach ($xml->rule as $rule_node) { $f->rules[] = Services_Gnip_Rule::fromXML($rule_node); } return $f; }