Commit af16fa26f1a91fa048bc406b77d66e613beb9663

Stephen Moloney 2016-05-02T19:00:38

clean up mix task and readme

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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
diff --git a/README.md b/README.md
index c90654f..9aa205a 100644
--- a/README.md
+++ b/README.md
@@ -1,220 +1,273 @@
 # ExOvh
-ExOvh is an elixir library to make it easier to interact with both the [Ovh Api](https://api.ovh.com/) 
-and the [Hubic Api](https://api.hubic.com/).
+ExOvh is an elixir library for the [Ovh Api](https://api.ovh.com/).
 
-## Note
 
-This repository is a work in progress.
+## Project Features
 
-
-## Project Features 
-- Provides Query modules that enable the easy generation of ovh and hubic related api queries for use by HTTPotion.
-- Provides Caches which are modules handling the authentication tokens in the background within a supervision tree.
-- Add more here....
+- Cache modules (genservers) running in the background which store frequently accessed authentication information.
+- Query and Helper modules for making calls to the OVH API.
+- Query and Helper modules for making calls to the Openstack Swift API. OVH uses openstack for their [webstorage cdn service](https://www.ovh.ie/cdn/webstorage/)
+and their [public cloud storage service](https://www.ovh.ie/cloud/storage/)
 
 
 ## Getting Started
 
+- Add :ex_ovh to the dependencies.
+
+  ```elixir
+  defp deps() do
+    [
+      {:ex_ovh, "~> 0.0.1"}
+    ]
+  end
+  ```
 
-### Hubic  
+- Create an OVH account at [OVH](https://www.ovh.com/us/)
 
-Create a hubic account. 
+- Create an API application at the [OVH API page](https://eu.api.ovh.com/createApp/). Follow the
+  steps outlined by OVH there. This is the correct way to create the OVH application.
 
-Create a hubic application.
-    
-With the credentials, get the refresh_token. Use the Mix hubic task to 
-help generate the refresh token on your behalf if you wish: 
+- Alternatively, there is a mix task which:
 
+    1. Creates an application on the user's behalf by sending http requests using the user's username and password credentials.
+    2. Gets a consumer key and validation url.
+    3. Validates the validation url on the user's behalf by sending http requests using the user's username and password credentials.
+    4. Adds the application key, application secret and associated consumer key to the environment configuration.
 
+- Examples using the mix ovh task:
+
+  - Most basic usage:
+
+  **Shell Input:**
   ```shell
-  mix hubic
-  --login=<login>
-  --password=<password>
-  --clientid=<client_id>
-  --clientsecret=<client_secret>
-  --redirecturi=<uri>
+  mix ovh \
+  --login=<username-ovh> \
+  --password=<password> \
+  --appname='ex_ovh'
   ```
 
-  
-Shell Output
-  
-  ```elixir
-  %{
-  client_id: "<client_id>",
-  client_secret: "<client_secret>",
-  refresh_token: "<refresh_token>",
-  redirect_uri: "<uri>"
-  }
-  ```
+  - `login`: username/nic_handle for logging into OVH services. *Note*: must include `-ovh` at the end of the string.
+  - `password`: password for logging into OVH services.
+  - `appname`: this should correspond to the `otp_app` name in the elixir application. The same name will be used as
+  the name for the application in OVH.
+  - `redirecturi`: defaults to `""` when absent.
+  - `endpoint`: defaults to `"ovh-eu"` wen absent.
+  - `accessrules`: defaults to `get-[/*]::put-[/*]::post-[/*]::delete-[/*]` when absent giving the application all
+    full priveleges. One may consider fine-tuning the accessrules, see advanced example below.
+  - `appdescription`: defaults to `appname` if absent
+  - `clientname`:" defaults to `ExOvh` when the appname is exactly equal to `ex_ovh`, otherwise defaults to `OvhClient`.
 
-Add the hubic credentials printed in the shell by the mix hubic task to the `config/prod.secret.exs` file
+  **Shell Output:**
 
-  ```
+  ```elixir
   config :ex_ovh,
-    ovh: :nil
-    hubic:   %{
-              client_id: "<client_id>",
-              client_secret: "<client_secret>",
-              refresh_token: "<refresh_token>",
-              redirect_uri: "<uri>"
-             }
+    ovh: [
+      application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
+      application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
+      consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
+      endpoint: System.get_env("EX_OVH_ENDPOINT"),
+      api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
+    ]
   ```
+  This configuration can be added to `config.exs`.
+
+  - `EX_OVH_APPLICATION_KEY`: The system environment variable name for the application key.
+  - `EX_OVH_APPLICATION_SECRET`: The system environment variable name for the application secret.
+  - `EX_OVH_CONSUMER_KEY`: The system environment variable name for the consumer key.
+  - `EX_OVH_ENDPOINT`: The system environment variable name for the ovh endpoint.
+  - `EX_OVH_API_VERSION`: The system environment variable name for the api version.
 
-### OVH
 
+  - The enviroment variables are saved to a file called `.env` automatically by the mix task.
+  **Do not add the `.env` file to version control.** Add the variables to the system environment
+  by running the command or some other commands as appropriate to the deployment method.
 
-Create an OVH account 
+  ```shell
+  source .env
+  ```
 
-Create an application at `https://eu.api.ovh.com/createApp/` or
-alternatively use the mix ovh task to generate the application:
+  - Advanced usage:
 
+  **Shell Input:**
 
   ```shell
-  mix ovh
-  --login=<username>
-  --password=<password>
-  --appname='My app'
-  --appdesc='my app for api'
-  --accessrules='get-[/*]::put-[/me,/cdn]::post-[/me,/cdn]::delete-[]'
+  mix ovh \
+  --login=<username-ovh> \
+  --password=<password> \
+  --appdescription='Ovh Application for my app' \
+  --endpoint='ovh-eu' \
+  --apiversion='1.0' \
+  --redirecturi='http://localhost:4000/' \
+  --accessrules='get-[/*]::put-[/me,/cdn]::post-[/me,/cdn]::delete-[]' \
+  --appname='my_app'
+  --clientname='OvhClient'
   ```
 
-As seen above, access rules can be specified so that only certain endpoints are allowed.
+  - `login`: username/nic_handle for logging into OVH services. *Note*: must include `-ovh` at the end of the string.
+  - `password`: password for logging into OVH services.
+  - `appname`: appname corresponds to the `otp_app` name in the elixir application. The same name will be used as
+  the name for the application in OVH.
+  - `clientname`:" defaults to `ExOvh` when the appname is exactly equal to `ex_ovh`, otherwise defaults to `OvhClient`. `clientname` corresponds to the name of the client. So for example, if appname is `'my_app'` and clientname is
+    `'Client'` then the config file will be `config :my_app, MyApp.Client`. Also, the client in application code can be referred
+    to as `MyApp.Client.function_name`.
+  - `appdescription`: A description for the application saved to OVH.
+  - `endpoint`: OVH endpoint to be used. May vary depending on the OVH service. See `ExOvh.Ovh.Defaults`.
+  - `apiversion`: version of the api to use. Only one version available currently.
+  - `redirecturi`: redirect url for oauth authentication. Should be https.
+  - `accessrules`: restrictions can be added to the access rules. In this example, `get` requests to all endpoints are allowed,
+    `put` and `post` requests to `/me` and `/cdn` and `delete` requests are forbidden.
 
-Shell Output
 
-  A map is printed to the shell as follows:
+  **Shell Output:**
 
   ```elixir
-  %{
-  application_key: "<app_key>",
-  application_secret: "<app_secret>",
-  consumer_key: "<consumer_secret>",
-  endpoint: "ovh-eu",
-  api_version: "1.0"
-  }
+  config :my_app, MyApp.OvhClient,
+      ovh: [
+        application_key: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_KEY"),
+        application_secret: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_SECRET"),
+        consumer_key: System.get_env("MY_APP_OVH_CLIENT_CONSUMER_KEY"),
+        endpoint: System.get_env("MY_APP_OVH_CLIENT_ENDPOINT"),
+        api_version: System.get_env("MY_APP_OVH_CLIENT_API_VERSION") || "1.0"
+      ]
   ```
+  This configuration can be added to `config.exs`.
 
-  - This map can then be manually added by the user to the `config/prod.secret.exs` file
-
-  ```
-  config :ex_ovh,
-  ovh: %{
-        application_key: "<app_key>",
-        application_secret: "<app_secret>",
-        consumer_key: "<consumer_secret>",
-        endpoint: "ovh-eu",
-        api_version: "1.0"
-       },
-  hubic: %{
-          client_id: "<client_id>",
-          client_secret: "<client_secret>",
-          refresh_token: "<refresh_token>",
-          redirect_uri: "<uri>"
-         }
-  ```
+  - `EX_OVH_APPLICATION_KEY`: The system environment variable name for the application key.
+  - `EX_OVH_APPLICATION_SECRET`: The system environment variable name for the application secret.
+  - `EX_OVH_CONSUMER_KEY`: The system environment variable name for the consumer key.
+  - `EX_OVH_ENDPOINT`: The system environment variable name for the ovh endpoint.
+  - `EX_OVH_API_VERSION`: The system environment variable name for the api version.
 
 
-### Add :httpotion to applications on startup (httpotion is used for http requests) 
-
-```elixir
-  def application do 
-    [ 
-      applications: [:httpotion]
-    ]
-  end
-```
+  - The enviroment variables are saved to a file called `.env` automatically by the mix task.
+  **Do not add the `.env` file to version control.** Add the variables to the system environment
+  by running the command or some other commands as appropriate to the deployment method.
 
-### Starting the supervisor
+  ```shell
+  source .env
+  ```
 
-Add the supervisor to your supervision tree:
- 
- ```elixir 
-   def start(_type, _args) do
-    import Supervisor.Spec, warn: false
+- Make further configurations if necessary, depending on which OVH services are being used.
 
-    phoenix = [supervisor(TestOs.Endpoint, [])]
-    ex_ovh = [supervisor(ExOvh, [])]
+  - Configuration for [webstorage cdn service](https://www.ovh.ie/cdn/webstorage/)
 
-    opts = [strategy: :one_for_one, name: TestOs.Supervisor]
-    Supervisor.start_link(phoenix ++ ex_ovh, opts)
-  end
+  In the example below, `EX_OVH_WEBSTORAGE_CDN_NAME` is added to the environment variables.
+  ```elixir
+  config :ex_ovh,
+    ovh: [],
+    swift: [
+          webstorage: [
+                        cdn_name: System.get_env("MY_APP_OVH_CLIENT_WEBSTORAGE_CDN_NAME"),
+                        type: :webstorage
+                      ]
+         ]
+   ```
+
+  - Configuration for public cloud storage service](https://www.ovh.ie/cloud/storage/)
+
+  In the example below, `MY_APP_OVH_CLIENT_CLOUDSTORAGE_TENANT_ID` and `MY_APP_OVH_CLIENT_CLOUDSTORAGE_USER_ID` are
+  added to the environment variables.
+  ```elixir
+  config :ex_ovh,
+    ovh: [],
+    swift: [
+          cloudstorage: [
+                          tenant_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to a project id
+                          user_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_USER_ID"), # optional, if absent a user will be created using the ovh api.
+                          keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
+                          region: :nil, # defaults to "SBG1" if set to :nil
+                          type: :cloudstorage
+                        ]
+         ]
+   ```
+
+- Optionally configure `:openstex` which allows customization of [httpoison opts](https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L127)
+  for each request.
+
+  Example configuration for custom [httpoison opts](https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L127) (optional):
+  ```elixir
+  config :openstex,
+    httpoison: [
+                connect_timeout: 30000, # 30 seconds
+                receive_timeout: (60000 * 30) # 30 minutes
+               ]
   ```
 
+- The final phase of configuration is to set up the supervision tree. There are effectively two ways to do
+  this:
 
-#### Show how to add another client here ......
+    1. The 'correct way' where a client is setup for the otp_app, therefore allowing for the creation of
+       multiple clients.
 
+       Example configuration:
 
+       ```elixir
+       config :my_app, MyApp.OvhClient,
+           ovh: [
+             application_key: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_KEY"),
+             application_secret: System.get_env("MY_APP_OVH_CLIENT_APPLICATION_SECRET"),
+             consumer_key: System.get_env("MY_APP_OVH_CLIENT_CONSUMER_KEY"),
+             endpoint: System.get_env("MY_APP_OVH_CLIENT_ENDPOINT"),
+             api_version: System.get_env("MY_APP_OVH_CLIENT_API_VERSION") || "1.0"
+           ]
+       ```
 
-## Example Usage(s)
+       Add supervisors to the supervision tree of the application, for example:
 
+       ```elixir
+       def start(_type, _args) do
+        import Supervisor.Spec, warn: false
+        spec1 = [supervisor(MyApp.Endpoint, [])]
+        spec2 = [supervisor(MyApp.OvhClient, [])]
+        opts = [strategy: :one_for_one, name: MyApp.Supervisor]
+        Supervisor.start_link(spec1 ++ spec2, opts)
+       end
+       ```
 
-### Example 1: 
+    2. The 'quick way' which is quite useful when only one client is needed.
 
+       Example Configuration:
 
-Get account details and containers for given account
-  ```elixir
-  alias ExOvh.Query.Openstack.Swift, as: Query
-  alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
-  client = ExOvh
-  
-  account = OpenCache.get_account(client)
-  query = Query.account_info(account)
-  {:ok, resp} = ExOvh.hubic_request(query, %{ openstack: :true })
-  container_count1 = resp.body |> Enum.count() 
-  ```
+       ```elixir
+       config :ex_ovh,
+         ovh: [
+           application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
+           application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
+           consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
+           endpoint: System.get_env("EX_OVH_ENDPOINT"),
+           api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
+         ]
+       ```
 
-Creating a new container in hubic
-  ```elixir
-  random_container = SecureRandom.base64(8)
-  query = Query.create_container(account, random_container)
-  ExOvh.hubic_request(query, %{ openstack: :true })
-  ```
+       Then simply add the application to the project applications list. The supervision
+       tree is then started from the application level.
 
-Get the count of containers again
-  ```elixir
-  query = Query.account_info(account)
-  {:ok, resp} = ExOvh.hubic_request(query, %{ openstack: :true })
-  container_count2 = resp.body |> Enum.count()
-  container_count1 + 1 == container_count2
-  ```
- 
- 
-### Example 2: 
+       ```elixir
+       def application do
+         [
+         applications: [:ex_ovh]
+         ]
+       end
+       ```
 
 
-Adding an object to the "default" container in [OVH CDN Webstorage](https://www.ovh.ie/cdn/webstorage/)
+## Examples
 
-    import ExOvh.Query.Openstack.Swift
-    alias ExOvh.Ovh.OpenstackApi.Webstorage.Cache, as: OpenCache
-    client = ExOvh
-    service = "cdnwebstorage-<your_service_name>"
-    account = OpenCache.get_account(client, service)
-    
-    object_name = "client_file.txt"
-    client_object = Kernel.to_string(:code.priv_dir(:ex_ovh)) <> "/" <> object_name
-    container = "default"
-    server_object = String.replace(object_name, "client", "server")
-    create_file_request = create_object(account, container, client_object, server_object)
-    
-    ExOvh.ovh_request(create_file_request, %{ openstack: :true, webstorage: service })
 
+Get account details and containers for given account
+``` ```
+
+Creating a new container
+``` ```
 
-Listing all objects for "default" container to see if the new `server_object` is there in [OVH CDN Webstorage](https://www.ovh.ie/cdn/webstorage/)
+Get the container count
+``` ```
 
-    import ExOvh.Query.Openstack.Swift
-    alias ExOvh.Ovh.OpenstackApi.Webstorage.Cache, as: OpenCache
-    client = ExOvh
-    service = "cdnwebstorage-<your_service_name>"
-    account = OpenCache.get_account(client, service)
-    request = get_objects(account, "default")
-    
-    {:ok, resp} = ExOvh.ovh_request(request, %{ openstack: :true, webstorage: service })
-    objects = Enum.map(resp.body, &(Map.get(&1, "name")))
-    
-    Enum.member?(objects, server_object)
-      
+Adding an object to the "default" container in [OVH CDN Webstorage](https://www.ovh.ie/cdn/webstorage/)
+``` ```
 
-#### Add more examples ....
+Listing all objects for "default" container in [OVH CDN Webstorage](https://www.ovh.ie/cdn/webstorage/)
+``` ```
 
 
 
@@ -238,17 +291,8 @@ Listing all objects for "default" container to see if the new `server_object` is
 
 - [ ] *Needed* - generate hex docs
 - [ ] *Needed* - generate release and publish to hex packages
-- [ ] *Needed* - *Tests* - add basic tests for most api calls.
-- [ ] *Needed* - *Tests* - verify the supervisor chain, genservers and genserver naming is working ok.
-- [ ] *Needed* - *New functions* - ovh and hubic functions with !.
-
- 
-- [ ] *Maybe* - investigate ways to add sensitive keys, secrets, etc to system env and allow the config.exs to get variables from `System`.
-- [ ] *Maybe* - improve error handling for unexpected responses if possible - hard to find good documentation for expected error responses.
-- [ ] *Maybe* - add a time to live configuration for the validity period of the ovh credential token
-- [ ] *Maybe* - Add some further validations during the mix tasks.
-- [ ] *Maybe* - Add request helper functions to create folders in the hubic api.
-
+- [ ] *Needed* - Tests
+- [ ] *Maybe* - Option to set the application ttl when running ovh mix task.
 
 
 ## Note 
diff --git a/lib/client.ex b/lib/client.ex
index c46ccfa..ad58d1a 100644
--- a/lib/client.ex
+++ b/lib/client.ex
@@ -57,10 +57,6 @@ defmodule ExOvh.Client do
         use Openstex.Swift.V1.Helpers, client: __MODULE__
       end
 
-#      defmodule Keystone do
-#        use Openstex.Helpers.V2.Keystone, client: Keyword.fetch!(opts, :client)
-#      end
-
 
     end
   end
diff --git a/lib/defaults.ex b/lib/defaults.ex
index 5b2ad25..cf7f0e6 100644
--- a/lib/defaults.ex
+++ b/lib/defaults.ex
@@ -20,7 +20,7 @@ defmodule ExOvh.Ovh.Defaults do
 
   def endpoints() do
     %{
-      "ovh-eu"        => "https://api.ovh.com/",
+      "ovh-eu"        => "https://eu.api.ovh.com/",
       "ovh-ca"        => "https://ca.api.ovh.com/",
       "kimsufi-eu"    => "https://eu.api.kimsufi.com/",
       "kimsufi-ca"    => "https://ca.api.kimsufi.com/",
@@ -34,7 +34,7 @@ defmodule ExOvh.Ovh.Defaults do
   def create_app_uri_suffix(), do: "createApp/"
 
 
-  def consumer_key_suffix(), do: "/auth/credential/"
+  def consumer_key_suffix(), do: "/auth/credential"
 
 
   def access_rules() do
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index 3519b90..3226216 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -19,22 +19,20 @@ defmodule Mix.Tasks.Ovh do
   Create an app with access to all apis:
 
       mix ovh \
-      --login=<username> \
+      --login=<username-ovh> \
       --password=<password> \
       --appname='ex_ovh'
 
   Output:
 
       config :ex_ovh,
-        ovh: %{
+        ovh: [
           application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
           application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
           consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
           endpoint: System.get_env("EX_OVH_ENDPOINT"),
-          api_version: System.get_env("EX_OVH_API_VERSION") || "1.0",
-          connect_timeout: 30000, # 30 seconds
-          connect_timeout: (60000 * 30) # 30 minutes
-        }
+          api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
+        ]
 
 
   Create an app with access to all apis with specific app name and description:
@@ -42,10 +40,10 @@ defmodule Mix.Tasks.Ovh do
       mix ovh \
       --login=<username> \
       --password=<password> \
-      --appdescription='my app for api' \
+      --appdescription='Ovh Application for my app' \
       --endpoint='ovh-eu' \
       --apiversion='1.0' \
-      --redirect_uri='http://localhost:4000/' \
+      --redirecturi='http://localhost:4000/' \
       --accessrules='get-[/*]::put-[/me,/cdn]::post-[/me,/cdn]::delete-[]' \
       --appname='my_app'
 
@@ -64,7 +62,7 @@ defmodule Mix.Tasks.Ovh do
 
   ## Notes
 
-  - Access rules: The default for access rules will give your ovh application access to *all* of the api calls. More
+  - Access rules: The default for access rules will give the ovh application access to *all* of the api calls. More
   than likely this is not a good idea. To limit the number of api endpoints available, generate access rules using
   the commandline arguments as seen in the example above.
   """
@@ -86,7 +84,7 @@ defmodule Mix.Tasks.Ovh do
     Mix.Shell.IO.info("")
     Mix.Shell.IO.info("The details in the map above will be used to create the ovh application.")
     Mix.Shell.IO.info("")
-    if Mix.Shell.IO.yes?("Do you want to proceed?") do
+    if Mix.Shell.IO.yes?("Proceed?") do
       HTTPoison.start
       opts_map = parse_args(args)
 
@@ -97,7 +95,7 @@ defmodule Mix.Tasks.Ovh do
 
       Mix.Shell.IO.info(message)
       Mix.Shell.IO.info("")
-      Mix.Shell.IO.info("Update your environment variables and your set.")
+      Mix.Shell.IO.info("Update the environment variables and all is done here.")
       Mix.Shell.IO.info("")
       Mix.Shell.IO.info("For example: ")
       Mix.Shell.IO.info("")
@@ -138,8 +136,8 @@ defmodule Mix.Tasks.Ovh do
       raise "Task requires password argument"
     end
     {opts, %{}}
-    client_name = Keyword.get(opts, :appname, :ex_ovh)
-    if client_name === :nil do
+    application_name = Keyword.get(opts, :appname, :ex_ovh)
+    if application_name === :nil do
       raise "Task requires appname argument"
     end
     {opts, %{}}
@@ -148,49 +146,63 @@ defmodule Mix.Tasks.Ovh do
 
   defp parsers_login({opts, acc}), do: {opts, Map.merge(acc, %{login: Keyword.fetch!(opts, :login)}) }
   defp parsers_password({opts, acc}), do: {opts, Map.merge(acc, %{ password: Keyword.fetch!(opts, :password)}) }
-  defp parsers_client_name({opts, acc}), do: {opts, Map.merge(acc, %{ client_name: Keyword.fetch!(opts, :appname)}) }
+  defp parsers_app_name({opts, acc}), do: {opts, Map.merge(acc, %{ application_name: Keyword.fetch!(opts, :appname)}) }
   defp parsers_endpoint({opts, acc}) do
     endpoint = Keyword.get(opts, :endpoint, :nil)
-    if endpoint === :nil do
-      endpoint = "ovh-eu"
+    endpoint =
+    case endpoint do
+      :nil -> "ovh-eu"
+      _ -> endpoint
     end
     {opts, Map.merge(acc, %{ endpoint: endpoint }) }
   end
   defp parsers_api_version({opts, acc}) do
     api_version = Keyword.get(opts, :apiversion, :nil)
-    if api_version === :nil do
-      api_version = "1.0"
+    api_version =
+    case api_version do
+      :nil -> "1.0"
+      _ -> api_version
     end
     {opts, Map.merge(acc, %{ api_version: api_version }) }
   end
   defp parsers_redirect_uri({opts, acc}) do
     redirect_uri = Keyword.get(opts, :redirecturi, :nil)
-    if redirect_uri === :nil do
-      redirect_uri = ""
+    redirect_uri =
+    case redirect_uri do
+      :nil -> ""
+      _ -> redirect_uri
     end
     {opts, Map.merge(acc, %{ redirect_uri: redirect_uri }) }
   end
+  defp parsers_client_name({opts, acc}) do
+    client_name = Keyword.get(opts, :clientname, :nil)
+    {opts, Map.merge(acc, %{ client_name: client_name }) }
+  end
   defp parsers_app_name({opts, acc}) do
     application_name = Keyword.get(opts, :appname, :nil)
-    if application_name === :nil do
-      application_name = "ex_ovh"
+    application_name =
+    case application_name do
+      :nil -> "ex_ovh"
+      _ -> application_name
     end
     {opts, Map.merge(acc, %{ application_name: application_name }) }
   end
   defp parsers_app_desc({opts, acc}) do
     application_description = Keyword.get(opts, :appdescription, :nil)
-    if application_description === :nil do
-      application_description = "ex_ovh"
+    application_description =
+    case application_description do
+      :nil -> "ex_ovh"
+      _ -> application_description
     end
     {opts, Map.merge(acc, %{ application_description: application_description }) }
   end
   defp parsers_access_rules({opts, acc}) do
     access_rules = Keyword.get(opts, :accessrules, :nil)
+    access_rules =
     if access_rules === :nil do
-      access_rules = Defaults.access_rules()
+      Defaults.access_rules()
     else
-      access_rules = access_rules
-      |> String.split("::")
+      String.split(access_rules, "::")
       |> Enum.map(fn(method_rules) ->
         [method, paths] = String.split(method_rules, "-")
         {method, paths}
@@ -211,7 +223,7 @@ defmodule Mix.Tasks.Ovh do
         List.insert_at(acc, -1, new_rules)
       end)
       |> List.flatten()
-      end
+    end
     {opts, Map.merge(acc, %{access_rules: access_rules}) }
   end
 
@@ -220,7 +232,7 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :get
-    uri = opts_map[:endpoint] <> Defaults.create_app_uri_suffix()
+    uri = Defaults.endpoints()[opts_map[:endpoint]] <> Defaults.create_app_uri_suffix()
     body = ""
     headers = []
     options = @default_options
@@ -275,7 +287,7 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :post
-    uri = opts_map[:endpoint] <> "createApp/"
+    uri = Defaults.endpoints()[opts_map[:endpoint]] <> Defaults.create_app_uri_suffix()
     body = req_body
     headers = [{"Content-Type", "application/x-www-form-urlencoded"}]
     options = @default_options
@@ -323,7 +335,8 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :post
-    uri = opts_map[:endpoint] <> opts_map[:api_version] <> Defaults.consumer_key_suffix()
+    uri = Defaults.endpoints()[opts_map[:endpoint]] <> opts_map[:api_version] <> Defaults.consumer_key_suffix()
+    |> Og.log_return(__ENV__)
     body = %{ accessRules: access_rules, redirection: redirect_uri } |> Poison.encode!()
     headers = Map.merge(Enum.into(@default_headers, %{}), Enum.into([{"X-Ovh-Application", opts_map[:application_key]}], %{})) |> Enum.into([])
     options = @default_options
@@ -414,13 +427,21 @@ defmodule Mix.Tasks.Ovh do
     options = @default_options
     resp = HTTPoison.request!(method, uri, body, headers, options)
 
+    resp |> Og.log_return(__ENV__)
+
     error_msg1 = "Failed to bind the consumer token to the application. Please try to validate the consumer token manually at #{validation_url}"
     error_msg2 = "Invalid validity period entered for the consumer token. Please try to validate the consumer token manually at #{validation_url}"
     cond do
      String.contains?(resp.body, "Invalid validity") ->
       raise error_msg2
-     String.contains?(resp.body, "Your token is now valid, you can use it in your application") ->
+     String.contains?(resp.body, "The token is now valid, it can be used in the application") ->
+      ck
+    String.contains?(resp.body, "Your token is now valid, you can use it in your application") ->
+      ck
+    String.contains?(resp.body, "token is now valid") ->
       ck
+     resp.status_code == 302 && (resp.headers |> Enum.into(%{}) |> Map.has_key?("Location")) ->
+      ck  # presume the validation was successful if redirected to redirect uri
      true ->
       raise error_msg1
     end
@@ -449,20 +470,25 @@ defmodule Mix.Tasks.Ovh do
   end
 
 
-  defp config_names(client_name) do
+  defp config_names(app_name, client_name) do
     Og.context(__ENV__, :debug)
 
     {config_header, mod_client_name} =
-    case client_name  do
+    case app_name do
       "ex_ovh" ->
         {
-          ":" <> client_name,
+          ":" <> app_name,
           "EX_OVH_"
         }
       other ->
+        client_name =
+        case client_name do
+          :nil -> "OvhClient"
+          client_name -> client_name
+        end
         {
-          ":" <> client_name <> ", " <> Macro.camelize(client_name) <> "." <> "ExOvh",
-          String.upcase(other) <> "_EX_OVH_"
+          ":" <> app_name <> ", " <> Macro.camelize(app_name) <> "." <> client_name,
+          String.upcase(other) <> "_" <> Morph.to_snake_caps(client_name) <>"_"
         }
     end
     {config_header, mod_client_name}
@@ -472,7 +498,7 @@ defmodule Mix.Tasks.Ovh do
     env_path = ".env"
     File.touch!(env_path)
     existing = File.read!(env_path)
-    {_config_header, mod_client_name} = config_names(options.client_name)
+    {_config_header, mod_client_name} = config_names(options.application_name, options.client_name)
     format_date = ExOvh.Utils.formatted_date()
     new = existing <>
     ~s"""
@@ -494,24 +520,20 @@ defmodule Mix.Tasks.Ovh do
 
   defp print_config(options) do
     Og.context(__ENV__, :debug)
-
-    client_name = options.client_name
-    {config_header, mod_client_name} = config_names(client_name)
+    {config_header, mod_client_name} = config_names(options.application_name, options.client_name)
 
     ~s"""
 
-    Add the following paragraph to your config.exs file(s):
+    Add the following paragraph to the config.exs file(s):
 
     config #{config_header},
-        ovh: %{
+        ovh: [
           application_key: System.get_env(\"#{mod_client_name <> "APPLICATION_KEY"}\"),
           application_secret: System.get_env(\"#{mod_client_name <> "APPLICATION_SECRET"}\"),
           consumer_key: System.get_env(\"#{mod_client_name <> "CONSUMER_KEY"}\"),
           endpoint: System.get_env(\"#{mod_client_name <> "ENDPOINT"}\"),
-          api_version: System.get_env(\"#{mod_client_name <> "API_VERSION"}\") || "1.0",
-          connect_timeout: 30000, # 30 seconds
-          connect_timeout: (60000 * 30) # 30 minutes
-        }
+          api_version: System.get_env(\"#{mod_client_name <> "API_VERSION"}\") || "1.0"
+        ]
     """
   end
 
diff --git a/mix.exs b/mix.exs
index 3df52ab..44ddc33 100644
--- a/mix.exs
+++ b/mix.exs
@@ -34,6 +34,7 @@ defmodule ExOvh.Mixfile do
       {:floki, "~> 0.7.1"},
       {:calendar, "~> 0.13.2"},
       {:og, "~> 0.1"},
+      {:morph, "~> 0.1.0"},
       # {:openstex, github: "stephenmoloney/openstex", branch: "master"}, # incorporates :poison and httpoison
       {:openstex, path: "../openstex"},
       {:markdown, github: "devinus/markdown"},