001/*
002 * Copyright (c) 2010-2024 Mark Allen, Norbert Bartels.
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.restfb;
023
024import java.util.Arrays;
025import java.util.stream.Stream;
026
027public enum Version {
028
029  /**
030   * unversiond api
031   */
032  UNVERSIONED(null),
033
034  /**
035   * <tt>Graph API 9.0</tt>, available until February 23, 2023
036   *
037   * @since November 10th, 2020
038   */
039  VERSION_9_0("v9.0"),
040
041  /**
042   * <tt>Graph API 10.0</tt>, available until June 8th, 2023
043   *
044   * @since February 23th, 2021
045   */
046  VERSION_10_0("v10.0"),
047
048  /**
049   * <tt>Graph API 11.0</tt>, available until September 14th, 2023
050   *
051   * @since June 8th, 2021
052   */
053  VERSION_11_0("v11.0"),
054
055  /**
056   * <tt>Graph API 12.0</tt>, available until February 8th, 2024
057   *
058   * @since September 14th, 2021
059   */
060  VERSION_12_0("v12.0"),
061
062  /**
063   * <tt>Graph API 13.0</tt>, available until May 28th, 2024
064   *
065   * @since February 8th, 2022
066   */
067  VERSION_13_0("v13.0"),
068
069  /**
070   * <tt>Graph API 14.0</tt>, available until September 17th, 2024
071   *
072   * @since May 25th, 2022
073   */
074  VERSION_14_0("v14.0"),
075
076  /**
077   * <tt>Graph API 15.0</tt>, available until February 2nd, 2024
078   *
079   * @since September 17th, 2022
080   */
081  VERSION_15_0("v15.0"),
082
083  /**
084   * <tt>Graph API 16.0</tt>, available until May 23, 2025
085   *
086   * @since February 2nd, 2023
087   */
088  VERSION_16_0("v16.0"),
089
090  /**
091   * <tt>Graph API 17.0</tt>, available until September 12, 2025
092   *
093   * @since May 23, 2023
094   */
095  VERSION_17_0("v17.0"),
096
097  /**
098   * <tt>Graph API 18.0</tt>, available at least until January 23, 2026
099   *
100   * @since September 12, 2023
101   */
102  VERSION_18_0("v18.0"),
103
104  /**
105   * <tt>Graph API 19.0</tt>, available at least until January 2026
106   *
107   * @since January 23, 2024
108   */
109  VERSION_19_0("v19.0"),
110
111  /**
112   * convenience enum to provide simple access to the latest supported Graph API Version.
113   * <p>
114   * the current version is <tt>Graph API 19.0</tt>
115   * </p>
116   */
117  LATEST("v19.0");
118
119  private final String urlElement;
120
121  Version(String urlElement) {
122    this.urlElement = urlElement;
123  }
124
125  public String getUrlElement() {
126    return this.urlElement;
127  }
128
129  public boolean isUrlElementRequired() {
130    return null != this.urlElement;
131  }
132
133  /**
134   * converts a String (for example the url parameter) into a Version object
135   * 
136   * @param urlElementStr
137   *          String that should
138   * @return the generated version
139   */
140  public static Version getVersionFromString(String urlElementStr) {
141    if (urlElementStr == null) {
142      return UNVERSIONED;
143    }
144
145    return Arrays.stream(Version.values())
146            .filter(v -> urlElementStr.equals(v.getUrlElement()))
147            .findFirst()
148            .orElse(UNVERSIONED);
149  }
150}