Class: AmsLayout::Client
- Inherits:
-
Object
- Object
- AmsLayout::Client
- Includes:
- Pages
- Defined in:
- lib/ams_layout/client.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#base_url ⇒ Object
Return the base url for the current environment.
-
#credentials ⇒ Object
Return the credentials for the current environment.
-
#environment ⇒ Object
Return the current environment.
-
#environment=(env) ⇒ Object
Set the current environment.
-
#get_field_data ⇒ Object
Retrieve field data from Loan Entry (Prequal) screen.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#login(username, password, options = {}) ⇒ Object
Login to the Admin Module.
- #logout ⇒ Object
-
#quit ⇒ Object
Close the browser.
- #write_alias_example(layout_file_path) ⇒ Object
- #write_delegate_class(path, layout_file_path) ⇒ Object
- #write_layout(path, write_alias_example = false) ⇒ Object
- #write_layout_class(path, layout_file_path) ⇒ Object
Methods included from Pages
Constructor Details
Instance Attribute Details
#delegate_class_name ⇒ Object
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_name ⇒ Object
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_url ⇒ Object
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 |
#credentials ⇒ Object
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 |
#environment ⇒ Object
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_data ⇒ Object
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 login(username, password, = {}) force = .fetch(:force) { false } logout login_page(force).login_as username, password end |
#logout ⇒ Object
80 81 82 83 |
# File 'lib/ams_layout/client.rb', line 80 def logout login_page.logout @login_page = nil end |
#quit ⇒ Object
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 |section_label, 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 |