GoogleSheets

Main starting point of the application and public API for library. For introduction on how to configure and use the library, see README.

Summary

Functions

Fetches previously loaded spreadsheet data from ETS matching the given version and returns it as a {:ok, data} tuple

Fetches previously loaded spreadsheet data from ETS matching the given version. KeyError is raised if no spreadsheet data is found with the given version

Returns true, if there is a version stored for the spreadsheet identified by spreadsheet_id argument

Returns {:ok, version, data} tuple for the latest stored version for the spreadsheet identified by spreadsheet_id argument. If there is no version available, :not_found is returned

Returns {version, data} tuple for the latest stored version for the spreadsheet identified by spreadsheet_id argument. If no version is found, KeyError exception is raised

Returns {:ok, data} tuple for the latest stored entry for the spreadsheet identified by spreadsheet_id argument. If no entry is found, :not_found is returned

Returns the latest stored entry for the spreadsheet identified by spreadsheet_id argument. If no entry is found, KeyError exception is raised

Returns {:ok, version} tuple or the latest stored version for the spreadsheet identified by spreadsheet_id argument. If no version is found, :not_found is returned

Returns the latest version stored for the spreadsheet identified by spreadsheet_id argument. If no version is found, KeyError exception is raised

Manually triggers an update for fetching new data for the given spreadsheet_id argument

To support storing custom version into ETS table. Required use case for this is to support validation of parsed configuration before it's stored when using APIs which expect a version to be passed as parameter

To remove a spcific version from ETS table

Functions

fetch(version)

Specs

fetch(term) :: {:ok, term} | :not_found

Fetches previously loaded spreadsheet data from ETS matching the given version and returns it as a {:ok, data} tuple.

Examples

iex> GoogleSheets.fetch "fccb56afd7d7f1cdf457e8b9b841ec75"
{:ok, [
  %GoogleSheets.WorkSheet{
    csv: "Key,Value\r\nInteger,1\r\nFloat,1.1\r\nString,string",
    name: "KeyValue"
  }]
}

iex> GoogleSheets.fetch "not_a_valid_version"
:not_found
fetch!(version)

Specs

fetch!(term) :: term | no_return

Fetches previously loaded spreadsheet data from ETS matching the given version. KeyError is raised if no spreadsheet data is found with the given version.

Examples

iex> GoogleSheets.fetch! "fccb56afd7d7f1cdf457e8b9b841ec75"
[%GoogleSheets.WorkSheet{
  csv: "Key,Value\r\nInteger,1\r\nFloat,1.1\r\nString,string",
  name: "KeyValue"}
]

iex> GoogleSheets.fetch! "not_a_valid_version"
** (KeyError) key "not_a_valid_version" not found
has_version?(spreadsheet_id)

Specs

has_version?(atom) :: boolean

Returns true, if there is a version stored for the spreadsheet identified by spreadsheet_id argument.

latest(spreadsheet_id)

Specs

latest(atom) :: {:ok, term, term} | :not_found

Returns {:ok, version, data} tuple for the latest stored version for the spreadsheet identified by spreadsheet_id argument. If there is no version available, :not_found is returned.

latest!(spreadsheet_id)

Specs

latest!(atom) :: {term, term} | no_return

Returns {version, data} tuple for the latest stored version for the spreadsheet identified by spreadsheet_id argument. If no version is found, KeyError exception is raised.

latest_data(spreadsheet_id)

Specs

latest_data(atom) :: {:ok, term} | :not_found

Returns {:ok, data} tuple for the latest stored entry for the spreadsheet identified by spreadsheet_id argument. If no entry is found, :not_found is returned.

latest_data!(spreadsheet_id)

Specs

latest_data!(atom) :: term | no_return

Returns the latest stored entry for the spreadsheet identified by spreadsheet_id argument. If no entry is found, KeyError exception is raised.

latest_version(spreadsheet_id)

Specs

latest_version(atom) :: {:ok, term} | :not_found

Returns {:ok, version} tuple or the latest stored version for the spreadsheet identified by spreadsheet_id argument. If no version is found, :not_found is returned.

latest_version!(spreadsheet_id)

Specs

latest_version!(atom) :: term | no_return

Returns the latest version stored for the spreadsheet identified by spreadsheet_id argument. If no version is found, KeyError exception is raised.

update(spreadsheet_id, timeout \\ 60000)

Specs

update(atom, integer) ::
  {:updated, term} |
  :unchanged |
  {:error, term} |
  no_return

Manually triggers an update for fetching new data for the given spreadsheet_id argument.

Return values:

  • {:updated, version} - Spreadsheet was updated and stored with the version
  • :unchanged - Spreadsheet contents haven't been changed since last update.
  • {:error, reason} - The update failed because of reason.
version_add(id, version, data)

Specs

version_add(atom, term, term) :: :ok

To support storing custom version into ETS table. Required use case for this is to support validation of parsed configuration before it's stored when using APIs which expect a version to be passed as parameter.

Examples

iex> GoogleSheets.version_add :config, "add-test-configuration", %{data: "test-data"}
iex> GoogleSheets.fetch "add-test-configuration"
{:ok, %{data: "test-data"}}
version_remove(version)

Specs

version_remove(term) :: :ok

To remove a spcific version from ETS table.

Examples

iex> GoogleSheets.version_add :config, "remove-test-configuration", %{data: "test-data"}
iex> GoogleSheets.version_remove "remove-test-configuration"
true