001/*
002 * Copyright (c) 2010-2025 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;
025
026public enum Version {
027
028  /**
029   * unversiond api
030   */
031  UNVERSIONED(null),
032
033  /**
034   * <tt>Graph API 12.0</tt>, available until February 8th, 2024
035   *
036   * @since September 14th, 2021
037   */
038  @Deprecated
039  VERSION_12_0("v12.0"),
040
041  /**
042   * <tt>Graph API 13.0</tt>, available until May 28th, 2024
043   *
044   * @since February 8th, 2022
045   */
046  @Deprecated
047  VERSION_13_0("v13.0"),
048
049  /**
050   * <tt>Graph API 14.0</tt>, available until September 17th, 2024
051   *
052   * @since May 25th, 2022
053   */
054  @Deprecated
055  VERSION_14_0("v14.0"),
056
057  /**
058   * <tt>Graph API 15.0</tt>, available until February 2nd, 2025
059   *
060   * @since September 17th, 2022
061   */
062  VERSION_15_0("v15.0"),
063
064  /**
065   * <tt>Graph API 16.0</tt>, available until May 23, 2025
066   *
067   * @since February 2nd, 2023
068   */
069  VERSION_16_0("v16.0"),
070
071  /**
072   * <tt>Graph API 17.0</tt>, available until September 12, 2025
073   *
074   * @since May 23, 2023
075   */
076  VERSION_17_0("v17.0"),
077
078  /**
079   * <tt>Graph API 18.0</tt>, available at least until January 23, 2026
080   *
081   * @since September 12, 2023
082   */
083  VERSION_18_0("v18.0"),
084
085  /**
086   * <tt>Graph API 19.0</tt>, available at least until May 21, 2026
087   *
088   * @since January 23, 2024
089   */
090  VERSION_19_0("v19.0"),
091
092  /**
093   * <tt>Graph API 20.0</tt>, available at least until September 24, 2026
094   *
095   * @since May 21, 2024
096   */
097  VERSION_20_0("v20.0"),
098
099  /**
100   * <tt>Graph API 21.0</tt>, available at least until January 21, 2027
101   *
102   * @since October 2, 2024
103   */
104  VERSION_21_0("v21.0"),
105
106  /**
107   * <tt>Graph API 22.0</tt>, available at least until January 2027
108   *
109   * @since January 21, 2025
110   */
111  VERSION_22_0("v22.0"),
112
113  /**
114   * convenience enum to provide simple access to the latest supported Graph API Version.
115   * <p>
116   * the current version is <tt>Graph API 22.0</tt>
117   * </p>
118   */
119  LATEST("v22.0"),
120
121  /**
122   * <tt>Threads API 1.0</tt>, according to the documentation, this is the first Threads API Version
123   */
124  THREADS_1_0("v1.0"),
125
126  /**
127   * convenience enum to provide simple access to the latest supported Threads API Version.
128   */
129  THREADS_LATEST("v1.0");
130
131  private final String urlElement;
132
133  Version(String urlElement) {
134    this.urlElement = urlElement;
135  }
136
137  public String getUrlElement() {
138    return this.urlElement;
139  }
140
141  public boolean isUrlElementRequired() {
142    return null != this.urlElement;
143  }
144
145  /**
146   * converts a String (for example the url parameter) into a Version object
147   * 
148   * @param urlElementStr
149   *          String that should
150   * @return the generated version
151   */
152  public static Version getVersionFromString(String urlElementStr) {
153    if (urlElementStr == null) {
154      return UNVERSIONED;
155    }
156
157    return Arrays.stream(Version.values()).filter(v -> urlElementStr.equals(v.getUrlElement())).findFirst()
158      .orElse(UNVERSIONED);
159  }
160}