Sha256: 7157329bea873bc593761d1ac6757af98427551400a9b451fa03f00a09b41bed

Contents?: true

Size: 907 Bytes

Versions: 1

Compression:

Stored size: 907 Bytes

Contents

module OMCL
  module Auth
    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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omcl-0.0.0.1 lib/omcl/auth.rb