How to create a custom API connector in Ruby

In the How to use the httparty Ruby gem section, we walked through the httparty Ruby gem segment and we discussed how to integrate built-in classes from the gem to call an API. If you need something more specific, it's a good idea to create a separate class to manage the API processes. That's what we are going to do here while still leveraging some of the key modules supplied by HTTParty:

require 'rubygems'   require 'httparty'class StackExchange  include HTTParty  base_uri 'api.stackexchange.com'end 

In this code, we created a class called StackExchange. As the first step, we included the HTTParty module so that this class can access the methods provided by the gem. Next, we set base_uri, which is ...

Get Comprehensive Ruby Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.