 defmodule IpfsElixir.Api do
 
-    ## TODO: add (add_cmd, block, bootstrap, config, dag, dht, diag, dns, 
-    ## files, id, key, log, mount, name, object, pin, ping, p2p, pubsub, 
+    ## TODO: add (add_cmd, block, bootstrap, config, dag, dht, diag, dns,
+    ## files, id, key, log, mount, name, object, pin, ping, p2p, pubsub,
     ## bitswap, filestore, shutdown, refs, repo, resolve, stats, tar, file)
 
     import IpfsConnection
-    
+
     ## TODO: add get_cmd for output, archive, compress and compression level
     def get_cmd(multihash) when is_bitstring(multihash) do
         requests("/get?arg=", multihash)
-        ##TODO add optional file writing funcitonality. 
+        ##TODO add optional file writing funcitonality.
     end
+
+    # starts the ipfs daemon. TODO: Make this asynchronous. 
+    def start do
+        System.cmd("ipfs", ["daemon"])
+    end
+
+    
 
     def cat_cmd(multihash) when is_bitstring(multihash) do
         requests("/cat?arg=", multihash)

        res.body
    end

    #Ls cmd TODO  Implement proper Json Format. 
    def ls_cmd(multihash) when is_bitstring(multihash) do
        requests("/ls?arg=", multihash)
    end
    
    ##Currently throws an error due to the size of JSON response. 
    def repo_verify do
        requests("/repo/verify", "")
    end

    #Update function  - takes in the current args for update. 
    def update(args) when is_bitstring(args) do
        res = requests("/update?arg=", args)
        res.body|> String.replace(~r/\r|\n/, "")
    end

    #version function - does not currently accept the optional arguments on golang client. 
    def version(num \\ false, comm \\ false, repo \\ false, all \\ false) do
       res = requests("/version?number=" <> to_string(num) <> "&commit=" <> to_string(comm) <> "&repo=" <> to_string(repo) <> "&all=" <> to_string(all) , "")
       res.body

                String.valid?(w) ->
                    r <> w
                true ->
                    << parsed :: 8 >> = w
                    r <> << parsed :: utf8 >>
            end
        end)
