Class: InstantQuote::AdapterFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/instant_quote/adapter_finder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ AdapterFinder

Returns a new instance of AdapterFinder.



22
23
24
25
26
27
28
29
30
31
# File 'lib/instant_quote/adapter_finder.rb', line 22

def initialize(connection)
  @connection = connection
  @adapter_name = connection.adapter

  validate_adapter_name!

  @adapter = Object.const_get("InstantQuote::Adapters::#{adapter_class}")
  @translator = Object.const_get("InstantQuote::ConnectionTranslators::#{adapter_class}")
  @decision_parser = Object.const_get("InstantQuote::DecisionParsers::#{adapter_class}")
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



20
21
22
# File 'lib/instant_quote/adapter_finder.rb', line 20

def adapter
  @adapter
end

#connectionObject (readonly)

Returns the value of attribute connection.



20
21
22
# File 'lib/instant_quote/adapter_finder.rb', line 20

def connection
  @connection
end

#decision_parserObject (readonly)

Returns the value of attribute decision_parser.



20
21
22
# File 'lib/instant_quote/adapter_finder.rb', line 20

def decision_parser
  @decision_parser
end

#translatorObject (readonly)

Returns the value of attribute translator.



20
21
22
# File 'lib/instant_quote/adapter_finder.rb', line 20

def translator
  @translator
end

Class Method Details

.available_adaptersObject



33
34
35
36
# File 'lib/instant_quote/adapter_finder.rb', line 33

def self.available_adapters
  Dir.glob('*.rb', base: File.expand_path('adapters', __dir__))
     .map { |adapter| adapter.sub('.rb', '') }
end

Instance Method Details

#accept_offer(offer_id) ⇒ Object



62
63
64
# File 'lib/instant_quote/adapter_finder.rb', line 62

def accept_offer(offer_id)
  adapter.accept_offer(connection.external_id, connection, offer_id)
end

#additional_fieldsObject



66
67
68
# File 'lib/instant_quote/adapter_finder.rb', line 66

def additional_fields
  adapter.additional_fields
end

#get_approvalObject



58
59
60
# File 'lib/instant_quote/adapter_finder.rb', line 58

def get_approval
  adapter.get_approval(connection.external_id, connection)
end


38
39
40
# File 'lib/instant_quote/adapter_finder.rb', line 38

def get_link
  adapter.get_link(connection)
end

#get_preapprovalObject



52
53
54
55
56
# File 'lib/instant_quote/adapter_finder.rb', line 52

def get_preapproval
  params = translator.translate(connection)

  adapter.get_preapproval(params, connection)
end

#get_quoteObject



42
43
44
45
46
# File 'lib/instant_quote/adapter_finder.rb', line 42

def get_quote
  params = translator.translate(connection)

  adapter.get_quote(params, connection)
end

#get_statusObject



48
49
50
# File 'lib/instant_quote/adapter_finder.rb', line 48

def get_status
  adapter.get_status(connection.external_id, connection)
end

#parse_decisionObject



70
71
72
# File 'lib/instant_quote/adapter_finder.rb', line 70

def parse_decision
  decision_parser.new(connection.approval_decision_info)
end