O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Why an Adapter?

Using an adapter class to mediate interaction with the external service is a good idea even when, like Twitter, the external service already has a Ruby gem. The adapter encapsulates logic that is specific to the interaction between your application and the service.

An adapter is useful if your code has any or all of the following qualities:

  • The external service will be accessed from multiple points in your code.

  • The interaction with the external service has logic of its own, such as authentication or type changing or common sets of options.

  • There’s a mismatch between the language or metaphor of the API and the domain terms and structures of your code.

Our Twitter example doesn’t have the first one, at least not yet. We do have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required