11package com .crowdin .client .core ;
22
33import com .crowdin .client .core .http .HttpClient ;
4+ import com .crowdin .client .core .http .HttpRequestConfig ;
45import com .crowdin .client .core .http .JsonTransformer ;
56import com .crowdin .client .core .http .impl .http .ApacheHttpClient ;
67import com .crowdin .client .core .http .impl .json .JacksonJsonTransformer ;
7- import com .crowdin .client .core .model .ClientConfig ;
8- import com .crowdin .client .core .model .Credentials ;
8+ import com .crowdin .client .core .model .*;
99import org .apache .http .client .config .CookieSpecs ;
1010import org .apache .http .client .config .RequestConfig ;
1111import org .apache .http .impl .client .HttpClientBuilder ;
@@ -19,6 +19,7 @@ public abstract class CrowdinApi {
1919 protected final HttpClient httpClient ;
2020 protected final ClientConfig clientConfig ;
2121 protected final String url ;
22+ protected final String graphqlUrl ;
2223
2324 public CrowdinApi (Credentials credentials ) {
2425 this (credentials , ClientConfig .builder ()
@@ -38,23 +39,50 @@ public CrowdinApi(Credentials credentials, ClientConfig clientConfig) {
3839 defaultHeaders .put ("X-Crowdin-Integrations-User-Agent" , clientConfig .getIntegrationUserAgent ());
3940 }
4041 JsonTransformer jsonTransformer = (clientConfig .getJsonTransformer () != null )
41- ? clientConfig .getJsonTransformer () : new JacksonJsonTransformer ();
42+ ? clientConfig .getJsonTransformer () : new JacksonJsonTransformer ();
4243 this .httpClient = (clientConfig .getHttpClient () != null )
43- ? clientConfig .getHttpClient ()
44- : new ApacheHttpClient (credentials , jsonTransformer , defaultHeaders , clientConfig .getProxy (), clientConfig .getProxyCreds (), clientConfig .getHttpTimeoutMs ());
44+ ? clientConfig .getHttpClient ()
45+ : new ApacheHttpClient (credentials , jsonTransformer , defaultHeaders , clientConfig .getProxy (), clientConfig .getProxyCreds (), clientConfig .getHttpTimeoutMs ());
4546 this .clientConfig = clientConfig ;
4647 if (credentials .getBaseUrl () != null ) {
4748 if (credentials .getBaseUrl ().endsWith ("/" )) {
4849 this .url = credentials .getBaseUrl () + "api/v2" ;
50+ this .graphqlUrl = credentials .getBaseUrl () + "api/graphql" ;
4951 } else {
5052 this .url = credentials .getBaseUrl () + "/api/v2" ;
53+ this .graphqlUrl = credentials .getBaseUrl () + "/api/graphql" ;
5154 }
5255 } else {
5356 if (credentials .getOrganization () != null ) {
5457 this .url = "https://" + credentials .getOrganization () + ".api.crowdin.com/api/v2" ;
58+ this .graphqlUrl = "https://" + credentials .getOrganization () + ".api.crowdin.com/api/graphql" ;
5559 } else {
5660 this .url = "https://api.crowdin.com/api/v2" ;
61+ this .graphqlUrl = "https://api.crowdin.com/api/graphql" ;
5762 }
5863 }
5964 }
65+
66+ /**
67+ * @param request request object
68+ * @return newly created bundle
69+ * @see <ul>
70+ * <li><a href="https://support.crowdin.com/developer/graphql-api/" target="_blank"><b>API Documentation</b></a></li>
71+ * </ul>
72+ */
73+ public ResponseObject <Map <String , Object >> graphql (GraphQLRequest request ) {
74+ GraphQLResponse response = this .graphql (request , GraphQLResponse .class );
75+ return ResponseObject .of (response .getData ());
76+ }
77+
78+ /**
79+ * @param request request object
80+ * @return newly created bundle
81+ * @see <ul>
82+ * <li><a href="https://support.crowdin.com/developer/graphql-api/" target="_blank"><b>API Documentation</b></a></li>
83+ * </ul>
84+ */
85+ public <T > T graphql (GraphQLRequest request , Class <T > clazz ) {
86+ return this .httpClient .post (this .graphqlUrl , request , new HttpRequestConfig (), clazz );
87+ }
6088}
0 commit comments