Sha256: ce5bdf319adc39214649931d341c490609b93b5cd0c5b37383c75c4049c34e33

Contents?: true

Size: 1.32 KB

Versions: 13

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module FinApps
  module REST
    class PortfoliosConsumers < FinAppsCore::REST::Resources
      include FinApps::Utils::QueryBuilder

      def list(portfolio_id, params = nil)
        not_blank(portfolio_id, :portfolio_id)

        path = build_path(portfolio_id)
        return super path if params.nil?

        raise FinAppsCore::InvalidArgumentsError, 'Invalid argument: params' unless params.is_a? Hash

        super build_query_path(path, params)
      end

      def create(portfolio_id, params)
        not_blank(portfolio_id, :portfolio_id)
        not_blank(params, :params)

        return super nil, build_path(portfolio_id, params) if params.is_a?(String) # Single Consumer Subscribe

        # Array Consumer Subscribe
        super params, build_path(portfolio_id)
      end

      def destroy(portfolio_id, consumer_id)
        not_blank(portfolio_id, :portfolio_id)
        not_blank(consumer_id, :consumer_id)

        # Single Consumer Unsubscribe Only
        super nil, build_path(portfolio_id, consumer_id)
      end

      private

      def build_path(portfolio_id, consumer_id = nil)
        consumer_path = consumer_id ? "consumers/#{ERB::Util.url_encode(consumer_id)}" : 'consumers'
        "portfolios/#{ERB::Util.url_encode(portfolio_id)}/" + consumer_path
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
finapps-5.0.3 lib/finapps/rest/portfolios_consumers.rb
finapps-5.0.2 lib/finapps/rest/portfolios_consumers.rb
finapps-5.0.1 lib/finapps/rest/portfolios_consumers.rb
finapps-5.0.0 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.16 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.15 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.14 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.12 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.11 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.10 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.9 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.8 lib/finapps/rest/portfolios_consumers.rb
finapps-4.0.7 lib/finapps/rest/portfolios_consumers.rb