Skip to content

Commit

Permalink
Merge pull request #5 from michaeldchin/summaryfield-updates
Browse files Browse the repository at this point in the history
adding update summary field related methods
  • Loading branch information
Trey Foster authored Oct 28, 2021
2 parents 0c765e0 + 2f371a6 commit ee752d0
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 ee752d0

Please sign in to comment.