Skip to content

Commit

Permalink
adding update summary field related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldchin committed Oct 28, 2021
1 parent 0c765e0 commit 2f371a6
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/Resources/Sheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ public function addColumn(array $column)
return $this->addColumns([$column]);
}

public function addColumns(array $column)
public function addColumns(array $columns)
{
return $this->client->post("sheets/$this->id/columns", [
'json' => $column
'json' => $columns
]);
}

Expand All @@ -358,6 +358,32 @@ public function addSummaryField(String $title, String $formula, String $type = '
);
}

public function updateSummaryFieldByName(String $fieldName, array $summaryFieldDefinition)
{
$summaryField = $this->getSummaryFieldByName($fieldName);
$summaryFieldDefinition['id'] = $summaryField->id;

return $this->updateSummaryField($summaryFieldDefinition);
}

public function updateSummaryField(array $summaryField)
{
return $this->updateSummaryFields([$summaryField]);
}

public function updateSummaryFields(array $summaryFields)
{
return $this->client->put("sheets/$this->id/summary/fields",
['json' => [...$summaryFields]]
);
}

public function getSummaryFieldByName(String $fieldName)
{
return collect($this->getSummaryFields()->fields)
->first(fn ($field) => $field->title == $fieldName);
}

public function getSummaryFields()
{
return $this->client->get("sheets/$this->id/summary");
Expand Down

0 comments on commit 2f371a6

Please sign in to comment.