Sha256: c70512e3c89b8831293ead3c9fe30192259ee6e3f5fdfc9ed001c1d298c9a1c1

Contents?: true

Size: 1.17 KB

Versions: 23

Compression:

Stored size: 1.17 KB

Contents

module ZuoraConnect
  class Login

    def initialize (fields)
      @clients = {}
      if fields["tenant_type"] == "Zuora" && fields["entities"] && fields["entities"].size > 0
        @clients["none"] = ::ZuoraAPI::Login.new(fields.map{|k,v| [k.to_sym, v]}.to_h)
        @default_entity = fields["entities"][0]["id"] if fields["entities"].size == 1
        fields["entities"].each do |entity|
          login_fields = fields.map{|k,v| [k.to_sym, v]}.to_h
          login_fields[:entity_id] = entity["id"]
          @clients[entity["id"]] = ::ZuoraAPI::Login.new(login_fields)
        end
      elsif fields["tenant_type"] == "Zuora"
        @clients["none"] = ::ZuoraAPI::Login.new(fields.map{|k,v| [k.to_sym, v]}.to_h)
      end

      self.attr_builder("available_entities",@clients.keys) if fields["tenant_type"] == "Zuora"

      fields.each do |k,v|
        self.attr_builder(k,v)
      end
      @default_entity ||= "none"
    end

    def attr_builder(field,val)
      singleton_class.class_eval { attr_accessor "#{field}" }
      send("#{field}=", val)
    end

    def client(id = @default_entity)
      return id.blank? ? @clients[@default_entity] : @clients[id]
    end

  end
end


Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
zuora_connect-1.4.0c app/models/zuora_connect/login.rb
zuora_connect-1.4.0b app/models/zuora_connect/login.rb
zuora_connect-1.4.0a app/models/zuora_connect/login.rb
zuora_connect-1.3.8.1 app/models/zuora_connect/login.rb
zuora_connect-1.3.8 app/models/zuora_connect/login.rb
zuora_connect-1.3.7 app/models/zuora_connect/login.rb
zuora_connect-1.3.6 app/models/zuora_connect/login.rb
zuora_connect-1.3.5 app/models/zuora_connect/login.rb
zuora_connect-1.3.4 app/models/zuora_connect/login.rb
zuora_connect-1.3.3 app/models/zuora_connect/login.rb
zuora_connect-1.3.2 app/models/zuora_connect/login.rb
zuora_connect-1.3.1.2 app/models/zuora_connect/login.rb
zuora_connect-1.3.1.1 app/models/zuora_connect/login.rb
zuora_connect-1.3.1 app/models/zuora_connect/login.rb
zuora_connect-1.3.0e app/models/zuora_connect/login.rb
zuora_connect-1.3.0d app/models/zuora_connect/login.rb
zuora_connect-1.3.0c app/models/zuora_connect/login.rb
zuora_connect-1.3.0b app/models/zuora_connect/login.rb
zuora_connect-1.3.0a app/models/zuora_connect/login.rb
zuora_connect-1.2.7 app/models/zuora_connect/login.rb