All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.eliux.mega.cmd.MegaCmdSession Maven / Gradle / Ivy

Go to download

Java client library that works on top of MEGAcmd to provide access to the services of Mega.nz

There is a newer version: 1.6.2
Show newest version
package com.github.eliux.mega.cmd;

import com.github.eliux.mega.MegaUtils;
import com.github.eliux.mega.error.MegaIOException;
import com.github.eliux.mega.error.MegaLoginRequiredException;

import java.io.IOException;
import java.util.Optional;

public class MegaCmdSession extends AbstractMegaCmdCaller {

    @Override
    public String getCmd() {
        return "session";
    }

    static final Optional parseSessionID(String response) {
        return Optional.ofNullable(response)
                .map(s -> s.split(":"))
                .filter(x -> x.length == 2)
                .map(s -> s[1].trim());
    }

    @Override
    public String call() {
        try {
            final String response =
                    MegaUtils.execCmdWithOutput(executableCommand()).get(0);
            return parseSessionID(response)
                    .orElseThrow(() -> new MegaLoginRequiredException());
        } catch (IOException e) {
            throw new MegaIOException();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy