OpenCPU client to interact with a OpenCPU server, see https://www.opencpu.org/.
Almosts exactly mimics the behaviour of the Ruby opencpu gem (https://github.com/roqua/opencpu).
If available in Hex, the package can be installed
by adding opencpu
to your list of dependencies in mix.exs
:
def deps do
[{:opencpu, "~> 0.1.0"}]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/opencpu.
Create an entry in your config/config.exs
for :opencpu
with at least an endpoint_url, the rest of the configuration is optional: Set username
and password
to use http basic auth for each request.
# basics
config :opencpu,
endpoint_url: "https://public.opencpu.org/ocpu",
verify_ssl: true,
timeout: 5
# use http basic auth
config :opencpu,
endpoint_url: "https://public.opencpu.org/ocpu",
username: "username",
password: "password",
verify_ssl: true,
timeout: 5
Execute a request on the OpenCPU server:
OpenCPU.Client.execute(:animation, "flip.coin")
# %{"freq" => [0.56, 0.44], "nmax" => [50]}
Prepare and use a delayed calculation to retreive a plot/graphic, supported formats are :png
and :svg
:
delayed_calculation = OpenCPU.Client.prepare("animation", "flip.coin")
OpenCPU.DelayedCalculation.graphics(delayed_calculation, 0, :png)
# Returns the PNG file contents