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 178 179 180 181 182
defmodule ExOvh.Query.Hubic do
@moduledoc ~S"""
Helper functions for building queries for the hubic api.
The raw query can be passed into a client request.
## Example
import ExOvh.Query.Hubic, only: [scope: 0]
scope = ExOvh.hubic_request(scope())
"""
#########################
# General Hubic Requests
#########################
@doc ~S"""
GET /scope/scope, Get the possible scopes for hubiC API
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(scope())
"""
@spec scope() :: ExOvh.Client.raw_query_t
def scope(), do: {:get, "/scope/scope", :nil}
@doc ~S"""
GET /account, Get the account object properties
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(account())
"""
@spec account() :: ExOvh.Client.raw_query_t
def account(), do: {:get, "/account", :nil}
@doc ~S"""
GET /account/credentials, Returns openstack credentials for connecting to the file API
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(openstack_credentials())
"""
@spec openstack_credentials() :: ExOvh.Client.raw_query_t
def openstack_credentials(), do: {:get, "/account/credentials", :nil}
@doc ~S"""
GET /account/usage, Returns used space & quota of your account
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(account_usage())
"""
@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 (showing the object internal uri - not the indirectUri)
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(get_links())
```
"""
@spec get_links() :: ExOvh.Client.raw_query_t
def get_links(), do: {:get, "/account/links", :nil}
@doc """
GET /account/getAllLinks, Get all published objects' public urls with detailed info
### Example:
```elixir
import ExOvh.Query.Hubic
ExOvh.hubic_request(get_links_detailed())
```
"""
@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 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
See hubic ovh [docs](https://hubic.com/en/faq) under 'What is sharing?'.
### Example:
```elixir
import ExOvh.Query.Hubic
container = "new_container"
object = "server_file.txt"
{: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, opts :: map)
:: ExOvh.Client.raw_query_t
def publish_object(container, object, folder \\ "/", ttl \\ "5", file \\ "file") do
params = %{
"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}
########################################
# Folder related requests
########################################
end