Commit 8c0d1730cee331bda960aa2101cc7e169e3078f8

Stephen Moloney 2016-02-11T00:54:30

added more queries up as far as but not including publish_link

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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
diff --git a/.gitignore b/.gitignore
index 41e983f..fea1397 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/priv/client_file.txt
 /_build
 /cover
 /deps
diff --git a/lib/client.ex b/lib/client.ex
index 44f903c..fdc4e58 100644
--- a/lib/client.ex
+++ b/lib/client.ex
@@ -11,7 +11,7 @@ defmodule ExOvh.Client do
   @type raw_query_t :: { method_t, path_t, params_t }
   @type query_t :: { method_t, path_t, options_t }
 
-  @type response_t :: %{ body: map(), headers: map(), status_code: integer() }
+  @type response_t :: %{ body: map() | String.t, headers: map(), status_code: integer() }
 
   defmacro __using__(opts) do
     quote bind_quoted: [opts: opts] do
diff --git a/lib/hubic/hubic_api/auth.ex b/lib/hubic/hubic_api/auth.ex
index 62ad95b..313cddc 100644
--- a/lib/hubic/hubic_api/auth.ex
+++ b/lib/hubic/hubic_api/auth.ex
@@ -22,7 +22,7 @@ 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 !== "", do: uri = uri <> "?" <> URI.encode_query(params)
     options = %{ headers: headers(method), timeout: @timeout }
     {method, uri, options}
   end
@@ -30,7 +30,8 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
   def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
     config = config(client)
     uri = uri(config, uri)
-    if params !== "" and params !== :nil, do: params = Poison.encode!(params)
+    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
diff --git a/lib/hubic/hubic_api/request.ex b/lib/hubic/hubic_api/request.ex
index ac214d2..33ddd52 100644
--- a/lib/hubic/hubic_api/request.ex
+++ b/lib/hubic/hubic_api/request.ex
@@ -17,16 +17,26 @@ defmodule ExOvh.Hubic.HubicApi.Request do
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query, retries \\ 0) do
     {method, uri, options} = Auth.prepare_request(client, query)
+    LoggingUtils.log_return({method, uri, options}, :debug)
     resp = HTTPotion.request(method, uri, options)
-    resp =
-    %{
-      body: resp.body |> Poison.decode!(),
-      headers: resp.headers,
-      status_code: resp.status_code
-    }
-
+    |> LoggingUtils.log_return(:debug)
     if resp.status_code >= 100 and resp.status_code < 300 do
-     {:ok, resp}
+      try do
+        {:ok, %{
+               body: resp.body |> Poison.decode!(),
+               headers: resp.headers,
+               status_code: resp.status_code
+              }
+        }
+      rescue
+        _ ->
+        {:ok, %{
+               body: resp.body,
+               headers: resp.headers,
+               status_code: resp.status_code
+              }
+        }
+      end
     else
       if Map.has_key?(resp.body, "error") do
         #error = Map.get(body, "error") <> " :: " <> Map.get(body, "error_description")
diff --git a/lib/hubic/openstack_api/auth.ex b/lib/hubic/openstack_api/auth.ex
index 9a18c10..4b60dfd 100644
--- a/lib/hubic/openstack_api/auth.ex
+++ b/lib/hubic/openstack_api/auth.ex
@@ -20,14 +20,14 @@ defmodule ExOvh.Hubic.OpenstackApi.Auth do
 
   def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
     uri =  Cache.get_endpoint(client) <> uri
-    if params !== :nil and params !== "", do: uri = uri <> URI.encode_query(params)
+    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
     options = %{ headers: headers(client), timeout: @timeout }
     {method, uri, options}
   end
 
   def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
     uri =  Cache.get_endpoint(client) <> uri
-    if params !== "" and params !== :nil and method in [:post, :put], do: params = Poison.encode!(params)
+    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
     options = %{ body: params, headers: headers(client), timeout: @timeout }
     {method, uri, options}
   end
diff --git a/lib/hubic/openstack_api/cache.ex b/lib/hubic/openstack_api/cache.ex
index 9f57b12..a4265ab 100644
--- a/lib/hubic/openstack_api/cache.ex
+++ b/lib/hubic/openstack_api/cache.ex
@@ -8,6 +8,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
   alias ExOvh.Hubic.Request
   @get_credentials_retries 10
   @get_credentials_sleep_interval 150
+  @init_delay 6_000
 
 
   #####################
@@ -62,7 +63,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     :erlang.process_flag(:trap_exit, :true)
     token = Cache.get_token(client)
-    :timer.sleep(10_000) # give some time for TokenCache Genserver to initialize
+    :timer.sleep(@init_delay) # give some time for TokenCache Genserver to initialize
     create_ets_table(client)
     {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
     |> LoggingUtils.log_return(:debug)
diff --git a/lib/hubic/openstack_api/request.ex b/lib/hubic/openstack_api/request.ex
index 61c0f2e..bab2983 100644
--- a/lib/hubic/openstack_api/request.ex
+++ b/lib/hubic/openstack_api/request.ex
@@ -17,16 +17,27 @@ defmodule ExOvh.Hubic.OpenstackApi.Request do
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
     {method, uri, options} = Auth.prepare_request(client, query)
+    |> LoggingUtils.log_return(:debug)
     resp = HTTPotion.request(method, uri, options)
-    resp =
-    %{
-      body: resp.body |> Poison.decode!(),
-      headers: resp.headers,
-      status_code: resp.status_code
-    }
+    |> LoggingUtils.log_return(:debug)
 
     if resp.status_code >= 100 and resp.status_code < 300 do
-     {:ok, resp}
+      try do
+        {:ok, %{
+               body: resp.body |> Poison.decode!(),
+               headers: resp.headers,
+               status_code: resp.status_code
+              }
+        }
+      rescue
+        _ ->
+        {:ok, %{
+               body: resp.body,
+               headers: resp.headers,
+               status_code: resp.status_code
+              }
+        }
+      end
     else
      {:error, resp}
     end
diff --git a/lib/hubic/request_helpers.ex b/lib/hubic/request_helpers.ex
new file mode 100644
index 0000000..60d93a6
--- /dev/null
+++ b/lib/hubic/request_helpers.ex
@@ -0,0 +1,80 @@
+defmodule ExOvh.Hubic.RequestHelpers do
+  import ExOvh.Query.Openstack.Swift
+  alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+
+
+  @doc ~s"""
+  Gets a list of all openstack swift containers for the hubic app
+
+  Returns `{:ok, [<container_name>, <container_name> ...]`
+  or
+  Returns `{:error, resp}`
+
+  ## Example
+
+      ```elixir
+      alias ExOvh.Hubic.RequestHelpers
+      client = ExOvh # Enter your client here
+      RequestHelpers.containers(client)
+      ```
+  """
+  @spec containers(client :: atom)
+                   :: {:ok, [String.t]} | {:error, ExOvh.Client.response_t}
+  def containers(client) do
+    account = OpenCache.get_account(client)
+    case ExOvh.hubic_request(account_info(account), %{ openstack: :true }) do
+      {:ok, resp} ->
+        LoggingUtils.log_return(resp)
+        {:ok, resp.body |> Enum.map(fn(%{"name" => container}) -> container end)}
+      {:error, resp} ->
+        {:error, resp}
+    end
+  end
+
+
+  @doc ~s"""
+  Gets a list of all objects by name in an openstack swift container for the hubic app
+  Allows to filter the returned list by hash or by name depending on the filter used.
+
+  Returns `{:ok, [<object_name>, <object_name> ...]`
+  or
+  Returns `{:error, resp}`
+
+  ## Example
+
+      ```elixir
+      alias ExOvh.Hubic.RequestHelpers
+      client = ExOvh
+      container = "new_container"
+      RequestHelpers.get_objects(client, container, :name)
+      RequestHelpers.get_objects(client, container, :hash)
+      ```
+  """
+  @spec get_objects(client :: atom, container :: String.t, filter :: atom)
+                   :: {:ok, [String.t]} | {:error, ExOvh.Client.response_t}
+  def get_objects(client, container, filter)
+
+  def get_objects(client, container, :name) do
+    account = OpenCache.get_account(client)
+    case ExOvh.hubic_request(get_objects(account, container), %{ openstack: :true }) do
+      {:ok, resp} ->
+        LoggingUtils.log_return(resp)
+        {:ok, resp.body |> Enum.map(fn(%{"name" => object_name}) -> object_name end)}
+      {:error, resp} ->
+        {:error, resp}
+    end
+  end
+
+  def get_objects(client, container, :hash) do
+    account = OpenCache.get_account(client)
+    case ExOvh.hubic_request(get_objects(account, container), %{ openstack: :true }) do
+      {:ok, resp} ->
+        LoggingUtils.log_return(resp)
+        {:ok, resp.body |> Enum.map(fn(%{"hash" => object_hash}) -> object_hash end)}
+      {:error, resp} ->
+        {:error, resp}
+    end
+  end
+
+
+end
\ No newline at end of file
diff --git a/lib/ovh/openstack_api/auth.ex b/lib/ovh/openstack_api/auth.ex
index e39d5f9..3de6358 100644
--- a/lib/ovh/openstack_api/auth.ex
+++ b/lib/ovh/openstack_api/auth.ex
@@ -24,7 +24,7 @@ defmodule ExOvh.Ovh.Openstack.Auth do
   def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
     uri = uri(config, uri)
     config = config(client)
-    if params !== :nil and params !== "", do: uri = uri <> URI.encode_query(params)
+    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
     consumer_key = get_consumer_key(config)
     opts = [app_secret(config), app_key(config), consumer_key, Atom.to_string(method), uri, ""]
     options = %{ headers: headers(opts, client), timeout: @timeout }
@@ -35,7 +35,7 @@ defmodule ExOvh.Ovh.Openstack.Auth do
     uri = uri(config, uri)
     config = config(client)
     consumer_key = get_consumer_key(config)
-    if params !== "" and params !== :nil and method in [:post, :put], do: params = Poison.encode!(params)
+    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
     opts = [app_secret(config), consumer_key, Atom.to_string(method), uri, params]
     options = %{ body: params, headers: headers(opts, client), timeout: @timeout }
     {method, uri, options}
diff --git a/lib/ovh/ovh_api/auth.ex b/lib/ovh/ovh_api/auth.ex
index 17bca84..b79d639 100644
--- a/lib/ovh/ovh_api/auth.ex
+++ b/lib/ovh/ovh_api/auth.ex
@@ -24,7 +24,7 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
   def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
     uri = uri(config, uri)
     config = config(client)
-    if params !== :nil and params !== "", do: uri = uri <> URI.encode_query(params)
+    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
     consumer_key = get_consumer_key(config)
     opts = [app_secret(config), app_key(config), consumer_key, Atom.to_string(method), uri, ""]
     options = %{ headers: headers(opts, client), timeout: @timeout }
@@ -35,7 +35,7 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
     uri = uri(config, uri)
     config = config(client)
     consumer_key = get_consumer_key(config)
-    if params !== "" and params !== :nil and method in [:post, :put], do: params = Poison.encode!(params)
+    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
     opts = [app_secret(config), consumer_key, Atom.to_string(method), uri, params]
     options = %{ body: params, headers: headers(opts, client), timeout: @timeout }
     {method, uri, options}
diff --git a/lib/ovh/ovh_api/request.ex b/lib/ovh/ovh_api/request.ex
index bc968e0..3119d63 100644
--- a/lib/ovh/ovh_api/request.ex
+++ b/lib/ovh/ovh_api/request.ex
@@ -19,14 +19,14 @@ defmodule ExOvh.Ovh.OvhApi.Request do
     config = config(client)
     {method, uri, options} = Auth.prepare_request(client, query)
     resp = HTTPotion.request(method, uri, options)
-    resp =
-    %{
-      body: resp.body |> Poison.decode!(),
-      headers: resp.headers,
-      status_code: resp.status_code
-    }
+    |> LoggingUtils.log_return(:debug)
     if resp.status_code >= 100 and resp.status_code < 300 do
-     {:ok, resp}
+      {:ok, %{
+             body: resp.body |> Poison.decode!(),
+             headers: resp.headers,
+             status_code: resp.status_code
+            }
+      }
     else
      {:error, resp}
     end
diff --git a/lib/query/hubic/query.ex b/lib/query/hubic/query.ex
index 2049011..a2ada36 100644
--- a/lib/query/hubic/query.ex
+++ b/lib/query/hubic/query.ex
@@ -6,16 +6,104 @@ defmodule ExOvh.Query.Hubic do
 
     ## Example
 
-      `scope = ExOvh.hubic_request(ExOvh.Query.Hubic.scope())`
+      ```elixir
+      import ExOvh.Query.Hubic, only: [scope: 0]
+      scope = ExOvh.hubic_request(scope())
+      ```
   """
 
+  #########################
+  # General Hubic Requests
+  #########################
+
+  @doc "GET /scope/scope, Get the possible scopes for hubiC API"
+  @spec scope() :: ExOvh.Client.raw_query_t
+  def scope(), do: {:get, "/scope/scope", :nil}
+
+
+  @doc "GET /account, Get the account object properties"
+  @spec account() :: ExOvh.Client.raw_query_t
+  def account(), do: {:get, "/account", :nil}
+
+
+  @doc "GET /account/credentials
+  Returns openstack credentials for connecting to the file API"
+  @spec openstack_credentials() :: ExOvh.Client.raw_query_t
+  def openstack_credentials(), do: {:get, "/account/credentials", :nil}
+
+
+  @doc "GET /account/usage, Returns used space & quota of your account"
+  @spec account_usage() :: ExOvh.Client.raw_query_t
+  def account_usage(), do: {:get, "/account/usage", :nil}
+
+  ########################################
+  # Link related Requests
+  ########################################
+
+
+
   @doc """
-  GET /1.0/scope/scope
-  Get the possible scopes for hubiC API
+  GET /account/links, Get all links as a list of links
+
+    ### Example:
+      ```elixir
+      import ExOvh.Query.Hubic
+      {:ok, resp} = ExOvh.hubic_request(get_links())
+      links = resp.body
+      ```
   """
- @spec scope() :: ExOvh.Client.raw_query_t
- def scope(), do: {:get, "/1.0/scope/scope", :nil}
+  @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_published_links_detailed())
+      ```
+  """
+  @spec get_published_links_detailed() :: ExOvh.Client.raw_query_t
+  def get_published_links_detailed(), do: {:get, "/account/getAllLinks", :nil}
+
+
+  @doc ~s"""
+  POST /account/links, Create a public link 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"
+      ExOvh.hubic_request(publish_object(container, object))
+      ```
+  """
+  @spec publish_object(container :: String.t, object :: String.t)
+                             :: ExOvh.Client.raw_query_t
+  def publish_object(container, object) do
+    params = %{
+               "comment": "none",
+               "container": container,
+               "mode": "ro",
+               "ttl": "5",
+               "type": "file",
+               "uri": URI.encode_www_form("/" <> object),
+              }
+    {:post, "/account/links", params}
+  end
+
+
+
 
+  ########################################
+  # HUBIC API FOLDER RELATED REQUESTS
+  ########################################
 
 
 end
\ No newline at end of file
diff --git a/lib/query/openstack/swift/query.ex b/lib/query/openstack/swift/query.ex
new file mode 100644
index 0000000..e9a94fb
--- /dev/null
+++ b/lib/query/openstack/swift/query.ex
@@ -0,0 +1,177 @@
+defmodule ExOvh.Query.Openstack.Swift do
+  @moduledoc ~s"""
+  Helps to build queries for the openstack swift api.
+  The raw query can be passed into a client request.
+
+    ## Example
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift, only: [scope: 0]
+      account = ExOvh.Hubic.OpenstackApi.Cache.get_account()
+      client = ExOvh
+      scope = ExOvh.hubic_request(account_info(client), %{ openstack: : true })
+      ```
+  """
+  alias ExOvh.Hubic.OpenstackApi.Cache, as: HubicOpenstackCache
+
+
+  #############################
+  # CONTAINER RELATED REQUESTS
+  #############################
+
+
+  @doc ~s"""
+  GET /v1/​{account}​, Get account details and containers for given account
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      ExOvh.hubic_request(account_info(OpenCache.get_account(client)), %{ openstack: :true })
+      ```
+  """
+  @spec account_info(account :: String.t) :: [map]
+  def account_info(account), do: {:get, account, %{ "format" => "json" }}
+
+
+  @doc ~s"""
+  PUT /v1/​{account}/{container}​, Create a new container
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      ExOvh.hubic_request(create_container(OpenCache.get_account(client), "new_container"), %{ openstack: :true })
+      ```
+  """
+  @spec create_container(account :: String.t, container :: String.t)
+                         :: ExOvh.Client.raw_query_t
+  def create_container(account, container), do: {:put, account <> "/" <> container, %{ "format" => "json" }}
+
+
+  @doc ~s"""
+  DELETE /v1/​{account}/{container}​, Delete a container
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      ExOvh.hubic_request(delete_container(OpenCache.get_account(client), "new_container"), %{ openstack: :true })
+      ```
+  """
+  @spec delete_container(account :: String.t, container :: String.t)
+                         :: ExOvh.Client.raw_query_t
+  def delete_container(account, container), do: {:delete, account <> "/" <> container, %{ "format" => "json" }}
+
+
+  ##########################
+  # OBJECT RELATED REQUESTS
+  ##########################
+
+
+  @doc ~s"""
+  GET /v1/​{account}​/{container}, List objects in a container
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      ExOvh.hubic_request(get_objects(OpenCache.get_account(client), "default"), %{ openstack: :true })
+      ```
+  """
+  @spec get_objects(account :: String.t, container :: String.t)
+                    :: ExOvh.Client.raw_query_t
+  def get_objects(account, container), do: {:get, account <> "/" <> container, %{ "format" => "json" }}
+
+
+
+  @doc ~s"""
+  GET /v1/​{account}​/{container}/{object}, Get/Download a specific object (file)
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      file = "server_file.txt"
+      container = "new_container"
+      ExOvh.hubic_request(get_object(OpenCache.get_account(client), container, file), %{ openstack: :true })
+      ```
+  """
+  @spec get_object(account :: String.t, container :: String.t, object :: String.t)
+                   :: ExOvh.Client.raw_query_t
+  def get_object(account, container, object), do: {:get, account <> "/" <> container <> "/" <> object, :nil}
+
+
+  @doc """
+  PUT /v1/​{account}​/{container}/{object}, Create or replace an object (file)
+
+    ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      account = OpenCache.get_account(client)
+      object_name = "client_file.txt"
+      client_object = Kernel.to_string(:code.priv_dir(:ex_ovh)) <> "/" <> object_name
+      container = "new_container"
+      server_object = String.replace(object_name, "client", "server")
+      ExOvh.hubic_request(create_object(account, container, client_object, server_object), %{ openstack: :true })
+      ```
+  """
+  @spec create_object(account :: String.t, container :: String.t, client_object :: String.t, server_object :: String.t)
+                      :: ExOvh.Client.raw_query_t
+  def create_object(account, container, client_object, server_object) do
+    case File.read(client_object) do
+      {:ok, binary_object} ->
+        path = account <> "/" <> container <> "/" <> server_object
+        {:put, path, binary_object}
+      {:error, posix_error} ->
+        LoggingUtils.log_mod_func_line(__ENV__, :error)
+        LoggingUtils.log_return(posix_error, :error)
+        raise posix_error
+    end
+  end
+
+
+  @doc """
+  DELETE /v1/​{account}​/{container}/{object}, Delete an Object (Delete a file)
+
+    ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Openstack.Swift
+      alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
+      client = ExOvh
+      account = OpenCache.get_account(client)
+      container = "new_container"
+      server_object = "server_file.txt"
+      ExOvh.hubic_request(delete_object(account, container, server_object), %{ openstack: :true })
+  """
+  @spec delete_object(account :: String.t, container :: String.t, server_object :: String.t)
+                      :: ExOvh.Client.raw_query_t
+  def delete_object(account, container, server_object) do
+    {:delete, account <> "/" <> container <> "/" <> server_object, :nil}
+  end
+
+
+
+end
+
+
+
+
+
+
+
+