Google\Spreadsheet\ListFeed::insert PHP Method

insert() public method

Insert a new row into this feed
public insert ( array $row ) : void
$row array
return void
    public function insert($row)
    {
        $entry = new \SimpleXMLElement("\n            <entry\n                xmlns=\"http://www.w3.org/2005/Atom\"\n                xmlns:gsx=\"http://schemas.google.com/spreadsheets/2006/extended\">\n            </entry>\n        ");
        foreach ($row as $colName => $value) {
            $entry->addChild("xmlns:gsx:{$colName}", $value);
        }
        ServiceRequestFactory::getInstance()->post($this->getPostUrl(), $entry->asXML());
    }

Usage Example

 public function testInsert()
 {
     $mockServiceRequest = $this->getMockBuilder('Google\\Spreadsheet\\DefaultServiceRequest')->setMethods(array("post"))->disableOriginalConstructor()->getMock();
     $mockServiceRequest->expects($this->once())->method('post')->with($this->equalTo('https://spreadsheets.google.com/feeds/list/G3345eEsfsk60/od6/private/full'), $this->stringContains('<gsx:occupation><![CDATA[software engineer]]></gsx:occupation>'));
     ServiceRequestFactory::setInstance($mockServiceRequest);
     $listFeed = new ListFeed(file_get_contents(__DIR__ . '/xml/list-feed.xml'));
     $listFeed->insert(["name" => "asim", "occupation" => "software engineer"]);
 }