diff --git a/api-lib/build.gradle b/api-lib/build.gradle index fb79e3b..fcbd881 100644 --- a/api-lib/build.gradle +++ b/api-lib/build.gradle @@ -54,7 +54,7 @@ dependencies { compile "io.swagger:swagger-annotations:$rootProject.swaggerVersion" // Apache Oltu - https://oltu.apache.org/ - compile ('org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.2') { + compile ('org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1') { /* * NOTE: Swagger generated client library depends on "org.apache.oltu.oauth2.client", which * includes classes from "org.apache.oltu.oauth2.common". So, we explicitly need to exclude diff --git a/api-lib/docs/Article.md b/api-lib/docs/Article.md new file mode 100644 index 0000000..774cc95 --- /dev/null +++ b/api-lib/docs/Article.md @@ -0,0 +1,29 @@ + +# Article + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**section** | **String** | | [optional] +**subsection** | **String** | | [optional] +**title** | **String** | | [optional] +**_abstract** | **String** | | [optional] +**url** | **String** | | [optional] +**thumbnailStandard** | **String** | | [optional] +**shortUrl** | **String** | | [optional] +**byline** | **String** | | [optional] +**itemType** | **String** | | [optional] +**updatedDate** | **String** | | [optional] +**createdDate** | **String** | | [optional] +**publishedDate** | **String** | | [optional] +**materialTypeFacet** | **String** | | [optional] +**kicker** | **String** | | [optional] +**desFacet** | **List<String>** | | [optional] +**orgFacet** | **String** | | [optional] +**perFacet** | **List<String>** | | [optional] +**geoFacet** | **List<String>** | | [optional] +**multimedia** | [**List<ArticleMultimedia>**](ArticleMultimedia.md) | | [optional] +**relatedUrls** | [**List<ArticleRelatedUrls>**](ArticleRelatedUrls.md) | | [optional] + + + diff --git a/api-lib/docs/ArticleMultimedia.md b/api-lib/docs/ArticleMultimedia.md new file mode 100644 index 0000000..3b13119 --- /dev/null +++ b/api-lib/docs/ArticleMultimedia.md @@ -0,0 +1,17 @@ + +# ArticleMultimedia + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**url** | **String** | | [optional] +**format** | **String** | | [optional] +**height** | **Integer** | | [optional] +**width** | **Integer** | | [optional] +**type** | **String** | | [optional] +**subtype** | **String** | | [optional] +**caption** | **String** | | [optional] +**copyright** | **String** | | [optional] + + + diff --git a/api-lib/docs/ArticleRelatedUrls.md b/api-lib/docs/ArticleRelatedUrls.md new file mode 100644 index 0000000..77cb22a --- /dev/null +++ b/api-lib/docs/ArticleRelatedUrls.md @@ -0,0 +1,11 @@ + +# ArticleRelatedUrls + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**suggestedLinkText** | **String** | | [optional] +**url** | **String** | | [optional] + + + diff --git a/api-lib/docs/InlineResponse200.md b/api-lib/docs/InlineResponse200.md new file mode 100644 index 0000000..1d27793 --- /dev/null +++ b/api-lib/docs/InlineResponse200.md @@ -0,0 +1,10 @@ + +# InlineResponse200 + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**results** | [**List<Article>**](Article.md) | | [optional] + + + diff --git a/api-lib/docs/StoriesApi.md b/api-lib/docs/StoriesApi.md new file mode 100644 index 0000000..87d0541 --- /dev/null +++ b/api-lib/docs/StoriesApi.md @@ -0,0 +1,68 @@ +# StoriesApi + +All URIs are relative to *http://api.nytimes.com/svc/topstories/v2/* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**sectionFormatGet**](StoriesApi.md#sectionFormatGet) | **GET** {section}.{format} | Top Stories + + + +# **sectionFormatGet** +> InlineResponse200 sectionFormatGet(section, format, callback) + +Top Stories + +The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + +### Example +```java +// Import classes: +//import io.swagger.client.ApiClient; +//import io.swagger.client.ApiException; +//import io.swagger.client.Configuration; +//import io.swagger.client.auth.*; +//import io.swagger.client.api.StoriesApi; + +ApiClient defaultClient = Configuration.getDefaultApiClient(); + +// Configure API key authorization: apikey +ApiKeyAuth apikey = (ApiKeyAuth) defaultClient.getAuthentication("apikey"); +apikey.setApiKey("YOUR API KEY"); +// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) +//apikey.setApiKeyPrefix("Token"); + +StoriesApi apiInstance = new StoriesApi(); +String section = "section_example"; // String | The section the story appears in. +String format = "format_example"; // String | if this is JSONP or JSON +String callback = "callback_example"; // String | The name of the function the API call results will be passed to. Required when using JSONP. This parameter has only one valid value per section. The format is {section_name}TopStoriesCallback. +try { + InlineResponse200 result = apiInstance.sectionFormatGet(section, format, callback); + System.out.println(result); +} catch (ApiException e) { + System.err.println("Exception when calling StoriesApi#sectionFormatGet"); + e.printStackTrace(); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **section** | **String**| The section the story appears in. | [enum: home, opinion, world, national, politics, upshot, nyregion, business, technology, science, health, sports, arts, books, movies, theater, sundayreview, fashion, tmagazine, food, travel, magazine, realestate, automobiles, obituaries, insider] + **format** | **String**| if this is JSONP or JSON | [enum: json, jsonp] + **callback** | **String**| The name of the function the API call results will be passed to. Required when using JSONP. This parameter has only one valid value per section. The format is {section_name}TopStoriesCallback. | [optional] + +### Return type + +[**InlineResponse200**](InlineResponse200.md) + +### Authorization + +[apikey](../README.md#apikey) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + diff --git a/api-lib/src/main/AndroidManifest.xml b/api-lib/src/main/AndroidManifest.xml index 240b928..465dcb5 100644 --- a/api-lib/src/main/AndroidManifest.xml +++ b/api-lib/src/main/AndroidManifest.xml @@ -1,10 +1,3 @@ - - - - - - + + diff --git a/api-lib/src/main/java/com/example/ApiCore.java b/api-lib/src/main/java/com/example/ApiCore.java deleted file mode 100644 index 0a25784..0000000 --- a/api-lib/src/main/java/com/example/ApiCore.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.example; - -public class ApiCore { - public static final String TEST = "TEST"; -} diff --git a/api-lib/src/main/java/io/swagger/client/ApiClient.java b/api-lib/src/main/java/io/swagger/client/ApiClient.java new file mode 100644 index 0000000..5f28a20 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/ApiClient.java @@ -0,0 +1,412 @@ +package io.swagger.client; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; +import org.joda.time.DateTime; +import org.joda.time.LocalDate; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; +import retrofit2.Converter; +import retrofit2.Retrofit; + +import retrofit2.converter.gson.GsonConverterFactory; +import retrofit2.converter.scalars.ScalarsConverterFactory; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonParseException; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.RequestBody; +import okhttp3.ResponseBody; + + +import io.swagger.client.auth.HttpBasicAuth; +import io.swagger.client.auth.ApiKeyAuth; +import io.swagger.client.auth.OAuth; +import io.swagger.client.auth.OAuth.AccessTokenListener; +import io.swagger.client.auth.OAuthFlow; + + +public class ApiClient { + + private Map apiAuthorizations; + private OkHttpClient.Builder okBuilder; + private Retrofit.Builder adapterBuilder; + + public ApiClient() { + apiAuthorizations = new LinkedHashMap(); + createDefaultAdapter(); + } + + public ApiClient(String[] authNames) { + this(); + for(String authName : authNames) { + Interceptor auth; + if (authName == "apikey") { + auth = new ApiKeyAuth("query", "api-key"); + } else { + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); + } + addAuthorization(authName, auth); + } + } + + /** + * Basic constructor for single auth name + * @param authName Authentication name + */ + public ApiClient(String authName) { + this(new String[]{authName}); + } + + /** + * Helper constructor for single api key + * @param authName Authentication name + * @param apiKey API key + */ + public ApiClient(String authName, String apiKey) { + this(authName); + this.setApiKey(apiKey); + } + + /** + * Helper constructor for single basic auth or password oauth2 + * @param authName Authentication name + * @param username Username + * @param password Password + */ + public ApiClient(String authName, String username, String password) { + this(authName); + this.setCredentials(username, password); + } + + /** + * Helper constructor for single password oauth2 + * @param authName Authentication name + * @param clientId Client ID + * @param secret Client Secret + * @param username Username + * @param password Password + */ + public ApiClient(String authName, String clientId, String secret, String username, String password) { + this(authName); + this.getTokenEndPoint() + .setClientId(clientId) + .setClientSecret(secret) + .setUsername(username) + .setPassword(password); + } + + public void createDefaultAdapter() { + Gson gson = new GsonBuilder() + .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ") + .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter()) + .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()) + .create(); + + okBuilder = new OkHttpClient.Builder(); + + String baseUrl = "http://api.nytimes.com/svc/topstories/v2/"; + if(!baseUrl.endsWith("/")) + baseUrl = baseUrl + "/"; + + adapterBuilder = new Retrofit + .Builder() + .baseUrl(baseUrl) + + .addConverterFactory(ScalarsConverterFactory.create()) + .addConverterFactory(GsonCustomConverterFactory.create(gson)); + } + + public S createService(Class serviceClass) { + return adapterBuilder + .client(okBuilder.build()) + .build() + .create(serviceClass); + + } + + /** + * Helper method to configure the first api key found + * @param apiKey API key + */ + private void setApiKey(String apiKey) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof ApiKeyAuth) { + ApiKeyAuth keyAuth = (ApiKeyAuth) apiAuthorization; + keyAuth.setApiKey(apiKey); + return; + } + } + } + + /** + * Helper method to configure the username/password for basic auth or password oauth + * @param username Username + * @param password Password + */ + private void setCredentials(String username, String password) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof HttpBasicAuth) { + HttpBasicAuth basicAuth = (HttpBasicAuth) apiAuthorization; + basicAuth.setCredentials(username, password); + return; + } + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.getTokenRequestBuilder().setUsername(username).setPassword(password); + return; + } + } + } + + /** + * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one) + * @return Token request builder + */ + public TokenRequestBuilder getTokenEndPoint() { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + return oauth.getTokenRequestBuilder(); + } + } + return null; + } + + /** + * Helper method to configure authorization endpoint of the first oauth found in the apiAuthorizations (there should be only one) + * @return Authentication request builder + */ + public AuthenticationRequestBuilder getAuthorizationEndPoint() { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + return oauth.getAuthenticationRequestBuilder(); + } + } + return null; + } + + /** + * Helper method to pre-set the oauth access token of the first oauth found in the apiAuthorizations (there should be only one) + * @param accessToken Access token + */ + public void setAccessToken(String accessToken) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.setAccessToken(accessToken); + return; + } + } + } + + /** + * Helper method to configure the oauth accessCode/implicit flow parameters + * @param clientId Client ID + * @param clientSecret Client secret + * @param redirectURI Redirect URI + */ + public void configureAuthorizationFlow(String clientId, String clientSecret, String redirectURI) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.getTokenRequestBuilder() + .setClientId(clientId) + .setClientSecret(clientSecret) + .setRedirectURI(redirectURI); + oauth.getAuthenticationRequestBuilder() + .setClientId(clientId) + .setRedirectURI(redirectURI); + return; + } + } + } + + /** + * Configures a listener which is notified when a new access token is received. + * @param accessTokenListener Access token listener + */ + public void registerAccessTokenListener(AccessTokenListener accessTokenListener) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + if (apiAuthorization instanceof OAuth) { + OAuth oauth = (OAuth) apiAuthorization; + oauth.registerAccessTokenListener(accessTokenListener); + return; + } + } + } + + /** + * Adds an authorization to be used by the client + * @param authName Authentication name + * @param authorization Authorization interceptor + */ + public void addAuthorization(String authName, Interceptor authorization) { + if (apiAuthorizations.containsKey(authName)) { + throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations"); + } + apiAuthorizations.put(authName, authorization); + okBuilder.addInterceptor(authorization); + } + + public Map getApiAuthorizations() { + return apiAuthorizations; + } + + public void setApiAuthorizations(Map apiAuthorizations) { + this.apiAuthorizations = apiAuthorizations; + } + + public Retrofit.Builder getAdapterBuilder() { + return adapterBuilder; + } + + public void setAdapterBuilder(Retrofit.Builder adapterBuilder) { + this.adapterBuilder = adapterBuilder; + } + + public OkHttpClient.Builder getOkBuilder() { + return okBuilder; + } + + public void addAuthsToOkBuilder(OkHttpClient.Builder okBuilder) { + for(Interceptor apiAuthorization : apiAuthorizations.values()) { + okBuilder.addInterceptor(apiAuthorization); + } + } + + /** + * Clones the okBuilder given in parameter, adds the auth interceptors and uses it to configure the Retrofit + * @param okClient An instance of OK HTTP client + */ + public void configureFromOkclient(OkHttpClient okClient) { + this.okBuilder = okClient.newBuilder(); + addAuthsToOkBuilder(this.okBuilder); + + } +} + +/** + * This wrapper is to take care of this case: + * when the deserialization fails due to JsonParseException and the + * expected type is String, then just return the body string. + */ +class GsonResponseBodyConverterToString implements Converter { + private final Gson gson; + private final Type type; + + GsonResponseBodyConverterToString(Gson gson, Type type) { + this.gson = gson; + this.type = type; + } + + @Override public T convert(ResponseBody value) throws IOException { + String returned = value.string(); + try { + return gson.fromJson(returned, type); + } + catch (JsonParseException e) { + return (T) returned; + } + } +} + +class GsonCustomConverterFactory extends Converter.Factory +{ + public static GsonCustomConverterFactory create(Gson gson) { + return new GsonCustomConverterFactory(gson); + } + + private final Gson gson; + private final GsonConverterFactory gsonConverterFactory; + + private GsonCustomConverterFactory(Gson gson) { + if (gson == null) throw new NullPointerException("gson == null"); + this.gson = gson; + this.gsonConverterFactory = GsonConverterFactory.create(gson); + } + + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + if(type.equals(String.class)) + return new GsonResponseBodyConverterToString(gson, type); + else + return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit); + } + + @Override + public Converter requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit); + } +} + +/** + * Gson TypeAdapter for Joda DateTime type + */ +class DateTimeTypeAdapter extends TypeAdapter { + + private final DateTimeFormatter formatter = ISODateTimeFormat.dateTime(); + + @Override + public void write(JsonWriter out, DateTime date) throws IOException { + if (date == null) { + out.nullValue(); + } else { + out.value(formatter.print(date)); + } + } + + @Override + public DateTime read(JsonReader in) throws IOException { + switch (in.peek()) { + case NULL: + in.nextNull(); + return null; + default: + String date = in.nextString(); + return formatter.parseDateTime(date); + } + } +} + +/** + * Gson TypeAdapter for Joda LocalDate type + */ +class LocalDateTypeAdapter extends TypeAdapter { + + private final DateTimeFormatter formatter = ISODateTimeFormat.date(); + + @Override + public void write(JsonWriter out, LocalDate date) throws IOException { + if (date == null) { + out.nullValue(); + } else { + out.value(formatter.print(date)); + } + } + + @Override + public LocalDate read(JsonReader in) throws IOException { + switch (in.peek()) { + case NULL: + in.nextNull(); + return null; + default: + String date = in.nextString(); + return formatter.parseLocalDate(date); + } + } +} diff --git a/api-lib/src/main/java/io/swagger/client/CollectionFormats.java b/api-lib/src/main/java/io/swagger/client/CollectionFormats.java new file mode 100644 index 0000000..e96d156 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/CollectionFormats.java @@ -0,0 +1,95 @@ +package io.swagger.client; + +import java.util.Arrays; +import java.util.List; + +public class CollectionFormats { + + public static class CSVParams { + + protected List params; + + public CSVParams() { + } + + public CSVParams(List params) { + this.params = params; + } + + public CSVParams(String... params) { + this.params = Arrays.asList(params); + } + + public List getParams() { + return params; + } + + public void setParams(List params) { + this.params = params; + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), ","); + } + + } + + public static class SSVParams extends CSVParams { + + public SSVParams() { + } + + public SSVParams(List params) { + super(params); + } + + public SSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), " "); + } + } + + public static class TSVParams extends CSVParams { + + public TSVParams() { + } + + public TSVParams(List params) { + super(params); + } + + public TSVParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join( params.toArray(new String[0]), "\t"); + } + } + + public static class PIPESParams extends CSVParams { + + public PIPESParams() { + } + + public PIPESParams(List params) { + super(params); + } + + public PIPESParams(String... params) { + super(params); + } + + @Override + public String toString() { + return StringUtil.join(params.toArray(new String[0]), "|"); + } + } + +} diff --git a/api-lib/src/main/java/io/swagger/client/StringUtil.java b/api-lib/src/main/java/io/swagger/client/StringUtil.java new file mode 100644 index 0000000..2e97f6c --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/StringUtil.java @@ -0,0 +1,67 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client; + +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-09-19T22:13:55.972-04:00") +public class StringUtil { + /** + * Check if the given array contains the given value (with case-insensitive comparison). + * + * @param array The array + * @param value The value to search + * @return true if the array contains the value + */ + public static boolean containsIgnoreCase(String[] array, String value) { + for (String str : array) { + if (value == null && str == null) return true; + if (value != null && value.equalsIgnoreCase(str)) return true; + } + return false; + } + + /** + * Join an array of strings with the given separator. + *

+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *

+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) return ""; + + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } +} diff --git a/api-lib/src/main/java/io/swagger/client/api/StoriesApi.java b/api-lib/src/main/java/io/swagger/client/api/StoriesApi.java new file mode 100644 index 0000000..18180ba --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/api/StoriesApi.java @@ -0,0 +1,33 @@ +package io.swagger.client.api; + +import io.swagger.client.CollectionFormats.*; + + +import retrofit2.Call; +import retrofit2.http.*; + +import okhttp3.RequestBody; + +import io.swagger.client.model.InlineResponse200; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public interface StoriesApi { + /** + * Top Stories + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * @param section The section the story appears in. (required) + * @param format if this is JSONP or JSON (required) + * @param callback The name of the function the API call results will be passed to. Required when using JSONP. This parameter has only one valid value per section. The format is {section_name}TopStoriesCallback. (optional) + * @return Call<InlineResponse200> + */ + + @GET("{section}.{format}") + Call sectionFormatGet( + @Path("section") String section, @Path("format") String format, @Query("callback") String callback + ); + +} diff --git a/api-lib/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/api-lib/src/main/java/io/swagger/client/auth/ApiKeyAuth.java new file mode 100644 index 0000000..05bf956 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -0,0 +1,68 @@ +package io.swagger.client.auth; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; + +public class ApiKeyAuth implements Interceptor { + private final String location; + private final String paramName; + + private String apiKey; + + public ApiKeyAuth(String location, String paramName) { + this.location = location; + this.paramName = paramName; + } + + public String getLocation() { + return location; + } + + public String getParamName() { + return paramName; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + @Override + public Response intercept(Chain chain) throws IOException { + String paramValue; + Request request = chain.request(); + + if ("query".equals(location)) { + String newQuery = request.url().uri().getQuery(); + paramValue = paramName + "=" + apiKey; + if (newQuery == null) { + newQuery = paramValue; + } else { + newQuery += "&" + paramValue; + } + + URI newUri; + try { + newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(), + request.url().uri().getPath(), newQuery, request.url().uri().getFragment()); + } catch (URISyntaxException e) { + throw new IOException(e); + } + + request = request.newBuilder().url(newUri.toURL()).build(); + } else if ("header".equals(location)) { + request = request.newBuilder() + .addHeader(paramName, apiKey) + .build(); + } + return chain.proceed(request); + } +} diff --git a/api-lib/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/api-lib/src/main/java/io/swagger/client/auth/HttpBasicAuth.java new file mode 100644 index 0000000..c7b67e2 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -0,0 +1,50 @@ +package io.swagger.client.auth; + +import java.io.IOException; + +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.Credentials; + +public class HttpBasicAuth implements Interceptor { + + private String username; + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setCredentials(String username, String password) { + this.username = username; + this.password = password; + } + + @Override + public Response intercept(Chain chain) throws IOException { + Request request = chain.request(); + + // If the request already have an authorization (eg. Basic auth), do nothing + if (request.header("Authorization") == null) { + String credentials = Credentials.basic(username, password); + request = request.newBuilder() + .addHeader("Authorization", credentials) + .build(); + } + return chain.proceed(request); + } +} diff --git a/api-lib/src/main/java/io/swagger/client/auth/OAuth.java b/api-lib/src/main/java/io/swagger/client/auth/OAuth.java new file mode 100644 index 0000000..97145ce --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/auth/OAuth.java @@ -0,0 +1,176 @@ +package io.swagger.client.auth; + +import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; +import static java.net.HttpURLConnection.HTTP_FORBIDDEN; + +import java.io.IOException; +import java.util.Map; + +import org.apache.oltu.oauth2.client.OAuthClient; +import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder; +import org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; +import org.apache.oltu.oauth2.common.message.types.GrantType; +import org.apache.oltu.oauth2.common.token.BasicOAuthToken; + +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Request.Builder; +import okhttp3.Response; + +public class OAuth implements Interceptor { + + public interface AccessTokenListener { + public void notify(BasicOAuthToken token); + } + + private volatile String accessToken; + private OAuthClient oauthClient; + + private TokenRequestBuilder tokenRequestBuilder; + private AuthenticationRequestBuilder authenticationRequestBuilder; + + private AccessTokenListener accessTokenListener; + + public OAuth( OkHttpClient client, TokenRequestBuilder requestBuilder ) { + this.oauthClient = new OAuthClient(new OAuthOkHttpClient(client)); + this.tokenRequestBuilder = requestBuilder; + } + + public OAuth(TokenRequestBuilder requestBuilder ) { + this(new OkHttpClient(), requestBuilder); + } + + public OAuth(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) { + this(OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes)); + setFlow(flow); + authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl); + } + + public void setFlow(OAuthFlow flow) { + switch(flow) { + case accessCode: + case implicit: + tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); + break; + case password: + tokenRequestBuilder.setGrantType(GrantType.PASSWORD); + break; + case application: + tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); + break; + default: + break; + } + } + + @Override + public Response intercept(Chain chain) + throws IOException { + + Request request = chain.request(); + + // If the request already have an authorization (eg. Basic auth), do nothing + if (request.header("Authorization") != null) { + return chain.proceed(request); + } + + // If first time, get the token + OAuthClientRequest oAuthRequest; + if (getAccessToken() == null) { + updateAccessToken(null); + } + + if (getAccessToken() != null) { + // Build the request + Builder rb = request.newBuilder(); + + String requestAccessToken = new String(getAccessToken()); + try { + oAuthRequest = new OAuthBearerClientRequest(request.url().toString()) + .setAccessToken(requestAccessToken) + .buildHeaderMessage(); + } catch (OAuthSystemException e) { + throw new IOException(e); + } + + for ( Map.Entry header : oAuthRequest.getHeaders().entrySet() ) { + rb.addHeader(header.getKey(), header.getValue()); + } + rb.url( oAuthRequest.getLocationUri()); + + //Execute the request + Response response = chain.proceed(rb.build()); + + // 401 most likely indicates that access token has expired. + // Time to refresh and resend the request + if ( response != null && (response.code() == HTTP_UNAUTHORIZED | response.code() == HTTP_FORBIDDEN) ) { + if (updateAccessToken(requestAccessToken)) { + return intercept( chain ); + } + } + return response; + } else { + return chain.proceed(chain.request()); + } + } + + /* + * Returns true if the access token has been updated + */ + public synchronized boolean updateAccessToken(String requestAccessToken) throws IOException { + if (getAccessToken() == null || getAccessToken().equals(requestAccessToken)) { + try { + OAuthJSONAccessTokenResponse accessTokenResponse = oauthClient.accessToken(this.tokenRequestBuilder.buildBodyMessage()); + if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) { + setAccessToken(accessTokenResponse.getAccessToken()); + if (accessTokenListener != null) { + accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken()); + } + return getAccessToken().equals(requestAccessToken); + } else { + return false; + } + } catch (OAuthSystemException e) { + throw new IOException(e); + } catch (OAuthProblemException e) { + throw new IOException(e); + } + } + return true; + } + + public void registerAccessTokenListener(AccessTokenListener accessTokenListener) { + this.accessTokenListener = accessTokenListener; + } + + public synchronized String getAccessToken() { + return accessToken; + } + + public synchronized void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public TokenRequestBuilder getTokenRequestBuilder() { + return tokenRequestBuilder; + } + + public void setTokenRequestBuilder(TokenRequestBuilder tokenRequestBuilder) { + this.tokenRequestBuilder = tokenRequestBuilder; + } + + public AuthenticationRequestBuilder getAuthenticationRequestBuilder() { + return authenticationRequestBuilder; + } + + public void setAuthenticationRequestBuilder(AuthenticationRequestBuilder authenticationRequestBuilder) { + this.authenticationRequestBuilder = authenticationRequestBuilder; + } + +} diff --git a/api-lib/src/main/java/io/swagger/client/auth/OAuthFlow.java b/api-lib/src/main/java/io/swagger/client/auth/OAuthFlow.java new file mode 100644 index 0000000..9bddf47 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/auth/OAuthFlow.java @@ -0,0 +1,30 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.auth; + +public enum OAuthFlow { + accessCode, implicit, password, application +} diff --git a/api-lib/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java b/api-lib/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java new file mode 100644 index 0000000..c9b6e12 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java @@ -0,0 +1,72 @@ +package io.swagger.client.auth; + +import java.io.IOException; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.oltu.oauth2.client.HttpClient; +import org.apache.oltu.oauth2.client.request.OAuthClientRequest; +import org.apache.oltu.oauth2.client.response.OAuthClientResponse; +import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory; +import org.apache.oltu.oauth2.common.exception.OAuthProblemException; +import org.apache.oltu.oauth2.common.exception.OAuthSystemException; + + +import okhttp3.Interceptor; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Request.Builder; +import okhttp3.Response; +import okhttp3.MediaType; +import okhttp3.RequestBody; + + +public class OAuthOkHttpClient implements HttpClient { + + private OkHttpClient client; + + public OAuthOkHttpClient() { + this.client = new OkHttpClient(); + } + + public OAuthOkHttpClient(OkHttpClient client) { + this.client = client; + } + + public T execute(OAuthClientRequest request, Map headers, + String requestMethod, Class responseClass) + throws OAuthSystemException, OAuthProblemException { + + MediaType mediaType = MediaType.parse("application/json"); + Request.Builder requestBuilder = new Request.Builder().url(request.getLocationUri()); + + if(headers != null) { + for (Entry entry : headers.entrySet()) { + if (entry.getKey().equalsIgnoreCase("Content-Type")) { + mediaType = MediaType.parse(entry.getValue()); + } else { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + } + } + + RequestBody body = request.getBody() != null ? RequestBody.create(mediaType, request.getBody()) : null; + requestBuilder.method(requestMethod, body); + + try { + Response response = client.newCall(requestBuilder.build()).execute(); + return OAuthClientResponseFactory.createCustomResponse( + response.body().string(), + response.body().contentType().toString(), + response.code(), + responseClass); + } catch (IOException e) { + throw new OAuthSystemException(e); + } + } + + public void shutdown() { + // Nothing to do here + } + +} diff --git a/api-lib/src/main/java/io/swagger/client/model/Article.java b/api-lib/src/main/java/io/swagger/client/model/Article.java new file mode 100644 index 0000000..f162f3e --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/model/Article.java @@ -0,0 +1,565 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.model; + +import java.util.Objects; +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.client.model.ArticleMultimedia; +import io.swagger.client.model.ArticleRelatedUrls; +import java.util.ArrayList; +import java.util.List; + + +/** + * Article + */ +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-09-19T22:13:55.972-04:00") +public class Article { + @SerializedName("section") + private String section = null; + + @SerializedName("subsection") + private String subsection = null; + + @SerializedName("title") + private String title = null; + + @SerializedName("abstract") + private String _abstract = null; + + @SerializedName("url") + private String url = null; + + @SerializedName("thumbnail_standard") + private String thumbnailStandard = null; + + @SerializedName("short_url") + private String shortUrl = null; + + @SerializedName("byline") + private String byline = null; + + @SerializedName("item_type") + private String itemType = null; + + @SerializedName("updated_date") + private String updatedDate = null; + + @SerializedName("created_date") + private String createdDate = null; + + @SerializedName("published_date") + private String publishedDate = null; + + @SerializedName("material_type_facet") + private String materialTypeFacet = null; + + @SerializedName("kicker") + private String kicker = null; + + @SerializedName("des_facet") + private List desFacet = new ArrayList(); + + @SerializedName("org_facet") + private String orgFacet = null; + + @SerializedName("per_facet") + private List perFacet = new ArrayList(); + + @SerializedName("geo_facet") + private List geoFacet = new ArrayList(); + + @SerializedName("multimedia") + private List multimedia = new ArrayList(); + + @SerializedName("related_urls") + private List relatedUrls = new ArrayList(); + + public Article section(String section) { + this.section = section; + return this; + } + + /** + * Get section + * @return section + **/ + @ApiModelProperty(example = "null", value = "") + public String getSection() { + return section; + } + + public void setSection(String section) { + this.section = section; + } + + public Article subsection(String subsection) { + this.subsection = subsection; + return this; + } + + /** + * Get subsection + * @return subsection + **/ + @ApiModelProperty(example = "null", value = "") + public String getSubsection() { + return subsection; + } + + public void setSubsection(String subsection) { + this.subsection = subsection; + } + + public Article title(String title) { + this.title = title; + return this; + } + + /** + * Get title + * @return title + **/ + @ApiModelProperty(example = "null", value = "") + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public Article _abstract(String _abstract) { + this._abstract = _abstract; + return this; + } + + /** + * Get _abstract + * @return _abstract + **/ + @ApiModelProperty(example = "null", value = "") + public String getAbstract() { + return _abstract; + } + + public void setAbstract(String _abstract) { + this._abstract = _abstract; + } + + public Article url(String url) { + this.url = url; + return this; + } + + /** + * Get url + * @return url + **/ + @ApiModelProperty(example = "null", value = "") + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public Article thumbnailStandard(String thumbnailStandard) { + this.thumbnailStandard = thumbnailStandard; + return this; + } + + /** + * Get thumbnailStandard + * @return thumbnailStandard + **/ + @ApiModelProperty(example = "null", value = "") + public String getThumbnailStandard() { + return thumbnailStandard; + } + + public void setThumbnailStandard(String thumbnailStandard) { + this.thumbnailStandard = thumbnailStandard; + } + + public Article shortUrl(String shortUrl) { + this.shortUrl = shortUrl; + return this; + } + + /** + * Get shortUrl + * @return shortUrl + **/ + @ApiModelProperty(example = "null", value = "") + public String getShortUrl() { + return shortUrl; + } + + public void setShortUrl(String shortUrl) { + this.shortUrl = shortUrl; + } + + public Article byline(String byline) { + this.byline = byline; + return this; + } + + /** + * Get byline + * @return byline + **/ + @ApiModelProperty(example = "null", value = "") + public String getByline() { + return byline; + } + + public void setByline(String byline) { + this.byline = byline; + } + + public Article itemType(String itemType) { + this.itemType = itemType; + return this; + } + + /** + * Get itemType + * @return itemType + **/ + @ApiModelProperty(example = "null", value = "") + public String getItemType() { + return itemType; + } + + public void setItemType(String itemType) { + this.itemType = itemType; + } + + public Article updatedDate(String updatedDate) { + this.updatedDate = updatedDate; + return this; + } + + /** + * Get updatedDate + * @return updatedDate + **/ + @ApiModelProperty(example = "null", value = "") + public String getUpdatedDate() { + return updatedDate; + } + + public void setUpdatedDate(String updatedDate) { + this.updatedDate = updatedDate; + } + + public Article createdDate(String createdDate) { + this.createdDate = createdDate; + return this; + } + + /** + * Get createdDate + * @return createdDate + **/ + @ApiModelProperty(example = "null", value = "") + public String getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(String createdDate) { + this.createdDate = createdDate; + } + + public Article publishedDate(String publishedDate) { + this.publishedDate = publishedDate; + return this; + } + + /** + * Get publishedDate + * @return publishedDate + **/ + @ApiModelProperty(example = "null", value = "") + public String getPublishedDate() { + return publishedDate; + } + + public void setPublishedDate(String publishedDate) { + this.publishedDate = publishedDate; + } + + public Article materialTypeFacet(String materialTypeFacet) { + this.materialTypeFacet = materialTypeFacet; + return this; + } + + /** + * Get materialTypeFacet + * @return materialTypeFacet + **/ + @ApiModelProperty(example = "null", value = "") + public String getMaterialTypeFacet() { + return materialTypeFacet; + } + + public void setMaterialTypeFacet(String materialTypeFacet) { + this.materialTypeFacet = materialTypeFacet; + } + + public Article kicker(String kicker) { + this.kicker = kicker; + return this; + } + + /** + * Get kicker + * @return kicker + **/ + @ApiModelProperty(example = "null", value = "") + public String getKicker() { + return kicker; + } + + public void setKicker(String kicker) { + this.kicker = kicker; + } + + public Article desFacet(List desFacet) { + this.desFacet = desFacet; + return this; + } + + public Article addDesFacetItem(String desFacetItem) { + this.desFacet.add(desFacetItem); + return this; + } + + /** + * Get desFacet + * @return desFacet + **/ + @ApiModelProperty(example = "null", value = "") + public List getDesFacet() { + return desFacet; + } + + public void setDesFacet(List desFacet) { + this.desFacet = desFacet; + } + + public Article orgFacet(String orgFacet) { + this.orgFacet = orgFacet; + return this; + } + + /** + * Get orgFacet + * @return orgFacet + **/ + @ApiModelProperty(example = "null", value = "") + public String getOrgFacet() { + return orgFacet; + } + + public void setOrgFacet(String orgFacet) { + this.orgFacet = orgFacet; + } + + public Article perFacet(List perFacet) { + this.perFacet = perFacet; + return this; + } + + public Article addPerFacetItem(String perFacetItem) { + this.perFacet.add(perFacetItem); + return this; + } + + /** + * Get perFacet + * @return perFacet + **/ + @ApiModelProperty(example = "null", value = "") + public List getPerFacet() { + return perFacet; + } + + public void setPerFacet(List perFacet) { + this.perFacet = perFacet; + } + + public Article geoFacet(List geoFacet) { + this.geoFacet = geoFacet; + return this; + } + + public Article addGeoFacetItem(String geoFacetItem) { + this.geoFacet.add(geoFacetItem); + return this; + } + + /** + * Get geoFacet + * @return geoFacet + **/ + @ApiModelProperty(example = "null", value = "") + public List getGeoFacet() { + return geoFacet; + } + + public void setGeoFacet(List geoFacet) { + this.geoFacet = geoFacet; + } + + public Article multimedia(List multimedia) { + this.multimedia = multimedia; + return this; + } + + public Article addMultimediaItem(ArticleMultimedia multimediaItem) { + this.multimedia.add(multimediaItem); + return this; + } + + /** + * Get multimedia + * @return multimedia + **/ + @ApiModelProperty(example = "null", value = "") + public List getMultimedia() { + return multimedia; + } + + public void setMultimedia(List multimedia) { + this.multimedia = multimedia; + } + + public Article relatedUrls(List relatedUrls) { + this.relatedUrls = relatedUrls; + return this; + } + + public Article addRelatedUrlsItem(ArticleRelatedUrls relatedUrlsItem) { + this.relatedUrls.add(relatedUrlsItem); + return this; + } + + /** + * Get relatedUrls + * @return relatedUrls + **/ + @ApiModelProperty(example = "null", value = "") + public List getRelatedUrls() { + return relatedUrls; + } + + public void setRelatedUrls(List relatedUrls) { + this.relatedUrls = relatedUrls; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Article article = (Article) o; + return Objects.equals(this.section, article.section) && + Objects.equals(this.subsection, article.subsection) && + Objects.equals(this.title, article.title) && + Objects.equals(this._abstract, article._abstract) && + Objects.equals(this.url, article.url) && + Objects.equals(this.thumbnailStandard, article.thumbnailStandard) && + Objects.equals(this.shortUrl, article.shortUrl) && + Objects.equals(this.byline, article.byline) && + Objects.equals(this.itemType, article.itemType) && + Objects.equals(this.updatedDate, article.updatedDate) && + Objects.equals(this.createdDate, article.createdDate) && + Objects.equals(this.publishedDate, article.publishedDate) && + Objects.equals(this.materialTypeFacet, article.materialTypeFacet) && + Objects.equals(this.kicker, article.kicker) && + Objects.equals(this.desFacet, article.desFacet) && + Objects.equals(this.orgFacet, article.orgFacet) && + Objects.equals(this.perFacet, article.perFacet) && + Objects.equals(this.geoFacet, article.geoFacet) && + Objects.equals(this.multimedia, article.multimedia) && + Objects.equals(this.relatedUrls, article.relatedUrls); + } + + @Override + public int hashCode() { + return Objects.hash(section, subsection, title, _abstract, url, thumbnailStandard, shortUrl, byline, itemType, updatedDate, createdDate, publishedDate, materialTypeFacet, kicker, desFacet, orgFacet, perFacet, geoFacet, multimedia, relatedUrls); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Article {\n"); + + sb.append(" section: ").append(toIndentedString(section)).append("\n"); + sb.append(" subsection: ").append(toIndentedString(subsection)).append("\n"); + sb.append(" title: ").append(toIndentedString(title)).append("\n"); + sb.append(" _abstract: ").append(toIndentedString(_abstract)).append("\n"); + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append(" thumbnailStandard: ").append(toIndentedString(thumbnailStandard)).append("\n"); + sb.append(" shortUrl: ").append(toIndentedString(shortUrl)).append("\n"); + sb.append(" byline: ").append(toIndentedString(byline)).append("\n"); + sb.append(" itemType: ").append(toIndentedString(itemType)).append("\n"); + sb.append(" updatedDate: ").append(toIndentedString(updatedDate)).append("\n"); + sb.append(" createdDate: ").append(toIndentedString(createdDate)).append("\n"); + sb.append(" publishedDate: ").append(toIndentedString(publishedDate)).append("\n"); + sb.append(" materialTypeFacet: ").append(toIndentedString(materialTypeFacet)).append("\n"); + sb.append(" kicker: ").append(toIndentedString(kicker)).append("\n"); + sb.append(" desFacet: ").append(toIndentedString(desFacet)).append("\n"); + sb.append(" orgFacet: ").append(toIndentedString(orgFacet)).append("\n"); + sb.append(" perFacet: ").append(toIndentedString(perFacet)).append("\n"); + sb.append(" geoFacet: ").append(toIndentedString(geoFacet)).append("\n"); + sb.append(" multimedia: ").append(toIndentedString(multimedia)).append("\n"); + sb.append(" relatedUrls: ").append(toIndentedString(relatedUrls)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/api-lib/src/main/java/io/swagger/client/model/ArticleMultimedia.java b/api-lib/src/main/java/io/swagger/client/model/ArticleMultimedia.java new file mode 100644 index 0000000..68ba43e --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/model/ArticleMultimedia.java @@ -0,0 +1,260 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.model; + +import java.util.Objects; +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + + +/** + * ArticleMultimedia + */ +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-09-19T22:13:55.972-04:00") +public class ArticleMultimedia { + @SerializedName("url") + private String url = null; + + @SerializedName("format") + private String format = null; + + @SerializedName("height") + private Integer height = null; + + @SerializedName("width") + private Integer width = null; + + @SerializedName("type") + private String type = null; + + @SerializedName("subtype") + private String subtype = null; + + @SerializedName("caption") + private String caption = null; + + @SerializedName("copyright") + private String copyright = null; + + public ArticleMultimedia url(String url) { + this.url = url; + return this; + } + + /** + * Get url + * @return url + **/ + @ApiModelProperty(example = "null", value = "") + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public ArticleMultimedia format(String format) { + this.format = format; + return this; + } + + /** + * Get format + * @return format + **/ + @ApiModelProperty(example = "null", value = "") + public String getFormat() { + return format; + } + + public void setFormat(String format) { + this.format = format; + } + + public ArticleMultimedia height(Integer height) { + this.height = height; + return this; + } + + /** + * Get height + * @return height + **/ + @ApiModelProperty(example = "null", value = "") + public Integer getHeight() { + return height; + } + + public void setHeight(Integer height) { + this.height = height; + } + + public ArticleMultimedia width(Integer width) { + this.width = width; + return this; + } + + /** + * Get width + * @return width + **/ + @ApiModelProperty(example = "null", value = "") + public Integer getWidth() { + return width; + } + + public void setWidth(Integer width) { + this.width = width; + } + + public ArticleMultimedia type(String type) { + this.type = type; + return this; + } + + /** + * Get type + * @return type + **/ + @ApiModelProperty(example = "null", value = "") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public ArticleMultimedia subtype(String subtype) { + this.subtype = subtype; + return this; + } + + /** + * Get subtype + * @return subtype + **/ + @ApiModelProperty(example = "null", value = "") + public String getSubtype() { + return subtype; + } + + public void setSubtype(String subtype) { + this.subtype = subtype; + } + + public ArticleMultimedia caption(String caption) { + this.caption = caption; + return this; + } + + /** + * Get caption + * @return caption + **/ + @ApiModelProperty(example = "null", value = "") + public String getCaption() { + return caption; + } + + public void setCaption(String caption) { + this.caption = caption; + } + + public ArticleMultimedia copyright(String copyright) { + this.copyright = copyright; + return this; + } + + /** + * Get copyright + * @return copyright + **/ + @ApiModelProperty(example = "null", value = "") + public String getCopyright() { + return copyright; + } + + public void setCopyright(String copyright) { + this.copyright = copyright; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ArticleMultimedia articleMultimedia = (ArticleMultimedia) o; + return Objects.equals(this.url, articleMultimedia.url) && + Objects.equals(this.format, articleMultimedia.format) && + Objects.equals(this.height, articleMultimedia.height) && + Objects.equals(this.width, articleMultimedia.width) && + Objects.equals(this.type, articleMultimedia.type) && + Objects.equals(this.subtype, articleMultimedia.subtype) && + Objects.equals(this.caption, articleMultimedia.caption) && + Objects.equals(this.copyright, articleMultimedia.copyright); + } + + @Override + public int hashCode() { + return Objects.hash(url, format, height, width, type, subtype, caption, copyright); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ArticleMultimedia {\n"); + + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append(" format: ").append(toIndentedString(format)).append("\n"); + sb.append(" height: ").append(toIndentedString(height)).append("\n"); + sb.append(" width: ").append(toIndentedString(width)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" subtype: ").append(toIndentedString(subtype)).append("\n"); + sb.append(" caption: ").append(toIndentedString(caption)).append("\n"); + sb.append(" copyright: ").append(toIndentedString(copyright)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/api-lib/src/main/java/io/swagger/client/model/ArticleRelatedUrls.java b/api-lib/src/main/java/io/swagger/client/model/ArticleRelatedUrls.java new file mode 100644 index 0000000..c9fe2c1 --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/model/ArticleRelatedUrls.java @@ -0,0 +1,122 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.model; + +import java.util.Objects; +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + + +/** + * ArticleRelatedUrls + */ +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-09-19T22:13:55.972-04:00") +public class ArticleRelatedUrls { + @SerializedName("suggested_link_text") + private String suggestedLinkText = null; + + @SerializedName("url") + private String url = null; + + public ArticleRelatedUrls suggestedLinkText(String suggestedLinkText) { + this.suggestedLinkText = suggestedLinkText; + return this; + } + + /** + * Get suggestedLinkText + * @return suggestedLinkText + **/ + @ApiModelProperty(example = "null", value = "") + public String getSuggestedLinkText() { + return suggestedLinkText; + } + + public void setSuggestedLinkText(String suggestedLinkText) { + this.suggestedLinkText = suggestedLinkText; + } + + public ArticleRelatedUrls url(String url) { + this.url = url; + return this; + } + + /** + * Get url + * @return url + **/ + @ApiModelProperty(example = "null", value = "") + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ArticleRelatedUrls articleRelatedUrls = (ArticleRelatedUrls) o; + return Objects.equals(this.suggestedLinkText, articleRelatedUrls.suggestedLinkText) && + Objects.equals(this.url, articleRelatedUrls.url); + } + + @Override + public int hashCode() { + return Objects.hash(suggestedLinkText, url); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ArticleRelatedUrls {\n"); + + sb.append(" suggestedLinkText: ").append(toIndentedString(suggestedLinkText)).append("\n"); + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/api-lib/src/main/java/io/swagger/client/model/InlineResponse200.java b/api-lib/src/main/java/io/swagger/client/model/InlineResponse200.java new file mode 100644 index 0000000..65af28c --- /dev/null +++ b/api-lib/src/main/java/io/swagger/client/model/InlineResponse200.java @@ -0,0 +1,107 @@ +/* + * Top Stories V2 + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + * + * OpenAPI spec version: 2.0.0 + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.model; + +import java.util.Objects; +import com.google.gson.annotations.SerializedName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.client.model.Article; +import java.util.ArrayList; +import java.util.List; + + +/** + * InlineResponse200 + */ +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-09-19T22:13:55.972-04:00") +public class InlineResponse200 { + @SerializedName("results") + private List
results = new ArrayList
(); + + public InlineResponse200 results(List
results) { + this.results = results; + return this; + } + + public InlineResponse200 addResultsItem(Article resultsItem) { + this.results.add(resultsItem); + return this; + } + + /** + * Get results + * @return results + **/ + @ApiModelProperty(example = "null", value = "") + public List
getResults() { + return results; + } + + public void setResults(List
results) { + this.results = results; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + InlineResponse200 inlineResponse200 = (InlineResponse200) o; + return Objects.equals(this.results, inlineResponse200.results); + } + + @Override + public int hashCode() { + return Objects.hash(results); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class InlineResponse200 {\n"); + + sb.append(" results: ").append(toIndentedString(results)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/api-lib/src/test/java/io/swagger/client/api/StoriesApiTest.java b/api-lib/src/test/java/io/swagger/client/api/StoriesApiTest.java new file mode 100644 index 0000000..13b51b3 --- /dev/null +++ b/api-lib/src/test/java/io/swagger/client/api/StoriesApiTest.java @@ -0,0 +1,41 @@ +package io.swagger.client.api; + +import io.swagger.client.ApiClient; +import io.swagger.client.model.InlineResponse200; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * API tests for StoriesApi + */ +public class StoriesApiTest { + + private StoriesApi api; + + @Before + public void setup() { + api = new ApiClient().createService(StoriesApi.class); + } + + + /** + * Top Stories + * + * The Top Stories API provides JSON and JSONP lists of articles and associated images by section. + */ + @Test + public void sectionFormatGetTest() { + String section = null; + String format = null; + String callback = null; + // InlineResponse200 response = api.sectionFormatGet(section, format, callback); + + // TODO: test validations + } + +} diff --git a/core-lib/src/main/java/info/hossainkhan/android/core/CoreConfig.java b/core-lib/src/main/java/info/hossainkhan/android/core/CoreConfig.java index 9a2cf39..acf5714 100644 --- a/core-lib/src/main/java/info/hossainkhan/android/core/CoreConfig.java +++ b/core-lib/src/main/java/info/hossainkhan/android/core/CoreConfig.java @@ -1,8 +1,5 @@ package info.hossainkhan.android.core; -import com.example.ApiCore; - public class CoreConfig { public static final String NAME = "TESTING"; - public static final String LIB_DEPS = ApiCore.TEST; } diff --git a/mobile/src/main/java/info/hossainkhan/dailynewsheadlines/MainActivity.java b/mobile/src/main/java/info/hossainkhan/dailynewsheadlines/MainActivity.java index 9b13ea1..0dc5c6a 100644 --- a/mobile/src/main/java/info/hossainkhan/dailynewsheadlines/MainActivity.java +++ b/mobile/src/main/java/info/hossainkhan/dailynewsheadlines/MainActivity.java @@ -4,7 +4,6 @@ import android.os.Bundle; import android.util.Log; -import com.example.ApiCore; import com.google.firebase.crash.FirebaseCrash; import info.hossainkhan.android.core.CoreConfig; @@ -17,7 +16,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Log.d(TAG, "onCreate: " + ApiCore.TEST + CoreConfig.NAME); + Log.d(TAG, "onCreate: " + CoreConfig.NAME); } @Override