Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPoison.Base behaviour #330

Merged
merged 2 commits into from
May 19, 2018
Merged

HTTPoison.Base behaviour #330

merged 2 commits into from
May 19, 2018

Conversation

JoeMerriweather-Webb
Copy link
Contributor

This makes HTTPoison.Base a behaviour module.

This has the following benefits:

  • Functions in the callback module that uses HTTPoison.Base can be marked with @impl
  • It can now be used directly with Mox without a wrapping module.

This will cause warnings if the callback module using HTTPoison.Base overrides functions that are public with private ones.

It looks like it does not work with behaviours to mix def and defp
and results in warnings like:

warning: function process_request_headers/1 required by behaviour HTTPoison.Base was implemented as "defp" but should have been "def" (in module HTTPoisonBaseTest.ExampleDefp)
    test/httpoison_base_test.exs:16
@JoeMerriweather-Webb JoeMerriweather-Webb changed the title Add callbacks HTTPoison.Base behaviour May 10, 2018
@@ -50,20 +39,6 @@ defmodule HTTPoisonBaseTest do
assert validate :hackney
end

test "request body using ExampleDefp" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it does not work with behaviours to mix def and defp
and results in warnings like:

warning: function process_request_headers/1 required by behaviour HTTPoison.Base was implemented as "defp" but should have been "def" (in module HTTPoisonBaseTest.ExampleDefp)
    test/httpoison_base_test.exs:16

@whatyouhide
Copy link
Contributor

I am all for making Base a behaviour, I think it's definitely the way to go. The problem with private functions is that callbacks have to be public by design, so you'd have to turn all those defps into public functions which would be a breaking change because people are implementing them as private functions and you expect them to implement those as public functions now. I don't know what a good solution might be other than living with the warnings and telling folks to update those functions to be public.

@edgurgel
Copy link
Owner

Yeah I think we can push this forward and make them public. I will play with it this week and we can release a new version soon. Thanks, @JosephMichaelWebb & @whatyouhide

@edgurgel edgurgel merged commit 88e3967 into edgurgel:master May 19, 2018
@edgurgel
Copy link
Owner

Ok we can release this as a minor version as it's just a warning. I think it's ok to no bump a major version for this. I will release this soon ! Thanks 👍

bcardarella added a commit to bcardarella/mojito that referenced this pull request Jun 19, 2020
This PR does not change the public API at all but will reorganize the primary Mojito base
module functions into a Mojito.Base module meants to be pulled in via `use`.

This PR also includes behaviour and callbacks for all Mojito functions for the purpose
of compatibility with Mox.

The implementation was borrowed from HTTPoison: edgurgel/httpoison#330

Some additional types were added for readability.
gamache pushed a commit to appcues/mojito that referenced this pull request Jun 22, 2020
This PR does not change the public API at all but will reorganize the primary Mojito base
module functions into a Mojito.Base module meants to be pulled in via `use`.

This PR also includes behaviour and callbacks for all Mojito functions for the purpose
of compatibility with Mox.

The implementation was borrowed from HTTPoison: edgurgel/httpoison#330

Some additional types were added for readability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants