login_reliance 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a59ea00c7b9c546ba2b23317ba8fe2ec8fcb548e
4
+ data.tar.gz: 9c1fb1c0fa8755d0a442a67b42930286deb1f518
5
+ SHA512:
6
+ metadata.gz: b086af53071bfa862a87ad0e29d04b493fd699ceb04512b969603de9597830959a7bd049efe25b0d3064f4c78e378aee71cb691dc34812189b2738562ec15fb0
7
+ data.tar.gz: 01b662d9db65912bc6864597220a8fcf82fd63d762b327aef309f06f0987a9556971740116b67f2c74630a0e6e8995f18067c3a177f232e319b16bd754e12f1c
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ tags
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in login_reliance.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # LoginReliance
2
+
3
+ This gem is used to login to reliance broadband connection.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'login_reliance'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install login_reliance
20
+
21
+ ## Usage
22
+
23
+ Run
24
+
25
+ $ login_reliance
26
+
27
+ It will prompt for username and password. If you wish to save the password, it will be written to a file in a the home directory. The name of the file is reliance.
28
+
29
+ Run the following to keep trying to login.
30
+
31
+ $ login_reliance -r
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rakeshbs/login_reliance.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "login_reliance"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module LoginReliance
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,108 @@
1
+ require 'mechanize'
2
+
3
+ module StatusCode
4
+ LOGIN_FAILED = 0
5
+ INVALID_LOGIN = 1
6
+ LOGIN_SUCCESSFUL = 2
7
+ ALREADY_LOGGED_IN = 3
8
+ end
9
+
10
+ class LoginReliance
11
+
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
17
+
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
24
+ end
25
+ rescue
26
+ end
27
+ nil
28
+ end
29
+
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
41
+
42
+ def save_login_to_file(username, password)
43
+ File.open(@save_file, 'w') do |f|
44
+ f.write "#{username},#{password}"
45
+ end
46
+ end
47
+
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
62
+ end
63
+ rescue Exception => ex
64
+ puts ex.message
65
+ return StatusCode::LOGIN_FAILED
66
+ end
67
+ return StatusCode::LOGIN_SUCCESSFUL
68
+ end
69
+
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)
78
+ end
79
+ 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
+
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"
97
+ 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
+ end
108
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'login_reliance/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "login_reliance"
8
+ spec.version = LoginReliance::VERSION
9
+ spec.authors = ["Rakesh BS"]
10
+ spec.email = ["rakeshbs@gmail.com"]
11
+
12
+ spec.summary = %q{This gem is used to login to reliance broadband internet.}
13
+ spec.homepage = "https://github.com/rakeshbs"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ #spec.metadata['allowed_push_host'] = 'http://mygemserver.com'
20
+ #else
21
+ #raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ #end
23
+
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) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.10"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_dependency "mechanize"
32
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: login_reliance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rakesh BS
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - rakeshbs@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/login_reliance.rb
70
+ - lib/login_reliance/version.rb
71
+ - login_reliance.gemspec
72
+ homepage: https://github.com/rakeshbs
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: This gem is used to login to reliance broadband internet.
96
+ test_files: []