Commit b903f110263b5460ec1ad64168f31d3934a93f4b

Stephen Moloney 2016-02-10T10:07:58

bug fixes. ovh_request works.

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
diff --git a/lib/client.ex b/lib/client.ex
index 84bc091..44f903c 100644
--- a/lib/client.ex
+++ b/lib/client.ex
@@ -35,8 +35,8 @@ defmodule ExOvh.Client do
       end
 
 
-      def ovh_prep_request({method, uri, params} = query, opts \\ %{}) do
-        ExOvh.Ovh.Auth.prep_request(__MODULE__, query, opts)
+      def ovh_prepare_request({method, uri, params} = query, opts \\ %{}) do
+        ExOvh.Ovh.Auth.prepare_request(__MODULE__, query, opts)
       end
 
 
@@ -45,8 +45,8 @@ defmodule ExOvh.Client do
       end
 
 
-      def hubic_prep_request({method, uri, params} = query, opts \\ %{}) do
-        ExOvh.Hubic.Auth.prep_request(__MODULE__, query, opts)
+      def hubic_prepare_request({method, uri, params} = query, opts \\ %{}) do
+        ExOvh.Hubic.Auth.prepare_request(__MODULE__, query, opts)
       end
 
 
@@ -72,7 +72,7 @@ defmodule ExOvh.Client do
   Prepares all elements necessary prior to making a request to the ovh api.
   Returns a tuple `{method, uri, options}`
   """
-  @callback ovh_prep_request(query :: raw_query_t)
+  @callback ovh_prepare_request(query :: raw_query_t)
                              :: query_t
 
 
@@ -88,7 +88,7 @@ defmodule ExOvh.Client do
   Prepares all elements necessary prior to making a request to the hubic api.
   Returns a tuple `{method, uri, options}`
   """
-  @callback hubic_prep_request(query :: raw_query_t)
+  @callback hubic_prepare_request(query :: raw_query_t)
                                :: query_t
 
 
diff --git a/lib/ex_ovh.ex b/lib/ex_ovh.ex
index da33c39..4e43985 100644
--- a/lib/ex_ovh.ex
+++ b/lib/ex_ovh.ex
@@ -1,8 +1,7 @@
 defmodule ExOvh do
   use ExOvh.Client, otp_app: :ex_ovh
 
-  # <<TODO>> Remove application later so that ExOvh is started
-  # <<TODO>> within a supervision tree on demand
+  # <<TODO>> Remove application later so that ExOvh is started within a supervision tree on demand
   use Application
 
   def start(_type, _args) do
diff --git a/lib/hubic/auth.ex b/lib/hubic/auth.ex
index 45ba23a..6e67fc3 100644
--- a/lib/hubic/auth.ex
+++ b/lib/hubic/auth.ex
@@ -1,6 +1,6 @@
 defmodule ExOvh.Hubic.Auth do
   @moduledoc ~s"""
-    Delegates the prep_request to the appropriate module and function
+    Delegates the prepare_request to the appropriate module and function
     depending on the opts specified.
     `%{ openstack: :true }` ==> delegates the query to the OpenstackApi.Auth Module
     `%{ }` ==> delegates the query to the HubicApi.Auth Module
@@ -13,17 +13,17 @@ defmodule ExOvh.Hubic.Auth do
   ############################
 
 
-  @spec prep_request(query :: ExOvh.Client.raw_query_t, opts :: map())
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t, opts :: map())
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query, opts), do: prep_request(ExOvh, query, opts)
+  def prepare_request({method, uri, params} = query, opts), do: prepare_request(ExOvh, query, opts)
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
                      :: ExOvh.Client.query_t
-  def prep_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
-    OpenstackAuth.prep_request(client, query)
+  def prepare_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
+    OpenstackAuth.prepare_request(client, query)
   end
-  def prep_request(client, {method, uri, params} = query, opts) do
-    HubicAuth.prep_request(client, query)
+  def prepare_request(client, {method, uri, params} = query, opts) do
+    HubicAuth.prepare_request(client, query)
   end
 
 
diff --git a/lib/hubic/hubic_api/auth.ex b/lib/hubic/hubic_api/auth.ex
index 84100b7..62ad95b 100644
--- a/lib/hubic/hubic_api/auth.ex
+++ b/lib/hubic/hubic_api/auth.ex
@@ -10,16 +10,16 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
   # Public
   ###################
   
-  @spec prep_request(query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query), do: prep_request(ExOvh, query)
+  def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
 
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
                     :: ExOvh.Client.query_t
-  def prep_request(client, query)
+  def prepare_request(client, query)
 
-  def prep_request(client, {method, uri, params} = query) when method in [:get, :delete] 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)
@@ -27,7 +27,7 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
     {method, uri, options}
   end
 
-  def prep_request(client, {method, uri, params} = query) when method in [:post, :put] 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)
diff --git a/lib/hubic/hubic_api/request.ex b/lib/hubic/hubic_api/request.ex
index d932bc7..ac214d2 100644
--- a/lib/hubic/hubic_api/request.ex
+++ b/lib/hubic/hubic_api/request.ex
@@ -16,7 +16,7 @@ defmodule ExOvh.Hubic.HubicApi.Request do
   @spec request(client :: atom, query :: ExOvh.Client.raw_query_t, retries :: integer)
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query, retries \\ 0) do
-    {method, uri, options} = Auth.prep_request(client, query)
+    {method, uri, options} = Auth.prepare_request(client, query)
     resp = HTTPotion.request(method, uri, options)
     resp =
     %{
diff --git a/lib/hubic/openstack_api/auth.ex b/lib/hubic/openstack_api/auth.ex
index 4066e5b..9a18c10 100644
--- a/lib/hubic/openstack_api/auth.ex
+++ b/lib/hubic/openstack_api/auth.ex
@@ -10,22 +10,22 @@ defmodule ExOvh.Hubic.OpenstackApi.Auth do
   ############################
 
 
-  @spec prep_request(query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query), do: prep_request(ExOvh, query)
+  def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request(client, query)
+  def prepare_request(client, query)
 
-  def prep_request(client, {method, uri, params} = query) when method in [:get, :delete] 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)
     options = %{ headers: headers(client), timeout: @timeout }
     {method, uri, options}
   end
 
-  def prep_request(client, {method, uri, params} = query) when method in [:post, :put] do
+  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)
     options = %{ body: params, headers: headers(client), timeout: @timeout }
diff --git a/lib/hubic/openstack_api/request.ex b/lib/hubic/openstack_api/request.ex
index 98b9afe..61c0f2e 100644
--- a/lib/hubic/openstack_api/request.ex
+++ b/lib/hubic/openstack_api/request.ex
@@ -16,7 +16,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Request do
   @spec request(client :: atom, query :: ExOvh.Client.raw_query_t)
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
-    {method, uri, options} = Auth.prep_request(client, query)
+    {method, uri, options} = Auth.prepare_request(client, query)
     resp = HTTPotion.request(method, uri, options)
     resp =
     %{
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index ec2f57a..498da2c 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -243,7 +243,7 @@ defmodule Mix.Tasks.Ovh do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     body = %{ accessRules: access_rules, redirection: redirect_uri }
     query = {:post, consumer_key_uri(opts_map), body}
-    {method, uri, options} = Auth.ovh_prep_request(opts_map, query)
+    {method, uri, options} = Auth.ovh_prepare_request(opts_map, query)
     options = Map.put(options, :headers, Map.merge(@default_headers, %{ "X-Ovh-Application": app_key(opts_map)}))
     body = HTTPotion.request(method, consumer_key_uri(opts_map), options) |> Map.get(:body) |> Poison.decode!()
     {Map.get(body, "consumerKey"), Map.get(body, "validationUrl")}
diff --git a/lib/ovh/auth.ex b/lib/ovh/auth.ex
index d2e25d6..7d0709b 100644
--- a/lib/ovh/auth.ex
+++ b/lib/ovh/auth.ex
@@ -1,6 +1,6 @@
 defmodule ExOvh.Ovh.Auth do
   @moduledoc ~s"""
-    Delegates the prep_request to the appropriate module and function
+    Delegates the prepare_request to the appropriate module and function
     depending on the opts specified.
     `%{ openstack: :true }` ==> delegates the query to the OpenstackApi.Auth Module
     `%{ }` ==> delegates the query to the HubicApi.Auth Module
@@ -13,17 +13,17 @@ defmodule ExOvh.Ovh.Auth do
   ############################
 
 
-  @spec prep_request(query :: ExOvh.Client.raw_query_t, opts :: map())
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t, opts :: map())
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query, opts), do: prep_request(ExOvh, query, opts)
+  def prepare_request({method, uri, params} = query, opts), do: prepare_request(ExOvh, query, opts)
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map())
                      :: ExOvh.Client.query_t
-  def prep_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
-    OpenstackAuth.prep_request(client, query)
+  def prepare_request(client, {method, uri, params} = query, %{openstack: :true} = opts) do
+    OpenstackAuth.prepare_request(client, query)
   end
-  def prep_request(client, {method, uri, params} = query, opts) do
-    OvhAuth.prep_request(client, query)
+  def prepare_request(client, {method, uri, params} = query, opts) do
+    OvhAuth.prepare_request(client, query)
   end
 
 
diff --git a/lib/ovh/cache.ex b/lib/ovh/cache.ex
deleted file mode 100644
index b2fcd53..0000000
--- a/lib/ovh/cache.ex
+++ /dev/null
@@ -1,96 +0,0 @@
-defmodule ExOvh.Ovh.Cache do
-  @moduledoc ~s"""
-    Caches the ovh api time diff
-  """
-  use GenServer
-  alias ExOvh.Ovh.Defaults
-
-  ############################
-  # Public
-  ###########################
-
-  @doc "Starts a genserver to keep state on the config and time diff"
-  def start_link({client, config, opts}) do
-    LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    GenServer.start_link(__MODULE__, {client, config, opts}, [name: gen_server_name(client)])
-  end
-
-
-  @doc "Retrieves the ovh api time diff from the cache"
-  def get_time_diff(client) do
-    GenServer.call(gen_server_name(client), :get_diff)
-  end
-  @doc "Retrieves the ovh config map"
-  def get_config(client) do
-    GenServer.call(gen_server_name(client), :get_config)
-  end
-
-
-  ############################
-  # Genserver Callbacks
-  ###########################
-
-  def init({client, config, opts}) do
-    LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    diff = calculate_diff(config)
-    {:ok, {config, diff}}
-  end
-
-  def handle_call(:get_diff, _from, {config, diff}) do
-    LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    {:reply, diff, {config, diff}}
-  end
-
-  def handle_call(:get_config, _from, {config, diff}) do
-    LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    {:reply, config, {config, diff}}
-  end
-
-  def handle_cast({:set_diff, new_diff}, {config, diff}) do
-    LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    {:noreply, {config, new_diff}}
-  end
-
-  def terminate(:shutdown, state) do
-    LoggingUtils.log_mod_func_line(__ENV__, :warn)
-    LoggingUtils.log_return("gen_server #{__MODULE__} shutting down", :warn)
-    :ok
-  end
-
-
-  ############################
-  # Private
-  ###########################
-
-
-  defp gen_server_name(client), do: String.to_atom(Atom.to_string(client) <> Atom.to_string(__MODULE__))
-  defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
-  defp api_version(config), do: config[:api_version]
-
-
-  defp api_time_request(config) do
-    time_uri = endpoint(config) <> api_version(config) <> "/auth/time"
-    options = %{ headers: %{ "Content-Type": "application/json; charset=utf-8" }, timeout: 10_000 }
-    api_time = HTTPotion.request(:get, time_uri, options) |> Map.get(:body) |> Poison.decode!()
-  end
-
-
-  defp calculate_diff(config) do
-    api_time = api_time_request(config)
-    os_t = :os.system_time(:seconds)
-    os_t - api_time
-  end
-
-
-  #Caches the ovh api time diff
-  defp set_time_diff(client) do
-    config = get_config(client)
-    set_time_diff(client, config)
-  end
-  defp set_time_diff(client, config) when is_map(config) do
-    diff = calculate_diff(config)
-    GenServer.cast(gen_server_name(client), {:set_diff, diff})
-  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 c57944c..e39d5f9 100644
--- a/lib/ovh/openstack_api/auth.ex
+++ b/lib/ovh/openstack_api/auth.ex
@@ -1,7 +1,7 @@
 defmodule ExOvh.Ovh.Openstack.Auth do
   alias LoggingUtils
   alias ExOvh.Ovh.Defaults
-  alias ExOvh.Ovh.Cache
+  alias ExOvh.Ovh.OvhApi.Cache
 
   @default_headers %{ "Content-Type": "application/json; charset=utf-8" }
   @methods [:get, :post, :put, :delete]
@@ -13,15 +13,15 @@ defmodule ExOvh.Ovh.Openstack.Auth do
   ############################
 
 
-  @spec prep_request(query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query), do: prep_request(ExOvh, query)
+  def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request(client, query)
+  def prepare_request(client, query)
 
-  def prep_request(client, {method, uri, params} = query) when method in [:get, :delete] 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)
@@ -31,7 +31,7 @@ defmodule ExOvh.Ovh.Openstack.Auth do
     {method, uri, options}
   end
 
-  def prep_request(client, {method, uri, params} = query) when method in [:post, :put] do
+  def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
     uri = uri(config, uri)
     config = config(client)
     consumer_key = get_consumer_key(config)
diff --git a/lib/ovh/openstack_api/request.ex b/lib/ovh/openstack_api/request.ex
index 9b79ca0..372165f 100644
--- a/lib/ovh/openstack_api/request.ex
+++ b/lib/ovh/openstack_api/request.ex
@@ -1,8 +1,7 @@
 defmodule ExOvh.Ovh.Openstack.Request do
-  alias ExOvh.Ovh.Auth
-  alias LoggingUtils
+  alias ExOvh.Ovh.Openstack.Auth
+  alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
   alias ExOvh.Ovh.Defaults
-  alias ExOvh.Ovh.Cache
 
   ############################
   # Public
@@ -18,7 +17,7 @@ defmodule ExOvh.Ovh.Openstack.Request do
                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
     config = config(client)
-    {method, uri, options} = Auth.prep_request(client, query)
+    {method, uri, options} = Auth.prepare_request(client, query)
     resp = HTTPotion.request(method, uri, options)
     resp =
     %{
@@ -39,8 +38,8 @@ defmodule ExOvh.Ovh.Openstack.Request do
   ############################
 
 
-  defp config(), do: Cache.get_config(ExOvh)
-  defp config(client), do: Cache.get_config(client)
+  defp config(), do: ClientCache.get_config(ExOvh)
+  defp config(client), do: ClientCache.get_config(client)
   defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
   defp api_version(config), do: config[:api_version]
 
diff --git a/lib/ovh/ovh_api/auth.ex b/lib/ovh/ovh_api/auth.ex
index eb20d0f..17bca84 100644
--- a/lib/ovh/ovh_api/auth.ex
+++ b/lib/ovh/ovh_api/auth.ex
@@ -1,7 +1,7 @@
 defmodule ExOvh.Ovh.OvhApi.Auth do
   alias LoggingUtils
   alias ExOvh.Ovh.Defaults
-  alias ExOvh.Ovh.Cache
+  alias ExOvh.Ovh.OvhApi.Cache
 
   @default_headers %{ "Content-Type": "application/json; charset=utf-8" }
   @methods [:get, :post, :put, :delete]
@@ -13,15 +13,15 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
   ############################
 
 
-  @spec prep_request(query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request({method, uri, params} = query), do: prep_request(ExOvh, query)
+  def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
 
-  @spec prep_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
                      :: ExOvh.Client.query_t
-  def prep_request(client, query)
+  def prepare_request(client, query)
 
-  def prep_request(client, {method, uri, params} = query) when method in [:get, :delete] 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)
@@ -31,7 +31,7 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
     {method, uri, options}
   end
 
-  def prep_request(client, {method, uri, params} = query) when method in [:post, :put] do
+  def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
     uri = uri(config, uri)
     config = config(client)
     consumer_key = get_consumer_key(config)
@@ -42,7 +42,6 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
   end
 
 
-
   ############################
   # Private
   ############################
diff --git a/lib/ovh/ovh_api/cache.ex b/lib/ovh/ovh_api/cache.ex
new file mode 100644
index 0000000..2ea1eba
--- /dev/null
+++ b/lib/ovh/ovh_api/cache.ex
@@ -0,0 +1,96 @@
+defmodule ExOvh.Ovh.OvhApi.Cache do
+  @moduledoc ~s"""
+    Caches the ovh api time diff
+  """
+  use GenServer
+  alias ExOvh.Ovh.Defaults
+
+  ############################
+  # Public
+  ###########################
+
+  @doc "Starts a genserver to keep state on the config and time diff"
+  def start_link({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    GenServer.start_link(__MODULE__, {client, config, opts}, [name: gen_server_name(client)])
+  end
+
+
+  @doc "Retrieves the ovh api time diff from the cache"
+  def get_time_diff(client) do
+    GenServer.call(gen_server_name(client), :get_diff)
+  end
+  @doc "Retrieves the ovh config map"
+  def get_config(client) do
+    GenServer.call(gen_server_name(client), :get_config)
+  end
+
+
+  ############################
+  # Genserver Callbacks
+  ###########################
+
+  def init({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    diff = calculate_diff(config)
+    {:ok, {config, diff}}
+  end
+
+  def handle_call(:get_diff, _from, {config, diff}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    {:reply, diff, {config, diff}}
+  end
+
+  def handle_call(:get_config, _from, {config, diff}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    {:reply, config, {config, diff}}
+  end
+
+  def handle_cast({:set_diff, new_diff}, {config, diff}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    {:noreply, {config, new_diff}}
+  end
+
+  def terminate(:shutdown, state) do
+    LoggingUtils.log_mod_func_line(__ENV__, :warn)
+    LoggingUtils.log_return("gen_server #{__MODULE__} shutting down", :warn)
+    :ok
+  end
+
+
+  ############################
+  # Private
+  ###########################
+
+
+  defp gen_server_name(client), do: String.to_atom(Atom.to_string(client) <> Atom.to_string(__MODULE__))
+  defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
+  defp api_version(config), do: config[:api_version]
+
+
+  defp api_time_request(config) do
+    time_uri = endpoint(config) <> api_version(config) <> "/auth/time"
+    options = %{ headers: %{ "Content-Type": "application/json; charset=utf-8" }, timeout: 10_000 }
+    api_time = HTTPotion.request(:get, time_uri, options) |> Map.get(:body) |> Poison.decode!()
+  end
+
+
+  defp calculate_diff(config) do
+    api_time = api_time_request(config)
+    os_t = :os.system_time(:seconds)
+    os_t - api_time
+  end
+
+
+  #Caches the ovh api time diff
+  defp set_time_diff(client) do
+    config = get_config(client)
+    set_time_diff(client, config)
+  end
+  defp set_time_diff(client, config) when is_map(config) do
+    diff = calculate_diff(config)
+    GenServer.cast(gen_server_name(client), {:set_diff, diff})
+  end
+
+
+end
\ No newline at end of file
diff --git a/lib/ovh/ovh_api/request.ex b/lib/ovh/ovh_api/request.ex
index 57edbb6..bc968e0 100644
--- a/lib/ovh/ovh_api/request.ex
+++ b/lib/ovh/ovh_api/request.ex
@@ -1,8 +1,7 @@
 defmodule ExOvh.Ovh.OvhApi.Request do
-  alias ExOvh.Ovh.Auth
-  alias LoggingUtils
+  alias ExOvh.Ovh.OvhApi.Auth
+  alias ExOvh.Ovh.OvhApi.Cache
   alias ExOvh.Ovh.Defaults
-  alias ExOvh.Ovh.Cache
 
   ############################
   # Public
@@ -18,7 +17,7 @@ defmodule ExOvh.Ovh.OvhApi.Request do
                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
     config = config(client)
-    {method, uri, options} = Auth.prep_request(client, query)
+    {method, uri, options} = Auth.prepare_request(client, query)
     resp = HTTPotion.request(method, uri, options)
     resp =
     %{
diff --git a/lib/ovh/supervisor.ex b/lib/ovh/supervisor.ex
index 1d4436a..66a0baf 100644
--- a/lib/ovh/supervisor.ex
+++ b/lib/ovh/supervisor.ex
@@ -3,7 +3,7 @@ defmodule ExOvh.Ovh.Supervisor do
   Supervisor for the Ovh Configuration
   """
   use Supervisor
-  alias ExOvh.Ovh.Cache
+  alias ExOvh.Ovh.OvhApi.Cache
 
   #####################
   #  Public