temporal

A library to download documents from the interwebs.


License
MIT

Documentation

Temporal

A library to download documents from the interwebs.

Installation

If available in Hex, the package can be installed by adding temporal to your list of dependencies in mix.exs:

@deps [
  {:temporal, "~> 0.2.2"}
]

Documentation can be generated with ExDoc and is published at https://hexdocs.pm/temporal.

Configuration

You can configure the following defaults.

config :temporal,
  basedir: "/tmp",
  frequency: :daily,
  method: :get,
  force: false

The default values are shown above, so only if you don't trust they will remain that way, or if you want something different should you add the configuration to your application. are shown below

Usage

If you want to download a file then you can run

Temporal.download_now(
  %{basedir: "/tmp",
    frequency: :once,
    source: "https://example.com/myfile.txt",
    method: :get})

This will only download the file if you haven't already, if you wanted to force a new download then add force: true, for example

Temporal.download_now(
  %{basedir: "/tmp",
    frequency: :once,
    force: true,
    source: "https://example.com/myfile.txt",
    method: :get})

If you want to schedule the download, say every hour, then call

Temporal.schedule_now(
  %{basedir: "/tmp",
    frequency: :hourly,
    source: "https://example.com/myfile.txt",
    method: :get})

If you want to schedule the download, say every hour, but you do not need to wait for the actual down, then change the call to schedule_later

Temporal.schedule_later(
  %{basedir: "/tmp",
    frequency: :hourly,
    source: "https://example.com/myfile.txt",
    method: :get})

Finally, if you want to be notified when a new file has been downloaded, then you can register callback functions

Temporal.Callback.register(
  fn(params, fname) ->
    IO.puts("NEW FILE DOWNLOADED")
    IO.inspect(params)
    IO.puts("called #{fname}")
  end)

Let's say you had a function (e.g. process) within your module, that conforms to the callback signature, then you can register it directly with

Temporal.Callback.register(&process/2)