Module: OMCL::Auth
- Defined in:
- lib/omcl/auth.rb
Class Method Summary collapse
Class Method Details
.authenticate(url, user, pass) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/omcl/auth.rb', line 19 def self.authenticate(url, user, pass) # Create JSON request json = self.make_json_request user, pass RG::Log.write "Authenticating..." res = HTTP.headers(:accept => "application/json") .post(url, {:body=>json}) if res.code == 403 RG::Log.crash "Invalid credentials error! If they are valid, try again after a while" elsif res.code != 200 RG::Log.crash "Received HTTP code #{res.code} while authenticating!" else return res end end |
.make_json_request(user, pass) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/omcl/auth.rb', line 3 def self.make_json_request(user, pass) RG::Log.write "Forming JSON request..." # Create hash dat = { :agent => { :name => "Minecraft", :version => 1 }, :username => user, :password => pass } # Generate JSON request and return it JSON.generate dat end |