Class: ZuoraConnect::Login
- Inherits:
-
Object
- Object
- ZuoraConnect::Login
- Defined in:
- app/models/zuora_connect/login.rb
Instance Method Summary collapse
- #attr_builder(field, val) ⇒ Object
- #client(id = @default_entity) ⇒ Object
-
#initialize(fields) ⇒ Login
constructor
A new instance of Login.
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 |
# File 'app/models/zuora_connect/login.rb', line 4 def initialize (fields) @clients = {} if fields["tenant_type"] == "Zuora" login_fields = fields.map{|k,v| [k.to_sym, v]}.to_h fields["authentication_type"] = "basic" if fields["authentication_type"].nil? @clients["Default"] = "::ZuoraAPI::#{fields["authentication_type"].capitalize}".constantize.new(login_fields) @default_entity = fields["entities"][0]["id"] if fields["entities"].size == 1 if fields["entities"] && fields["entities"].size > 0 if fields["entities"] && fields["entities"].size > 0 fields["entities"].each do |entity| params = {:entity_id => entity["id"]}.merge(login_fields) @clients[entity["id"]] = "::ZuoraAPI::#{fields["authentication_type"].capitalize}".constantize.new(params) end end self.attr_builder("available_entities", @clients.keys) end fields.each do |k,v| self.attr_builder(k,v) end @default_entity ||= "Default" end |
Instance Method Details
#attr_builder(field, val) ⇒ Object
27 28 29 30 |
# File 'app/models/zuora_connect/login.rb', line 27 def attr_builder(field,val) singleton_class.class_eval { attr_accessor "#{field}" } send("#{field}=", val) end |
#client(id = @default_entity) ⇒ Object
32 33 34 |
# File 'app/models/zuora_connect/login.rb', line 32 def client(id = @default_entity) return id.blank? ? @clients[@default_entity] : @clients[id] end |