ewildgoose / elixir-xml_rpc

Encode and decode elixir terms to XML-RPC parameters
Apache License 2.0
40 stars 17 forks source link

Example of HTTPoison wrapping does not work #2

Closed houshuang closed 9 years ago

houshuang commented 9 years ago

I defined the XMLRPC module like specified, and tried the example in iex:

iex(1)> request = %XMLRPC.MethodCall{method_name: "test.sumprod", params: [2,3]}
%XMLRPC.MethodCall{method_name: "test.sumprod", params: [2, 3]}
iex(2)> response = HTTPoison.post!("http://www.advogato.org/XMLRPC", request_body).body
** (RuntimeError) undefined function: request_body/0

iex(2)> response = HTTPoison.post!("http://www.advogato.org/XMLRPC", request).body
** (CaseClauseError) no case clause matching: %XMLRPC.MethodCall{method_name: "test.sumprod", params: [2, 3]}
      (hackney) src/hackney_client/hackney_request.erl:309: :hackney_request.handle_body/4
      (hackney) src/hackney_client/hackney_request.erl:79: :hackney_request.perform/2
      (hackney) src/hackney_client/hackney.erl:357: :hackney.send_request/2
    (httpoison) lib/httpoison.ex:60: HTTPoison.request/5
    (httpoison) lib/httpoison.ex:60: HTTPoison.request!/5
iex(2)>
ewildgoose commented 9 years ago

I think your error is just the typo "request_body", where it should be "request". I have corrected this in the README, but the point is that the first line assigns a variable, and the second processes it. Sorry for the typo.

Note, remember this project doesn't import HTTPoison, so be sure to setup some new project and add it to your dependencies for testing the above. Otherwise you will start to get errors about HTTPoison not being found. I'm using this wrapper syntax in anger for a real project - you can have HTTPoison do quite a lot of fixup for you!