Class: ZuoraConnect::Login

Inherits:
Object
  • Object
show all
Defined in:
app/models/zuora_connect/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields) ⇒ Login

Returns a new instance of Login.


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/zuora_connect/login.rb', line 4

def initialize (fields)
  self.clients = {}
  self.identifier_to_ids = {}
  if fields["tenant_type"] == "Zuora"
     = fields.map{|k,v| [k.to_sym, v]}.to_h
     = fields.dig("authentication_type").blank? ? 'Basic' : fields.dig("authentication_type").capitalize
    
    raise ZuoraConnect::Exceptions::InvalidCredentialSet.new("Cannot setup application with ZSession Login.") if  == "Session"
    self.clients["Default"] = "::ZuoraAPI::#{}".constantize.new(**)
    self.default_entity = fields["entities"][0]["id"] if (fields.dig("entities") || []).size == 1
    if fields["entities"] && fields["entities"].size > 0
      fields["entities"].each do |entity|
        params = {:entity_id => entity["id"], :entity_identifier => entity["identifier"]}.merge()
        self.clients[entity["id"]] =  "::ZuoraAPI::#{}".constantize.new(**params)
        self.identifier_to_ids[entity["identifier"]] = entity["id"]
      end
    end
    self.attr_builder("available_entities", self.clients.keys) 
  end
  fields.each do |k,v|
    self.attr_builder(k,v)
  end
  self.default_entity ||= "Default"
end

Instance Attribute Details

#clientsObject

Returns the value of attribute clients.


3
4
5
# File 'app/models/zuora_connect/login.rb', line 3

def clients
  @clients
end

#default_entityObject

Returns the value of attribute default_entity.


3
4
5
# File 'app/models/zuora_connect/login.rb', line 3

def default_entity
  @default_entity
end

#identifier_to_idsObject

Returns the value of attribute identifier_to_ids.


3
4
5
# File 'app/models/zuora_connect/login.rb', line 3

def identifier_to_ids
  @identifier_to_ids
end

Instance Method Details

#attr_builder(field, val) ⇒ Object


29
30
31
32
# File 'app/models/zuora_connect/login.rb', line 29

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

#client(id = self.default_entity) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/zuora_connect/login.rb', line 34

def client(id = self.default_entity)
  use_entity_name = self.identifier_to_ids.keys.include?(id)

  # Translate entity name to entity id
  id = self.identifier_to_ids[id] if use_entity_name

  client = id.blank? ? self.clients[self.default_entity] : self.clients[id]

  if client
    client.entity_header_type = use_entity_name ? :entity_name : :entity_id
  end

  client
end