Temporal v0.1.3 Temporal.Storage
Save and retrieve downloaded data from third party APIs
Summary
Functions
Has the data been saved yet?
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated
Retrieve data the data that we saved.
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated
Ensure the directory is available for saving
Calculate a unique path for the source being fetched. If you provide a basedir it will use that as a prefix
Save the data that was fetched from the interwebs.
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated
Determine if it’s time to perform your operation
Functions
Has the data been saved yet?
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated.
Examples
iex> File.write!("/tmp/apples.txt", "apples") && Temporal.Storage.exists?("/tmp/apples.txt")
true
iex> Temporal.Storage.exists?("/tmp/bananas.txt")
false
Retrieve data the data that we saved.
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated.
Examples
iex> File.write!("/tmp/apples.txt", "apples") && Temporal.Storage.get("/tmp/apples.txt")
{:ok, "apples"}
iex> Temporal.Storage.get("/tmp/bananas.txt")
{:error, :enoent}
Calculate a unique path for the source being fetched. If you provide a basedir it will use that as a prefix.
Examples
iex> Temporal.Storage.path("https://my.a4word.com/webfiles/x.txt")
"my.a4word.com/webfiles/x.txt"
iex> Temporal.Storage.path("https://www.dividata.com/stock/MMM")
"www.dividata.com/stock/mmm"
iex> Temporal.Storage.path("https://tsx.exdividend.ca/s/?q=T")
"tsx.exdividend.ca/s/query__q_eq_t"
iex> Temporal.Storage.path("https://tsx.exdividend.ca/s/lookup?q=T")
"tsx.exdividend.ca/s/lookup/query__q_eq_t"
iex> Temporal.Storage.path("http://www.nasdaq.com/symbol/aapl/dividend-history")
"www.nasdaq.com/symbol/aapl/dividend-history"
iex> Temporal.Storage.path("http://download.finance.yahoo.com/d/quotes.csv?s=T.TO&f=sod1ax")
"download.finance.yahoo.com/d/quotes.csv/query__s_eq_t.to_and_f_eq_sod1ax"
iex> Temporal.Storage.path("/tmp/", :once, "https://my.a4word.com/webfiles/x.txt")
"/tmp/my.a4word.com/webfiles/x.txt"
iex> Temporal.Storage.path("/tmp/", "2017", "https://my.a4word.com/webfiles/x.txt")
"/tmp/2017/my.a4word.com/webfiles/x.txt"
iex> Temporal.Storage.path("/tmp/abc", "2018", "https://my.a4word.com/webfiles/x.txt")
"/tmp/abc/2018/my.a4word.com/webfiles/x.txt"
Save the data that was fetched from the interwebs.
You can either provide the path directly, or use the
combination of basedir
, frequency
and source
to
have it calculated.
Examples
iex> Temporal.Storage.save({:ok, "apples"}, "/tmp/abc/apples.txt")
{:ok, "/tmp/abc/apples.txt"}
iex> Temporal.Storage.save({:error, "Broken"}, "/tmp/abc/apples.txt")
{:error, "Broken"}
Determine if it’s time to perform your operation.
Examples
iex> Temporal.Storage.timestamp(~N[2016-05-24 13:26:08.003], :yearly) “2016”
iex> Temporal.Storage.timestamp(~N[2016-05-24 13:26:08.003], :monthly) “201605”
iex> Temporal.Storage.timestamp(~N[2016-05-09 13:26:08.003], :daily) “20160509”
iex> Temporal.Storage.timestamp(~N[2016-05-09 13:26:08.003], :hourly) “2016050913”
iex> Temporal.Storage.timestamp(~N[2016-05-09 13:26:08.003], :once) “”