   @moduledoc """
   Client protocol used by `ApiClient` and `OauthClient`.
   """
+  @fallback_to_any true
 
   @type t :: Hipchat.ApiClient.t | Hipchat.OauthClient.t
   @type query_params_t :: [{String.t, String.t}]

      httpc_opts:    httpc_opts,
    }
  end
end

defimpl Hipchat.Client, for: Hipchat.ApiClient do
  alias Hipchat.ApiClient

  def headers(%ApiClient{access_token: nil}), do: []
  def headers(%ApiClient{access_token: a_t}), do: [{"authorization", "Bearer #{a_t}"}]

  def options(%ApiClient{auth_test?: false, httpc_opts: ho}, query_params), do: [{:params, query_params} | ho]
  def options(%ApiClient{auth_test?: true , httpc_opts: ho}, query_params), do: [{:params, [{"auth_test", "true"} | query_params]} | ho]
end

defimpl Hipchat.Client, for: Hipchat.OauthClient do
  alias Hipchat.OauthClient

  def headers(%OauthClient{client_id: ci, client_secret: cs}) do
    encoded = Base.encode64("#{ci}:#{cs}")
    [{"authorization", "Basic #{encoded}"}]
  end

  def options(%OauthClient{httpc_opts: ho}, query_params), do: [{:params, query_params} | ho]
end

      httpc_opts:   httpc_opts,
    }
  end

  alias __MODULE__, as: AC
  defimpl Hipchat.Client do
    def headers(%AC{access_token: nil}), do: []
    def headers(%AC{access_token: a_t}), do: [{"authorization", "Bearer #{a_t}"}]

    def options(%AC{auth_test?: false, httpc_opts: ho}, query_params), do: [{:params, query_params} | ho]
    def options(%AC{auth_test?: true , httpc_opts: ho}, query_params), do: [{:params, [{"auth_test", "true"} | query_params]} | ho]
  end
end

defmodule Hipchat.OauthClient do
