Class: AmsLayout::Client

Inherits:
Object
  • Object
show all
Includes:
Pages
Defined in:
lib/ams_layout/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Pages

#browser

Constructor Details

#initializeClient

Returns a new instance of Client.



20
21
22
23
# File 'lib/ams_layout/client.rb', line 20

def initialize
  # Make sure the configuration has been initialized.
  AmsLayout.configure
end

Instance Attribute Details

#delegate_class_nameObject



29
30
31
# File 'lib/ams_layout/client.rb', line 29

def delegate_class_name
  @delegate_class_name ||= AmsLayout.configuration.delegate_class_name
end

#layout_class_nameObject



25
26
27
# File 'lib/ams_layout/client.rb', line 25

def layout_class_name
  @layout_class_name ||= AmsLayout.configuration.layout_class_name
end

Instance Method Details

#base_urlObject

Return the base url for the current environment



62
63
64
# File 'lib/ams_layout/client.rb', line 62

def base_url
  return AmsLayout.configuration.base_urls[environment]
end

#credentialsObject

Return the credentials for the current environment



55
56
57
# File 'lib/ams_layout/client.rb', line 55

def credentials
  return AmsLayout.configuration.credentials[environment]
end

#environmentObject

Return the current environment



47
48
49
50
# File 'lib/ams_layout/client.rb', line 47

def environment
  @env ||= AmsLayout.configuration.default_environment
  @env
end

#environment=(env) ⇒ Object

Set the current environment



36
37
38
39
40
41
42
# File 'lib/ams_layout/client.rb', line 36

def environment=(env)
  raise "Unknown environment [#{env}]" unless AmsLayout.configuration.credentials.key?(env)
  @env = env
  AmsLayout.configure do |config|
    config.default_environment = env
  end
end

#get_field_dataObject

Retrieve field data from Loan Entry (Prequal) screen



99
100
101
102
103
104
# File 'lib/ams_layout/client.rb', line 99

def get_field_data
  prequal = PrequalDetail.new(browser, true)
  parser = Parser.new
  parser.parse prequal.html
  parser.layout
end

#login(username, password, options = {}) ⇒ Object

Login to the Admin Module

If we’re already logged in, do nothing unless the force flag is true.

force force a re-login if we’ve already logged in



73
74
75
76
77
78
# File 'lib/ams_layout/client.rb', line 73

def (username, password, options = {})
  force = options.fetch(:force) { false }

  logout
  (force). username, password
end

#logoutObject



80
81
82
83
# File 'lib/ams_layout/client.rb', line 80

def logout
  .logout
  @login_page = nil
end

#quitObject

Close the browser



88
89
90
91
92
93
94
# File 'lib/ams_layout/client.rb', line 88

def quit
  unless @browser.nil?
    logout
    @browser.close
    @browser = nil
  end
end

#write_alias_example(layout_file_path) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ams_layout/client.rb', line 113

def write_alias_example layout_file_path
  layout = YAML::load_file(layout_path(layout_file_path))
  aliases = {}

  layout.each do |, fields|
    fields.each do |fld|
      label = fld[:label]
      aliases[label] = [
        "Alias1 #{label}",
        "Alias2 #{label}"
      ]
    end # fields
  end # layout

  File.write "#{layout_path(layout_file_path)}.aliases.example", YAML.dump(aliases)
end

#write_delegate_class(path, layout_file_path) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ams_layout/client.rb', line 144

def write_delegate_class path, layout_file_path
  assert_file_exists layout_path(layout_file_path)

  layout = YAML::load_file(layout_path(layout_file_path))
  aliases = YAML::load_file("#{layout_path(layout_file_path)}.aliases") if File.exist?("#{layout_path(layout_file_path)}.aliases")
  writer = DelegateWriter.new
  writer.class_name = delegate_class_name
  writer.aliases = aliases unless aliases.nil?

  File.open(delegate_class_path(path), 'w') do |f|
    writer.write f, layout
  end
end

#write_layout(path, write_alias_example = false) ⇒ Object



106
107
108
109
110
111
# File 'lib/ams_layout/client.rb', line 106

def write_layout path, write_alias_example = false
  layout = get_field_data
  File.write layout_path(path), YAML.dump(layout)

  write_alias_example layout_path(path) if write_alias_example
end

#write_layout_class(path, layout_file_path) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ams_layout/client.rb', line 130

def write_layout_class path, layout_file_path
  assert_file_exists layout_path(layout_file_path)

  layout = YAML::load_file(layout_path(layout_file_path))
  aliases = YAML::load_file("#{layout_path(layout_file_path)}.aliases") if File.exist?("#{layout_path(layout_file_path)}.aliases")
  writer = Writer.new
  writer.class_name = layout_class_name
  writer.aliases = aliases unless aliases.nil?

  File.open(layout_class_path(path), 'w') do |f|
    writer.write f, layout
  end
end