A few things. If you want to add a new layer, the call for it is like the one below (the keyword is Polygon).
va = QgsVectorLayer("Polygon?crs=epsg:4326", "Segment buffers", "memory")
To set geometry to a Polyline, the code is like the following:
line_geometry=QgsGeometry.fromPolyline(QgsPoint(x,y),QgsPoint(w,z),...,QgsPoint(t,r))
The first and last points will be the extremities, while the middle ones will provide the actual shape (curvature) of the line feature
To set geometry to a Polygon, the code is like the following:
polygon_geometry=QgsGeometry.fromPolygon( [[ QgsPoint(x,y), QgsPoint(w,z),..., QgsPoint(p,l) ] ] )
Attributes work just the same for all geometry types. Hope it helps.
For more references, you can look at http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/geometry.html