Temporal v0.2.2 Temporal.Storage View Source

Save and retrieve downloaded data from third party APIs

Link to this section 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

Link to this section Functions

Link to this function exists?(basedir, frequency, source) View Source

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
Link to this function get(basedir, frequency, source) View Source

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}

Ensure the directory is available for saving

Link to this function path(basedir, frequency, source) View Source

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"
Link to this function save(response, basedir, frequency, source) View Source

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) “”