require 'onfido/address_picker'

module Onfido
  class API
    include Requestable
    include AddressPicker

    def url_for(path)
      Onfido.endpoint + path
    end

    def method_missing(method, *args)
      if [:get, :post].include?(method.to_sym)
        make_request(url: args.first.fetch(:url), payload: args.first.fetch(:payload), method: method.to_sym)
      else
        raise NoMethodError.new("undefined method '#{method}' for #{self.class}")
      end
    end

    private

    def headers
      {
        'Authorization' => "Token token=#{Onfido.api_key}",
        'Accept' => "application/json"
      }
    end
  end
end

module Onfido
  class API
    def method_missing(method, *args)
      klass = method.to_s.capitalize
      Object.const_get("Onfido::#{klass}").new
    rescue
      raise NoMethodError.new("undefined method '#{method}' for #{self.class}")
    end
  end
end

Make an API wrapper around the endpoints for better calling
Make an API wrapper around the endpoints for better calling

Now you have to explicitely call a resource before calling its endpoint.
It makes things clearer and will keep consistency between the endpoints
as well e.g.

api = Onfido::API.new
api.applicant.find('applicant_id')
api.address.find('postcode')
