Sha256: 14b44565a4e386caf36c775d6d6988c65d13e408cf9740eb0f6252bdaa8aaf27

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

require 'date'

module Killbill
  module Plugin

    #
    # Represents a subset of the Killbill Apis offered to the ruby plugins
    #
    class KillbillApi

      # @VisibleForTesting
      attr_reader :proxied_services

      def initialize(plugin_name, proxied_services)
        @plugin_name = plugin_name
        @proxied_services = proxied_services
        @services = {}
        proxied_services.each do |k,v|
          @services[k.to_sym] = create_proxy_api(k, v)
        end
      end

      #
      # Returns the proxy to the java api
      #
      def method_missing(m, *args, &block)
        return @services[m.to_sym] if @services.include? m.to_sym
        raise NoMethodError.new("undefined method `#{m}' for #{self}")
      end

      def create_context(tenant_id=nil, user_token=nil, reason_code=nil, comments=nil)
        context = Killbill::Plugin::Model::CallContext.new
        context.tenant_id= tenant_id
        context.user_token= user_token
        context.user_name= @plugin_name
        context.call_origin= :EXTERNAL
        context.user_type= :SYSTEM
        context.reason_code= reason_code
        context.comments= comments
        context.created_date= DateTime.new
        context.updated_date= DateTime.new
        context
      end

      private

      def create_proxy_api(api_name, java_api)
        proxy_class_name = "Killbill::Plugin::Api::#{api_name.to_s.split('_').map{|e| e.capitalize}.join}"
        proxy_class_name.to_class.new(java_api)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
killbill-7.0.2 lib/killbill/killbill_api.rb
killbill-7.0.1 lib/killbill/killbill_api.rb
killbill-7.0.0 lib/killbill/killbill_api.rb
killbill-6.5.0 lib/killbill/killbill_api.rb
killbill-6.4.0 lib/killbill/killbill_api.rb
killbill-6.3.0 lib/killbill/killbill_api.rb
killbill-6.2.0 lib/killbill/killbill_api.rb
killbill-6.1.0 lib/killbill/killbill_api.rb
killbill-6.0.0 lib/killbill/killbill_api.rb
killbill-5.2.0 lib/killbill/killbill_api.rb
killbill-5.1.0 lib/killbill/killbill_api.rb
killbill-5.0.0 lib/killbill/killbill_api.rb
killbill-4.4.0 lib/killbill/killbill_api.rb
killbill-4.3.0 lib/killbill/killbill_api.rb
killbill-4.2.0 lib/killbill/killbill_api.rb
killbill-4.1.0 lib/killbill/killbill_api.rb
killbill-4.0.0 lib/killbill/killbill_api.rb