def login
      @authenticating = true
      handler = proc do |response|
        if response.code == 200
          @session = response["session"]
          @login_info = response["loginInfo"]
          self.class.cookies(session["name"] => session["value"])
        else
          clear_session
          case response.code
          when 401 then
            raise Jiralicious::InvalidLogin, "Invalid login"
          when 403
            raise Jiralicious::CaptchaRequired, "Captacha is required. Try logging into Jira via the web interface"
          else
            # Give Net::HTTP reason
            raise Jiralicious::JiraError, response
          end
        end
      end

      request(
        :post, "/rest/auth/latest/session",
        body: {
          username: Jiralicious.username,
          password: Jiralicious.password
        }.to_json,
        handler: handler
      )
    end
def login
      @authenticating = true
      handler = proc do |response|
        if response.code == 200
          @session = response["session"]
          @login_info = response["loginInfo"]
          self.class.cookies(session["name"] => session["value"])
        else
          clear_session
          case response.code
          when 401 then
            raise Jiralicious::InvalidLogin, "Invalid login"
          when 403
            raise Jiralicious::CaptchaRequired, "Captacha is required. Try logging into Jira via the web interface"
          else
            # Give Net::HTTP reason
            raise Jiralicious::JiraError, response
          end
        end
      end

      request(
        :post, "/rest/auth/latest/session",
        body: {
          username: Jiralicious.username,
          password: Jiralicious.password
        }.to_json,
        handler: handler
      )
    end
Authenticates the login