0
我运行下面的代码实现协议:错误 - 在灵药
ExHubic.Request.request({:get, "/account", nil, :hubic}, ExHubic)
,并得到以下错误:
** (Protocol.UndefinedError) protocol ExHubic.Request not implemented for {:get, "/account", nil, :hubic}
(ex_hubic) lib/request.ex:1: ExHubic.Request.impl_for!/1
(ex_hubic) lib/request.ex:6: ExHubic.Request.request/2
此错误消息建议,我认为该协议未实现对于定义为@type t :: {atom, String.t, any, :hubic}
的ExHubic.Query.Hubic.t
类型
这可能是我创建的类型的问题,但我看不到它。
一些背景:
defprotocol ExHubic.Request do
@moduledoc false
@spec request(query :: ExHubic.Query.t, client :: atom)
:: ExHubic.Query.http_query_t
def request(query, client)
end
defimpl ExHubic.Request, for: ExHubic.Query.Hubic do
@spec request(query :: ExHubic.Query.Hubic.t, client :: atom)
:: {:ok, ExHubic.Client.response_t} | {:error, ExHubic.Client.response_t}
def request({method, uri, params, :hubic} = query, client) do
implementation_details
end
end
defmodule ExHubic.Query do
@moduledoc false
@type t :: {atom, String.t, any, atom}
end
defmodule ExHubic.Query.Hubic do
@type t :: {atom, String.t, any, :hubic}
@spec account() :: __MODULE__.t
def account(), do: {:get, "/account", :nil, :hubic}
end
我碰到了我以前的尝试的问题。你的答案可能是正确的答案,但我还没有能够成功实现这一点。我不会在电脑桌上呆几周。关于元组不允许的一点是绝对正确的,并且使我走上了正确的道路。但是我还不确定查询或客户端应该是第一个参数。当我回到办公桌时,我需要进一步调查。谢谢。 –
将元组更改为修复它的结构。为参考目的:文件:[查询](https://github.com/stephenmoloney/ex_hubic/blob/master/lib/query/hubic.ex),[协议](https://github.com/stephenmoloney/ex_hubic /blob/master/lib/request.ex),[Protocol Impl](https://github.com/stephenmoloney/ex_hubic/blob/master/lib/request/hubic/request.ex) –