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