Ejemplo n.º 1
0
 function xtestGetCurrentActivities()
 {
     $a = new Services_Gnip_Activity('2008-07-02T11:16:16+00:00', 'upload', 'sally', 'blog_post', 'web', 'trains,planes,automobiles', 'bob', 'http://example.com');
     $this->helper->expect('get', '/publishers/digg/activity/current.xml', array('and_return' => "<activities>" . $a->toXML() . "</activities>"));
     $activities = $this->gnip->getPublisherActivities(new Services_Gnip_Publisher('digg', array()));
     $this->assertEquals($a, $activities[0]);
 }
Ejemplo n.º 2
0
 /**
  * Test the ability to create a Gnip activity (with an XML document),
  * and compare against identical values in strings.
  *
  * @access    public
  * @param     void
  * @return    void
  */
 function testFromXml()
 {
     $xml = '<activity at="2008-07-02T11:16:16+00:00" action="upload" actor="sally" ' . 'regarding="blog_post" source="web" tags="trains,planes,automobiles" ' . 'to="bob" url="http://example.com"/>';
     $a = Services_Gnip_Activity::fromXML(new SimpleXMLElement($xml));
     $expected_tags = array("trains", "planes", "automobiles");
     $this->assertEquals("2008-07-02T11:16:16+00:00", $a->at->format(DATE_ATOM));
     $this->assertEquals("upload", $a->action);
     $this->assertEquals("sally", $a->actor);
     $this->assertEquals("blog_post", $a->regarding);
     $this->assertEquals("web", $a->source);
     $this->assertEquals($expected_tags, $a->tags);
     $this->assertEquals("http://example.com", $a->url);
 }
Ejemplo n.º 3
0
 /**
  * Parse an XML stream containing publisher or filter activities.
  *
  * @access    private
  * @param     string       $xml          contains xml to be parsed
  * @return    array                      publisher or filter activites
  */
 private function parseActivities($xml)
 {
     $xml = new SimpleXMLElement($xml);
     $activities = array();
     foreach ($xml->children() as $child) {
         $activities[] = Services_Gnip_Activity::fromXML($child);
     }
     return $activities;
 }
Ejemplo n.º 4
0
 /**
  * Converts XML formatted activity to Services_Gnip_Activity object.    
  * 
  * @param string $xml XML data
  * @return object Services_Gnip_Activity
  */
 public static function fromXML($xml)
 {
     $xml_element = new SimpleXMLElement($xml);
     $found_at = strval($xml_element->at);
     $found_action = strval($xml_element->action);
     $found_activityID = strval($xml_element->activityID);
     $found_URL = strval($xml_element->URL);
     $found_source = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('source'), 'source');
     $found_keyword = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('keyword'), 'keyword');
     $place_result = $xml_element->xpath('place');
     if (array_key_exists(0, $place_result)) {
         foreach ($place_result as $k => $v) {
             $found_place[] = Services_Gnip_Place::fromXML($v->asXML());
         }
     } else {
         $found_place = null;
     }
     $found_actor = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('actor'), 'actor', array('metaURL', 'uid'));
     $found_destinationURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('destinationURL'), 'destinationURL', array('metaURL'));
     $found_tag = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('tag'), 'tag', array('metaURL'));
     $found_to = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('to'), 'to', array('metaURL'));
     $found_regardingURL = Services_Gnip_Activity::getUnboundXML($xml_element->xpath('regardingURL'), 'regardingURL', array('metaURL'));
     $payload_result = $xml_element->xpath('payload');
     if (array_key_exists(0, $payload_result)) {
         foreach ($payload_result as $k => $v) {
             $found_payload = Services_Gnip_Payload::fromXML($v->asXML());
         }
     } else {
         $found_payload = null;
     }
     return new Services_Gnip_Activity(new DateTime($found_at), $found_action, $found_activityID, $found_URL, $found_source, $found_keyword, $found_place, $found_actor, $found_destinationURL, $found_tag, $found_to, $found_regardingURL, $found_payload);
 }
Ejemplo n.º 5
0
 /**
  * Test the ability to get the activities for a Gnip publisher.
  *
  * @access    public
  * @param     void
  * @return    void
  */
 function testGetCurrentActivities()
 {
     $a = new Services_Gnip_Activity("2008-07-02T11:16:16+00:00", "upload", "sally", "blog_post", "web", "trains,planes,automobiles", "bob", "http://example.com");
     $this->helper->expect("get", "/publishers/digg/activity/current.xml", array("and_return" => "<activities>" . $a->toXML() . "</activities>"));
     $activities = $this->gnip->getPublisherActivities(new Services_Gnip_Publisher("digg"));
     $this->assertEquals($a, $activities[0]);
 }
Ejemplo n.º 6
0
 function testFromXMLWithPayloadUnboundMediaURL()
 {
     $xml = '<activity>' . '<at>2008-07-02T11:16:16+00:00</at>' . '<action>post</action>' . '<payload><title>title</title><body>body</body><mediaURL type="image" mimeType="image/png">http://www.flickr.com/tour</mediaURL><mediaURL type="movie" mimeType="video/quicktime">http://www.gnipcentral.com/login</mediaURL><raw>H4sIAAAAAAAAAytKLAcAVduzGgMAAAA=</raw></payload>' . '</activity>';
     $a = Services_Gnip_Activity::fromXML($xml);
     $this->assertEquals($this->at, $a->at->format(DATE_ATOM));
     $this->assertEquals($this->action, $a->action);
     $this->assertEquals($this->payloadArray, $a->payload);
 }