login_reliance 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a59ea00c7b9c546ba2b23317ba8fe2ec8fcb548e
4
- data.tar.gz: 9c1fb1c0fa8755d0a442a67b42930286deb1f518
3
+ metadata.gz: abbc47b42092827910f4999eae5967182998f6d5
4
+ data.tar.gz: b7e75d9e2fb2452be0b5c9dce805dd472b01ebd2
5
5
  SHA512:
6
- metadata.gz: b086af53071bfa862a87ad0e29d04b493fd699ceb04512b969603de9597830959a7bd049efe25b0d3064f4c78e378aee71cb691dc34812189b2738562ec15fb0
7
- data.tar.gz: 01b662d9db65912bc6864597220a8fcf82fd63d762b327aef309f06f0987a9556971740116b67f2c74630a0e6e8995f18067c3a177f232e319b16bd754e12f1c
6
+ metadata.gz: 2e2eb3cc9d33e617abb52de788276145ca6ff403a9a009594fa0f7c1db91f37b54679e9a6ec793ed5b03dfa026874c3ad6620fc13bf866b11d08dc009ea62e12
7
+ data.tar.gz: 54090c6e3ada7609e2a082040b980ddd45306c31e9d769ba37b42682a1ca2722fdf628593c29d57e273d064bd2fb5b14e404f26d2d80ccaef852d5f66af87aff
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'login_reliance'
4
+
5
+ repeat = false
6
+ repeat = (ARGV[0] == "-r") if ARGV.size > 0
7
+ reliance = LoginReliance::Reliance.new
8
+
9
+ loop do
10
+ statusCode = reliance.login
11
+ if statusCode == StatusCode::LOGIN_FAILED
12
+ puts "Login failed."
13
+ unless repeat
14
+ puts "Try login_reliance -r to keep trying again."
15
+ break
16
+ else
17
+ puts "Trying again"
18
+ end
19
+ elsif statusCode == StatusCode::ALREADY_LOGGED_IN
20
+ puts "Already logged in"
21
+ break
22
+ elsif statusCode == StatusCode::INVALID_LOGIN
23
+ puts "Invalid login information"
24
+ reliance.remove_save_file
25
+ else
26
+ puts "Login successful"
27
+ break
28
+ end
29
+ end
@@ -7,102 +7,78 @@ module StatusCode
7
7
  ALREADY_LOGGED_IN = 3
8
8
  end
9
9
 
10
- class LoginReliance
10
+ module LoginReliance
11
+ class Reliance
11
12
 
12
- def initialize
13
- @save_file = File.expand_path('~/.reliance')
14
- @url = 'http://220.224.142.229/reliance/startportal_isg.do?CPURL=null'
15
- @url = 'http://reliancebroadband.co.in/reliance/startportal_isg.do'
16
- end
13
+ def initialize
14
+ @save_file = File.expand_path('~/.reliance')
15
+ @url = 'http://220.224.142.229/reliance/startportal_isg.do?CPURL=null'
16
+ #@url = 'http://reliancebroadband.co.in/reliance/startportal_isg.do'
17
+ end
17
18
 
18
- def read_login_from_file
19
- begin
20
- File.open(@save_file) do |f|
21
- contents_array = f.gets.split(',')
22
- throw Exception.new if contents_array.size != 2
23
- return contents_array
19
+ def read_login_from_file
20
+ begin
21
+ File.open(@save_file) do |f|
22
+ contents_array = f.gets.split(',')
23
+ throw Exception.new if contents_array.size != 2
24
+ return contents_array
25
+ end
26
+ rescue
24
27
  end
25
- rescue
28
+ nil
26
29
  end
27
- nil
28
- end
29
30
 
30
- def remove_save_file
31
- File.delete(@save_file)
32
- end
33
-
34
- def get_login_from_user
35
- puts 'Enter username'
36
- username = STDIN.gets.chomp
37
- puts 'Enter password'
38
- password = STDIN.gets.chomp
39
- [username, password]
40
- end
31
+ def remove_save_file
32
+ File.delete(@save_file)
33
+ end
41
34
 
42
- def save_login_to_file(username, password)
43
- File.open(@save_file, 'w') do |f|
44
- f.write "#{username},#{password}"
35
+ def get_login_from_user
36
+ puts 'Enter username'
37
+ username = STDIN.gets.chomp
38
+ puts 'Enter password'
39
+ password = STDIN.gets.chomp
40
+ [username, password]
45
41
  end
46
- end
47
42
 
48
- def login_reliance(username, password)
49
- begin
50
- agent = Mechanize.new
51
- agent.get(@url) do |signin_page|
52
- if signin_page.body.include?("logout")
53
- return StatusCode::ALREADY_LOGGED_IN
54
- end
55
- success_page = signin_page.form_with(:name => 'form1') do |form|
56
- form.userId = username
57
- form.password = password
58
- end.submit
59
- unless success_page.body.include?("logout")
60
- return StatusCode::INVALID_LOGIN
61
- end
43
+ def save_login_to_file(username, password)
44
+ File.open(@save_file, 'w') do |f|
45
+ f.write "#{username},#{password}"
62
46
  end
63
- rescue Exception => ex
64
- puts ex.message
65
- return StatusCode::LOGIN_FAILED
66
47
  end
67
- return StatusCode::LOGIN_SUCCESSFUL
68
- end
69
48
 
70
- def login
71
- username, password = read_login_from_file
72
- if username.nil?
73
- username, password = get_login_from_user
74
- puts 'Do you want to save the login to a file in the home folder? (y/n)'
75
- answer = STDIN.gets[0].downcase
76
- if answer == 'y'
77
- save_login_to_file(username, password)
49
+ def login_reliance(username, password)
50
+ begin
51
+ agent = Mechanize.new
52
+ agent.get(@url) do |signin_page|
53
+ if signin_page.body.include?("logout")
54
+ return StatusCode::ALREADY_LOGGED_IN
55
+ end
56
+ success_page = signin_page.form_with(:name => 'form1') do |form|
57
+ form.userId = username
58
+ form.password = password
59
+ end.submit
60
+ unless success_page.body.include?("logout")
61
+ return StatusCode::INVALID_LOGIN
62
+ end
63
+ end
64
+ rescue Exception => ex
65
+ puts ex.message
66
+ return StatusCode::LOGIN_FAILED
78
67
  end
68
+ return StatusCode::LOGIN_SUCCESSFUL
79
69
  end
80
- login_reliance(username, password)
81
- end
82
- end
83
-
84
- repeat = false
85
- repeat = (ARGV[0] == "-r") if ARGV.size > 0
86
- reliance = LoginReliance.new
87
70
 
88
- loop do
89
- statusCode = reliance.login
90
- if statusCode == StatusCode::LOGIN_FAILED
91
- puts "Login failed."
92
- unless repeat
93
- puts "Try login_reliance -r to keep trying again."
94
- break
95
- else
96
- puts "Trying again"
71
+ def login
72
+ username, password = read_login_from_file
73
+ if username.nil?
74
+ username, password = get_login_from_user
75
+ puts 'Do you want to save the login to a file in the home folder? (y/n)'
76
+ answer = STDIN.gets[0].downcase
77
+ if answer == 'y'
78
+ save_login_to_file(username, password)
79
+ end
80
+ end
81
+ login_reliance(username, password)
97
82
  end
98
- elsif statusCode == StatusCode::ALREADY_LOGGED_IN
99
- puts "Already logged in"
100
- break
101
- elsif statusCode == StatusCode::INVALID_LOGIN
102
- puts "Invalid login information"
103
- reliance.remove_save_file
104
- else
105
- puts "Login successful"
106
- break
107
83
  end
108
84
  end
@@ -1,3 +1,3 @@
1
1
  module LoginReliance
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  #end
23
23
 
24
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.bindir = "bin"
26
+ spec.executables = "login_reliance"
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 1.10"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: login_reliance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rakesh BS
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-03 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,8 @@ dependencies:
55
55
  description:
56
56
  email:
57
57
  - rakeshbs@gmail.com
58
- executables: []
58
+ executables:
59
+ - login_reliance
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -65,6 +66,7 @@ files:
65
66
  - README.md
66
67
  - Rakefile
67
68
  - bin/console
69
+ - bin/login_reliance
68
70
  - bin/setup
69
71
  - lib/login_reliance.rb
70
72
  - lib/login_reliance/version.rb