Sha256: 59715c6818ee8bbaee56724eb15116f1bb850e304b5b8dd4e9e69db5a57227a8

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require 'finapps_core'
require_relative './version'

module FinApps
  module REST
    class Client < FinAppsCore::REST::BaseClient # :nodoc:
      RESOURCES = %i(
        institutions
        institutions_forms
        orders
        order_assignments
        order_notifications
        order_refreshes
        order_reports
        order_statuses
        order_tokens
        operators
        operators_password_resets
        password_resets
        products
        sessions
        statements
        consumers
        consumer_institution_refreshes
        user_institutions
        user_institutions_forms
        user_institutions_statuses
        version
      ).freeze

      # @param [String] tenant_token
      # @param [Hash] options
      # @return [FinApps::REST::Client]
      def initialize(tenant_token, options={}, logger=nil)
        not_blank(tenant_token, :tenant_token)

        merged_options = options.merge(tenant_token: tenant_token)
        super(merged_options, logger)
      end

      def method_missing(symbol, *arguments, &block)
        if RESOURCES.include? symbol
          class_name = camelize(symbol.to_s)
          variable = "@#{class_name.downcase}"
          unless instance_variable_defined? variable
            klass = Object.const_get('FinApps').const_get('REST').const_get class_name
            instance_variable_set(variable, klass.new(self))
          end
          instance_variable_get(variable)
        else
          super
        end
      end

      def respond_to_missing?(method_sym, include_private=false)
        RESOURCES.include?(method_sym) ? true : super
      end

      private

      def camelize(term)
        string = term.to_s
        string = string.sub(/^[a-z\d]*/) { $&.capitalize }
        string.gsub!(%r{(?:_|(/))([a-z\d]*)}) { $2.capitalize.to_s }
        string
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
finapps-3.0.6 lib/finapps/rest/client.rb
finapps-3.0.5 lib/finapps/rest/client.rb
finapps-3.0.4 lib/finapps/rest/client.rb
finapps-3.0.3 lib/finapps/rest/client.rb
finapps-3.0.2 lib/finapps/rest/client.rb
finapps-3.0.1 lib/finapps/rest/client.rb
finapps-2.3.7 lib/finapps/rest/client.rb
finapps-2.3.6 lib/finapps/rest/client.rb
finapps-2.3.5 lib/finapps/rest/client.rb
finapps-2.3.3 lib/finapps/rest/client.rb