Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ipfs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ defmodule IPFS do
request(conn, path, &HTTPoison.post(&1, multipart(filename), params: params))
end

@doc """
High level function which allows to send a raw value to the node, say, a JSON encoded value.
"""
@spec post_raw(t, String.t(), String.t(), Sring.t(), keyword) :: result
def post_raw(conn, path, content, filename, params \\ []) do
request(conn, path, &HTTPoison.post(&1, raw_multipart(content, filename), params: params))
end

# Private stuff.

@typep poison_result :: {:ok, Response.t() | AsyncResponse.t()} | {:error, Error.t()}
Expand Down Expand Up @@ -90,6 +98,13 @@ defmodule IPFS do
[{:file, filename, {"form-data", [name: Path.basename(filename), filename: filename]}, []}]}
end

defp raw_multipart(content, name) do
{:multipart,
[
{"file", content, {"form-data", [name: "file", filename: name]}, []}
]}
end

defimpl String.Chars, for: IPFS do
def to_string(%{scheme: scheme, host: host, port: port, base: base}) do
["#{scheme}://#{host}:#{port}", base]
Expand Down
9 changes: 8 additions & 1 deletion lib/ipfs/api.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule IPFS.API do
@moduledoc false

import IPFS, only: [get: 2, get: 3, post_file: 4]
import IPFS, only: [get: 2, get: 3, post_file: 4, post_raw: 5]
import IPFS.Utils, only: [remap_fields: 2, remap_array: 2, successify_with: 1, okify: 1]

@type t :: IPFS.t()
Expand Down Expand Up @@ -101,6 +101,13 @@ defmodule IPFS.API do
|> okify
end

def add_raw(conn, content, name, params \\ []) do
conn
|> post_raw("add", content, name, params)
|> remap_fields(name: "Name", hash: "Hash", size: "Size")
|> okify()
end

# Pinning.

@doc "List all pins registered on this node."
Expand Down