001/*
002 * Copyright (c) 2012, the Last.fm Java Project and Committers
003 * All rights reserved.
004 *
005 * Redistribution and use of this software in source and binary forms, with or without modification, are
006 * permitted provided that the following conditions are met:
007 *
008 * - Redistributions of source code must retain the above
009 *   copyright notice, this list of conditions and the
010 *   following disclaimer.
011 *
012 * - Redistributions in binary form must reproduce the above
013 *   copyright notice, this list of conditions and the
014 *   following disclaimer in the documentation and/or other
015 *   materials provided with the distribution.
016 *
017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
018 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
019 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
020 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
021 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
023 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
024 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
025 */
026
027package de.umass.lastfm.scrobble;
028
029/**
030 * Contains information about the result of a scrobbling operation and an optional error message.
031 *
032 * @author Janni Kovacs
033 * @see de.umass.lastfm.scrobble.ScrobbleResult
034 * @see de.umass.lastfm.Track#scrobble(ScrobbleData, de.umass.lastfm.Session)
035 * @deprecated The 1.2.x scrobble protocol has now been deprecated in favour of the 2.0 protocol which is part of the Last.fm web services
036 *             API.
037 */
038@Deprecated
039public class ResponseStatus {
040
041        public static final int OK = 0;
042        public static final int BANNED = 1;
043        public static final int BADAUTH = 2;
044        public static final int BADTIME = 3;
045        public static final int BADSESSION = 4;
046        public static final int FAILED = 5;
047
048        private int status;
049        private String message;
050
051        public ResponseStatus(int status) {
052                this(status, null);
053        }
054
055        public ResponseStatus(int status, String message) {
056                this.status = status;
057                this.message = message;
058        }
059
060        /**
061         * Returns the optional error message, which is only available if <code>status</code> is <code>FAILED</code>, or
062         * <code>null</code>, if no message is available.
063         *
064         * @return the error message or <code>null</code>
065         */
066        public String getMessage() {
067                return message;
068        }
069
070        /**
071         * Returns the result status code of the operation, which is one of the integer constants defined in this class.
072         *
073         * @return the status code
074         */
075        public int getStatus() {
076                return status;
077        }
078
079        /**
080         * Returns <code>true</code> if the operation was successful. Same as <code>getStatus() == ResponseStatus.OK</code>.
081         *
082         * @return <code>true</code> if status is OK
083         */
084        public boolean ok() {
085                return status == OK;
086        }
087
088        static int codeForStatus(String status) {
089                if ("OK".equals(status))
090                        return OK;
091                if (status.startsWith("FAILED"))
092                        return FAILED;
093                if ("BADAUTH".equals(status))
094                        return BADAUTH;
095                if ("BADSESSION".equals(status))
096                        return BADSESSION;
097                if ("BANNED".equals(status))
098                        return BANNED;
099                if ("BADTIME".equals(status))
100                        return BADTIME;
101                return -1;
102        }
103}