intercom-elixir icon indicating copy to clipboard operation
intercom-elixir copied to clipboard

`@http_adapter` doesn't work reliably

Open Sgoettschkes opened this issue 5 years ago • 1 comments

I'm working with the 1.0.0. branch!

The module attribute @http_adapter in the Intercom.API.Request module doesn't work reliably for me. Using iex -S mix to get into the elixir repl, @http_adapter is nil even though Application.get_env(:intercom, :http_adapter) does return the correct value. I'm getting the following error:

** (UndefinedFunctionError) function nil.post/4 is undefined
    nil.post("https://api.intercom.io/users", "{\"custom_attributes\":{\"is_hcp\":true,\"occupation\":\"other\",\"real_country\":\"at\",\"real_first_name\":\"test\",\"real_gender\":\"male\",\"real_last_name\":\"test\",\"real_title\":\"test\",\"real_zip\":\"1060\",\"speciality\":\"\"},\"email\":\"[email protected]\",\"id\":1,\"name\":\"\",\"signed_up_at\":1579171202}", [Authorization: "Bearer dG9rOmMxODQ5MGRlXzQ1NmFfNGE3Ml9hYjJiXzE3Nzc3MDFlNzRiYjoxOjA=", Accept: "application/json", "Content-Type": "application/json"], [])
    (intercom) lib/intercom/api/request.ex:11: Intercom.API.Request.make_request/4
    (intercom) lib/intercom/api.ex:28: Intercom.API.call_endpoint/3

Changing the module to either use HTTPPoison directly or instead of using @http_adaptercalling the following function works:

defp http_adapter() do
    Application.get_env(:intercom, :http_adapter)
  end

I'm not sure what's the best approach to reading modules from the config is.

Sgoettschkes avatar Jan 16 '20 13:01 Sgoettschkes

I just looked up how Phoenix works with the configurable json library. They have a function calling Application.get_env just as I tried (see above). This might be the best approach moving forward.

Sgoettschkes avatar Jan 16 '20 13:01 Sgoettschkes