more queries for link operations added fpr hubic api
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
diff --git a/lib/hubic/hubic_api/auth.ex b/lib/hubic/hubic_api/auth.ex
index 313cddc..1d90c0e 100644
--- a/lib/hubic/hubic_api/auth.ex
+++ b/lib/hubic/hubic_api/auth.ex
@@ -22,7 +22,8 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
config = config(client)
uri = uri(config, uri)
- if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
+ if params !== :nil and params !== "" and is_map(params), do: uri = uri <> "?" <> URI.encode_query(params)
+ if params !== :nil and params !== "" and is_map(params) === :false, do: uri = uri <> URI.encode_www_form(params)
options = %{ headers: headers(method), timeout: @timeout }
{method, uri, options}
end
@@ -31,7 +32,6 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
config = config(client)
uri = uri(config, uri)
if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
- if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
options = %{ body: params, headers: headers(method), timeout: @timeout }
{method, uri, options}
end
@@ -80,7 +80,7 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
defp default_headers(), do: %{ "Authorization": "Bearer " <> Cache.get_token() }
defp headers(method) when method in [:post, :put] do
- Map.merge(default_headers(), %{ "Content-Type": "application/x-www-form-urlencoded" })
+ Map.merge(default_headers(), %{ "Content-Type": "application/json;charset=utf-8" })
end
defp headers(method) when method in [:get, :delete], do: default_headers()
diff --git a/lib/query/hubic/query.ex b/lib/query/hubic/query.ex
index a2ada36..5c4df5f 100644
--- a/lib/query/hubic/query.ex
+++ b/lib/query/hubic/query.ex
@@ -12,6 +12,7 @@ defmodule ExOvh.Query.Hubic do
```
"""
+
#########################
# General Hubic Requests
#########################
@@ -36,20 +37,21 @@ defmodule ExOvh.Query.Hubic do
@spec account_usage() :: ExOvh.Client.raw_query_t
def account_usage(), do: {:get, "/account/usage", :nil}
- ########################################
+
+
+ ########################
# Link related Requests
- ########################################
+ ########################
@doc """
- GET /account/links, Get all links as a list of links
+ GET /account/links, Get all links as a list of links (showing the object internal uri - not the indirectUri)
### Example:
```elixir
import ExOvh.Query.Hubic
- {:ok, resp} = ExOvh.hubic_request(get_links())
- links = resp.body
+ ExOvh.hubic_request(get_links())
```
"""
@spec get_links() :: ExOvh.Client.raw_query_t
@@ -62,15 +64,32 @@ defmodule ExOvh.Query.Hubic do
### Example:
```elixir
import ExOvh.Query.Hubic
- ExOvh.hubic_request(get_published_links_detailed())
+ ExOvh.hubic_request(get_links_detailed())
```
"""
- @spec get_published_links_detailed() :: ExOvh.Client.raw_query_t
- def get_published_links_detailed(), do: {:get, "/account/getAllLinks", :nil}
+ @spec get_links_detailed() :: ExOvh.Client.raw_query_t
+ def get_links_detailed(), do: {:get, "/account/getAllLinks", :nil}
+
+
+ @doc """
+ GET /account/links/{uri}, Get detailed information for an object at a given uri
+
+
+ ### Example:
+ ```elixir
+ import ExOvh.Query.Hubic
+ container = "new_container"
+ folder = "/"
+ object = "server_file.txt"
+ uri = folder <> object
+ ExOvh.hubic_request(get_link(uri))
+ """
+ @spec get_link(uri :: String.t) :: ExOvh.Client.raw_query_t
+ def get_link(uri), do: {:get, "/account/links/", uri}
@doc ~s"""
- POST /account/links, Create a public link to a file
+ POST /account/links, Create a public url to a file
Note: links have a max ttl of 30 days on hubic currently.
ttl can be 1,5,10,15,20,25 or 30
@@ -81,29 +100,58 @@ defmodule ExOvh.Query.Hubic do
import ExOvh.Query.Hubic
container = "new_container"
object = "server_file.txt"
- ExOvh.hubic_request(publish_object(container, object))
+ {:ok, resp} = ExOvh.hubic_request(publish_object(container, object))
+ %{ "indirectUrl" => link_indirect_uri, "expirationDate" => exp,
+ "creationDate" => created_on, "uri" => uri } = resp.body
+ object_attrs = %{
+ link: link_indirect_uri,
+ expiry: exp,
+ created: created_on,
+ object: object,
+ folder: String.replace(uri, object, ""),
+ object_uri: uri
+ }
```
"""
- @spec publish_object(container :: String.t, object :: String.t)
+ @spec publish_object(container :: String.t, object :: String.t, opts :: map)
:: ExOvh.Client.raw_query_t
- def publish_object(container, object) do
+ def publish_object(container, object, folder \\ "/", ttl \\ "5", file \\ "file") do
params = %{
- "comment": "none",
- "container": container,
- "mode": "ro",
- "ttl": "5",
- "type": "file",
- "uri": URI.encode_www_form("/" <> object),
+ "comment" => "none",
+ "container" => container,
+ "mode" => "ro",
+ "ttl" => ttl,
+ "type" => file,
+ "uri" => folder <> object
}
{:post, "/account/links", params}
end
+ @doc ~s"""
+ DELETE /account/links/{uri}, Deletes a public url to a file
+
+
+ ### Example:
+ ```elixir
+ import ExOvh.Query.Hubic
+ container = "new_container"
+ object = "server_file.txt"
+ folder = "/"
+ uri = folder <> object
+ ExOvh.hubic_request(delete_link(uri))
+ """
+ @spec delete_link(uri :: String.t) :: ExOvh.Client.raw_query_t
+ def delete_link(uri), do: {:delete, "/account/links/", uri}
+
+
########################################
- # HUBIC API FOLDER RELATED REQUESTS
+ # Folder related requests
########################################
+
+
end
\ No newline at end of file