Commit 74508a6227ae42de193466f804c3428d9de62a7e

Stephen Moloney 2017-04-18T16:10:24

fix adapter issue

diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index ec1a6a3..5cd4dbe 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -27,7 +27,7 @@ defmodule Mix.Tasks.Ovh do
           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")
-        ]
+       ]
 
   See the [mix task documentation]((https://github.com/stephenmoloney/ex_ovh/blob/master/docs/mix_task.md).
   """
@@ -35,7 +35,7 @@ defmodule Mix.Tasks.Ovh do
   alias ExOvh.Defaults
   @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
   @default_adapter HTTPipe.Adapters.Hackney
-  @default_hackney_options [ timeout: 30000, recv_timeout: (60000 * 1) ]
+  @default_hackney_options [timeout: 30000, recv_timeout: (60000 * 1)]
   @default_name "ex_ovh"
   @default_description "ex_ovh application"
   @default_redirect_uri ""
@@ -112,9 +112,9 @@ defmodule Mix.Tasks.Ovh do
   end
 
 
-  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_app_name({opts, acc}), do: {opts, Map.merge(acc, %{ application_name: Keyword.fetch!(opts, :appname)}) }
+  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_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)
     endpoint =
@@ -122,7 +122,7 @@ defmodule Mix.Tasks.Ovh do
       :nil -> "ovh-eu"
       _ -> endpoint
     end
-    {opts, Map.merge(acc, %{ endpoint: endpoint }) }
+    {opts, Map.merge(acc, %{endpoint: endpoint})}
   end
   defp parsers_api_version({opts, acc}) do
     api_version = Keyword.get(opts, :apiversion, :nil)
@@ -131,33 +131,26 @@ defmodule Mix.Tasks.Ovh do
       :nil -> "1.0"
       _ -> api_version
     end
-    {opts, Map.merge(acc, %{ api_version: api_version }) }
+    {opts, Map.merge(acc, %{api_version: api_version})}
   end
   defp parsers_redirect_uri({opts, acc}) do
     redirect_uri = Keyword.get(opts, :redirecturi, @default_redirect_uri)
-    {opts, Map.merge(acc, %{ redirect_uri: redirect_uri }) }
+    {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 }) }
+    {opts, Map.merge(acc, %{client_name: client_name})}
   end
   defp parsers_app_name({opts, acc}) do
     application_name = Keyword.get(opts, :appname, @default_name)
-    application_name =
-    case application_name do
-      :nil -> "ex_ovh"
-      _ -> application_name
-    end
-    {opts, Map.merge(acc, %{ application_name: application_name }) }
+    application_name = application_name && application_name || @default_name
+    {opts, Map.merge(acc, %{application_name: application_name})}
   end
   defp parsers_app_desc({opts, acc}) do
     application_description = Keyword.get(opts, :appdescription, :nil)
-    application_description =
-    case application_description do
-      :nil -> Keyword.get(opts, :appname, @default_description)
-      _ -> application_description
-    end
-    {opts, Map.merge(acc, %{ application_description: application_description }) }
+    application_description = application_description && application_description ||
+    Keyword.get(opts, :appname, @default_description)
+    {opts, Map.merge(acc, %{application_description: application_description})}
   end
   defp parsers_access_rules({opts, acc}) do
     access_rules = Keyword.get(opts, :accessrules, :nil)
@@ -181,13 +174,13 @@ defmodule Mix.Tasks.Ovh do
           %{
             method: String.upcase(method),
             path: path
-           }
+          }
         end)
         List.insert_at(acc, -1, new_rules)
       end)
       |> List.flatten()
     end
-    {opts, Map.merge(acc, %{access_rules: access_rules}) }
+    {opts, Map.merge(acc, %{access_rules: access_rules})}
   end
 
 
@@ -204,10 +197,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
 
     conn.response.body
@@ -261,10 +254,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
     body = conn.response.body
 
@@ -307,7 +300,7 @@ defmodule Mix.Tasks.Ovh do
   defp get_consumer_key(%{access_rules: access_rules, redirect_uri: redirect_uri} = opts_map) do
     method = :post
     url = Defaults.endpoints()[opts_map[:endpoint]] <> opts_map[:api_version] <> Defaults.consumer_key_suffix()
-    body = %{ accessRules: access_rules, redirection: redirect_uri } |> Poison.encode!()
+    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_hackney_options
 
@@ -317,10 +310,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
 
     body = Poison.decode!(conn.response.body)
@@ -341,10 +334,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
 
     conn.response.body
@@ -412,10 +405,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
 
     case check_for_successful_binding(conn.response, validation_url, ck) do
@@ -493,10 +486,10 @@ defmodule Mix.Tasks.Ovh do
         url: url,
         body: body,
         headers: headers
-      },
+     },
       adapter: @default_adapter,
       adapter_options: options
-    }
+   }
     {:ok, conn} = HTTPipe.Conn.execute(conn)
 
     error_msg = "function check_for_successful_binding seems to be entering an error loop"
@@ -515,9 +508,9 @@ defmodule Mix.Tasks.Ovh do
       application_secret: get_application_secret(create_app_body),
       application_name: get_application_name(create_app_body),
       application_description: get_application_description(create_app_body)
-    })
+   })
     ck = get_consumer_key(opts_map) |> bind_consumer_key_to_app(opts_map)
-    Map.merge(opts_map, %{ consumer_key: ck })
+    Map.merge(opts_map, %{consumer_key: ck})
     |> Map.delete(:login) |> Map.delete(:password)
   end
 
@@ -537,17 +530,13 @@ defmodule Mix.Tasks.Ovh do
         {
           ":" <> app_name,
           "EX_OVH_"
-        }
+       }
       other ->
-        client_name =
-        case client_name do
-          :nil -> "OvhClient"
-          client_name -> client_name
-        end
+        client_name = client_name && client_name || "OvhClient"
         {
           ":" <> app_name <> ", " <> Macro.camelize(app_name) <> "." <> client_name,
           String.upcase(other) <> "_" <> String.upcase(Macro.underscore(client_name)) <>"_"
-        }
+       }
     end
     {config_header, mod_client_name}
   end
@@ -594,7 +583,7 @@ defmodule Mix.Tasks.Ovh do
           consumer_key: System.get_env(\"#{mod_client_name <> "CONSUMER_KEY"}\"),
           endpoint: \"#{options.endpoint}\",
           api_version: \"#{options.api_version}\"
-        ]
+       ]
     """
   end
 
diff --git a/mix.lock b/mix.lock
index 2bf2e2f..dff676a 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,8 +1,8 @@
 %{"calendar": {:hex, :calendar, "0.17.2", "d6b7bccc29c72203b076d4e488d967780bf2d123a96fafdbf45746fdc2fa342c", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, optional: false]}]},
   "certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []},
   "earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []},
-  "ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
-  "floki": {:hex, :floki, "0.15.0", "c5b7ac5d585c93da4cec61fc9bac7b8c2655883a085d740871057aa30a0f1258", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, optional: false]}]},
+  "ex_doc": {:hex, :ex_doc, "0.15.1", "d5f9d588fd802152516fccfdb96d6073753f77314fcfee892b15b6724ca0d596", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
+  "floki": {:hex, :floki, "0.17.0", "ee23700dac178f601ae8cd05f8d8890a3dfd131fba8972dd3676bcedcb14a18d", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, optional: false]}]},
   "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
   "hoedown": {:git, "https://github.com/hoedown/hoedown.git", "980b9c549b4348d50b683ecee6abee470b98acda", []},
   "httpipe": {:hex, :httpipe, "0.9.0", "4db66493b0ec2a86d142ea959a62e221d6ddb23ab48a676b691be3a16c38a415", [:mix], []},
@@ -14,4 +14,4 @@
   "mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], []},
   "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
   "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
-  "tzdata": {:hex, :tzdata, "0.5.11", "3d5469a9f46bdf4a8760333dbdabdcc4751325035c454b10521f71e7c611ae50", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}}
+  "tzdata": {:hex, :tzdata, "0.5.12", "1c17b68692c6ba5b6ab15db3d64cc8baa0f182043d5ae9d4b6d35d70af76f67b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}}