Class: Tunnlr::Configurator
- Inherits:
-
Object
- Object
- Tunnlr::Configurator
- Defined in:
- lib/tunnlr/configurator.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#not_configured ⇒ Object
Returns the value of attribute not_configured.
-
#password ⇒ Object
Returns the value of attribute password.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
Instance Method Summary collapse
- #add_password ⇒ Object
- #configure(path) ⇒ Object
- #fetch(username, password) ⇒ Object
- #get_credentials ⇒ Object
-
#initialize ⇒ Configurator
constructor
A new instance of Configurator.
- #write_config(path) ⇒ Object
Constructor Details
#initialize ⇒ Configurator
Returns a new instance of Configurator.
6 7 8 9 |
# File 'lib/tunnlr/configurator.rb', line 6 def initialize @ui = HighLine.new @not_configured=true end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/tunnlr/configurator.rb', line 5 def email @email end |
#not_configured ⇒ Object
Returns the value of attribute not_configured.
5 6 7 |
# File 'lib/tunnlr/configurator.rb', line 5 def not_configured @not_configured end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/tunnlr/configurator.rb', line 5 def password @password end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
5 6 7 |
# File 'lib/tunnlr/configurator.rb', line 5 def subdomain @subdomain end |
Instance Method Details
#add_password ⇒ Object
21 22 23 |
# File 'lib/tunnlr/configurator.rb', line 21 def add_password @configuration.gsub!(/PASSWD/,password) end |
#configure(path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tunnlr/configurator.rb', line 39 def configure(path) while not_configured begin get_credentials fetch(subdomain,email,password) add_password write_config(path) puts "Created configuration in #{path}" self.not_configured=false rescue Net::HTTPNotAcceptable=>e puts "Login failed, please try again" end end end |
#fetch(username, password) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/tunnlr/configurator.rb', line 11 def fetch(username,password) url=URI.parse("http://#{subdomain}.tunnlr.com/configuration.yml") req = Net::HTTP::Get.new(url.path) req.basic_auth(username,password) res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) } @configuration = res.body end |
#get_credentials ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/tunnlr/configurator.rb', line 31 def get_credentials puts "Enter the email address and password you used to sign up for Tunnlr." self.subdomain = @ui.ask("Subdomain (i.e. elevatedrails for elevatedrails.tunnlr.com): ") self.email = @ui.ask("Email: ") self.password = @ui.ask("Password: ") { |q| q.echo = false } fetch(email,password) end |
#write_config(path) ⇒ Object
25 26 27 28 29 |
# File 'lib/tunnlr/configurator.rb', line 25 def write_config(path) open(path,"w+") do |f| f.puts(@configuration) end end |