twilio / twilio-ruby

A Ruby gem for communicating with the Twilio API and generating TwiML
MIT License
1.35k stars 462 forks source link

feat: Add Faraday 2.0 support #591

Closed tconst closed 2 years ago

tconst commented 2 years ago

Adds support for Faraday 2.x while maintaining backwards compatibility with older versions.

Checklist

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

hosamaly commented 2 years ago

Hi, @JenniferMah. I noticed that you approved some pull requests in this repository recently. Do you think we can move this one forward? It would be helpful to get rid of the deprecation warnings when using twilio-ruby with faraday 1.x.

tremulaes commented 2 years ago

i use twilio in a rails app and this compatibility issue is blocking my upgrade to rails 7- would be great to get this fix out :)

ismasan commented 2 years ago

Hi. Could I help to move this forward? The following is a test for Twilio::HTTP::Client to check that the Basic Authentication middleware is registered correctly depending on Faraday version (which is what this PR is about).

  context 'with different Faraday versions' do
    let(:connection) { Faraday.new }

    before do
      allow(Faraday).to receive(:new).and_return(connection).and_yield(connection)
      allow(connection).to receive(:request)
      allow(connection).to receive(:send).and_return(double('response', status: 301, body: {}, headers: {}))
    end

    it 'should set basic authorization with Faraday 1.x' do
      stub_const('Faraday::VERSION', '1.5')
      issue_request_with_auth('a', 'b')
      expect(connection).to have_received(:request).with(:basic_auth, 'a', 'b')
      expect(connection).not_to have_received(:request).with(:authorization, :basic, 'a', 'b')
    end

    it 'should set basic authorization with Faraday 2.x' do
      stub_const('Faraday::VERSION', '2.2')
      issue_request_with_auth('a', 'b')
      expect(connection).to have_received(:request).with(:authorization, :basic, 'a', 'b')
      expect(connection).not_to have_received(:request).with(:basic_auth, 'a', 'b')
    end

    def issue_request_with_auth(username, pwd)
      @client.request('host', 'port', 'GET', 'url', {}, {}, {}, [username, pwd], nil)
    end
  end

If helpful, let me know if you prefer this in patch form, or as a pull request to this branch.

tconst commented 2 years ago

It looks like rubocop is flagging the method length with this change, is there any preference on how you all would like me to resolve?

ismasan commented 2 years ago

Those methods flagged by Rubocop weren't changed in this PR, so perhaps that should be dealt with separately? Otherwise it risks widening the scope of this change. I agree that those argument lists are a bit unwieldy at the moment.

chrismanderson commented 2 years ago

Any updates on getting this PR completed and released? Even a stab at timing would be appreciated - this is the last gem my applications need an update to support Rails 7.

BrianHawley commented 2 years ago

@tconst the current rubocop complaint is definitely related to the method being changed. Since it's a method length complaint, you could just add disabling pragma comments around that method definition:

# rubocop:disable Metrics/MethodLength
def _request(request)
  # ...
end
# rubocop:enable Metrics/MethodLength
tconst commented 2 years ago

@BrianHawley Yea I was hoping to get a response from the maintainers on this, I can either disable the cop or move the conditional out into another method. I'll go ahead and disable for now.

michalkorzawski commented 2 years ago

Hey @JenniferMah, could you or anyone please merge this PR? I'm working on rails 7 app and this faraday thing it's totally blocking my work

v-kumar commented 2 years ago

We are also waiting on the same and it is blocking our upgrade to Faraday 2.0 and Rails 7.0