Sha256: e417ab9e9486c57cccec09bca2dbf023556606475221d8327676a76ddc3e99c6

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 KB

Contents

require 'date'

module Killbill
  module Plugin

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

      def initialize(plugin_name, java_service_map)
        @plugin_name = plugin_name
        @services = {}
        java_service_map.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)
        if api_name == "overdue_user_api"
          return nil
        end
        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

20 entries across 20 versions & 1 rubygems

Version Path
killbill-3.1.3 lib/killbill/killbill_api.rb
killbill-3.1.2 lib/killbill/killbill_api.rb
killbill-3.1.1 lib/killbill/killbill_api.rb
killbill-3.1.0 lib/killbill/killbill_api.rb
killbill-3.0.0 lib/killbill/killbill_api.rb
killbill-2.0.1 lib/killbill/killbill_api.rb
killbill-2.0.0 lib/killbill/killbill_api.rb
killbill-1.9.0 lib/killbill/killbill_api.rb
killbill-1.8.4 lib/killbill/killbill_api.rb
killbill-1.8.3 lib/killbill/killbill_api.rb
killbill-1.8.2 lib/killbill/killbill_api.rb
killbill-1.8.1 lib/killbill/killbill_api.rb
killbill-1.8.0 lib/killbill/killbill_api.rb
killbill-1.7.1 lib/killbill/killbill_api.rb
killbill-1.7.0 lib/killbill/killbill_api.rb
killbill-1.6.0 lib/killbill/killbill_api.rb
killbill-1.5.0 lib/killbill/killbill_api.rb
killbill-1.4.0 lib/killbill/killbill_api.rb
killbill-1.3.0 lib/killbill/killbill_api.rb
killbill-1.2.0 lib/killbill/killbill_api.rb