Skip to content

Commit a06e23a

Browse files
committed
Fixed URLs and Constants
1 parent 3b77abe commit a06e23a

File tree

10 files changed

+253
-333
lines changed

10 files changed

+253
-333
lines changed

core/src/main/java/com/github/api/v2/services/constant/ApplicationConstants.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,23 @@ public final class ApplicationConstants {
3131
}
3232
}
3333

34-
/** The Constant VALIDATE_XML. */
35-
public static final boolean VALIDATE_XML = getBooleanProperty("com.google.code.stackexchange.client.validateXml");
36-
37-
/** The Constant DEFAULT_PAGE_SIZE. */
38-
public static final int DEFAULT_PAGE_SIZE =
39-
getIntProperty("com.googleapis.ajax.services.client.defaultPageSize");
40-
4134
/** The Constant CONTENT_ENCODING. */
42-
public static final String CONTENT_ENCODING = getProperty("com.googleapis.ajax.services.client.encoding");
35+
public static final String CONTENT_ENCODING = getProperty("com.github.api.v2.services.encoding");
4336

4437
/** The Constant DEFAULT_API_VERSION. */
45-
public static final String DEFAULT_API_VERSION = getProperty("com.googleapis.ajax.services.client.defaultApiVersion");
38+
public static final String DEFAULT_API_VERSION = getProperty("com.github.api.v2.services.defaultApiVersion");
39+
40+
/** The Constant DEFAULT_API_VERSION. */
41+
public static final String DEFAULT_FORMAT = getProperty("com.github.api.v2.services.defaultFormat");
4642

4743
/** The Constant RFC822DATEFORMAT. */
48-
public static final String RFC822DATEFORMAT = getProperty("com.googleapis.ajax.services.client.dateFormat");
44+
public static final String RFC822DATEFORMAT = getProperty("com.github.api.v2.services.dateFormat");
4945

5046
/** The Constant CONNECT_TIMEOUT. */
51-
public static final int CONNECT_TIMEOUT = getIntProperty("com.googleapis.ajax.services.client.connectTimeout");
47+
public static final int CONNECT_TIMEOUT = getIntProperty("com.github.api.v2.services.connectTimeout");
5248

5349
/** The Constant READ_TIMEOUT. */
54-
public static final int READ_TIMEOUT = getIntProperty("com.googleapis.ajax.services.client.readTimeout");
50+
public static final int READ_TIMEOUT = getIntProperty("com.github.api.v2.services.readTimeout");
5551

5652
/**
5753
* Instantiates a new application constants.

core/src/main/java/com/github/api/v2/services/constant/GitHubApiUrls.java

Lines changed: 150 additions & 163 deletions
Large diffs are not rendered by default.

core/src/main/java/com/github/api/v2/services/constant/ParameterNames.java

Lines changed: 20 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,126 +7,64 @@
77
* The Interface ParameterNames.
88
*/
99
public interface ParameterNames {
10-
// Standard URL Arguments
11-
/** The Constant QUERY. */
12-
public static final String QUERY = "q";
13-
10+
1411
/** The Constant VERSION. */
15-
public static final String VERSION = "v";
12+
public static final String VERSION = "version";
1613

1714
/** The Constant USER_IP_ADDRESS. */
18-
public static final String USER_IP_ADDRESS = "userip";
15+
public static final String USER_NAME = "userName";
1916

2017
/** The Constant RESULTSET_SIZE. */
21-
public static final String RESULTSET_SIZE = "rsz";
18+
public static final String EMAIL = "email";
2219

2320
/** The Constant HOST_LANGUAGE. */
24-
public static final String HOST_LANGUAGE = "hl";
21+
public static final String REPOSITORY_NAME = "repositoryName";
2522

2623
/** The Constant KEY. */
27-
public static final String KEY = "key";
24+
public static final String KEYWORD = "keyword";
2825

2926
/** The Constant START. */
30-
public static final String START = "start";
27+
public static final String STATE = "state";
3128

3229
/** The Constant CALLBACK. */
33-
public static final String CALLBACK = "callback";
30+
public static final String ISSUE_NUMBER = "issueNumber";
3431

3532
/** The Constant CONTEXT. */
36-
public static final String CONTEXT = "context";
33+
public static final String LABEL = "label";
3734

38-
// Web Search Specific Arguments
3935
/** The Constant CUSTOM_SEARCH_ID. */
40-
public static final String CUSTOM_SEARCH_ID = "cx";
36+
public static final String GIST_ID = "gistId";
4137

4238
/** The Constant CUSTOM_SEARCH_URL. */
43-
public static final String CUSTOM_SEARCH_URL = "cref";
39+
public static final String FILE_NAME = "fileName";
4440

4541
/** The Constant SAFETY_LEVEL. */
46-
public static final String SAFETY_LEVEL = "safe";
42+
public static final String NET_HASH = "netHash";
4743

4844
/** The Constant LANGUAGE_RESTRICTION. */
49-
public static final String LANGUAGE_RESTRICTION = "lr";
45+
public static final String START_INDEX = "startIndex";
5046

5147
/** The Constant DUPLICATE_FILTER. */
52-
public static final String DUPLICATE_FILTER = "filter";
48+
public static final String END_INDEX = "endIndex";
5349

5450
/** The Constant COUNTRY_RESTRICTION. */
55-
public static final String COUNTRY_RESTRICTION = "gl";
51+
public static final String LANGUAGE = "language";
5652

57-
// Local Search Specific Arguments
5853
/** The Constant SEARCH_CENTER_POINT. */
59-
public static final String SEARCH_CENTER_POINT = "sll";
54+
public static final String START_PAGE = "startPage";
6055

6156
/** The Constant BOUNDING_BOX. */
62-
public static final String BOUNDING_BOX = "sspn";
57+
public static final String VISIBILITY = "visibility";
6358

6459
/** The Constant TYPE_OF_LISTING. */
65-
public static final String TYPE_OF_LISTING = "mrt";
60+
public static final String BRANCH = "branch";
6661

67-
// Video Search Specific Arguments
6862
/** The Constant SCORING. */
69-
public static final String SCORING = "scoring";
63+
public static final String FILE_PATH = "filePath";
7064

71-
// News Search Specific Arguments
7265
/** The Constant GEO. */
73-
public static final String GEO = "geo";
74-
75-
/** The Constant QSID. */
76-
public static final String QSID = "qsid";
77-
78-
/** The Constant TOPIC. */
79-
public static final String TOPIC = "topic";
80-
81-
/** The Constant NEWS_EDITION. */
82-
public static final String NEWS_EDITION = "ned";
83-
84-
// Book Search Specific Arguments
85-
/** The Constant BOOK_RESTRICTION. */
86-
public static final String BOOK_RESTRICTION = "as_brr";
87-
88-
/** The Constant BOOK_LIBRARY. */
89-
public static final String BOOK_LIBRARY = "as_list";
90-
91-
// Image Search Specific Arguments
92-
/** The Constant IMAGE_SIZE. */
93-
public static final String IMAGE_SIZE = "imgsz";
94-
95-
/** The Constant IMAGE_COLORIZATION. */
96-
public static final String IMAGE_COLORIZATION = "imgc";
97-
98-
/** The Constant IMAGE_COLOR. */
99-
public static final String IMAGE_COLOR = "imgcolor";
100-
101-
/** The Constant IMAGE_TYPE. */
102-
public static final String IMAGE_TYPE = "imgtype";
103-
104-
/** The Constant IMAGE_FILE_TYPE. */
105-
public static final String IMAGE_FILE_TYPE = "as_filetype";
106-
107-
/** The Constant IMAGE_RIGHTS. */
108-
public static final String IMAGE_RIGHTS = "as_rights";
109-
110-
/** The Constant IMAGE_SITE_SEARCH. */
111-
public static final String IMAGE_SITE_SEARCH = "as_sitesearch";
112-
113-
// Patent Search Specific Arguments
114-
/** The Constant PATENTS_ISSUED. */
115-
public static final String PATENTS_ISSUED = "as_psrg";
116-
117-
/** The Constant PATENTS_FILED. */
118-
public static final String PATENTS_FILED = "as_psra";
119-
120-
// Translate Language Specific Arguments
121-
/** The Constant LANGUAGE_PAIR. */
122-
public static final String LANGUAGE_PAIR = "langpair";
66+
public static final String SHA = "sha";
12367

12468
/** The Constant FORMAT. */
12569
public static final String FORMAT = "format";
126-
127-
/** The Constant SITE_SUFFIX. */
128-
public static final String SITE_SUFFIX = "site:";
129-
130-
/** The Constant RELATED_SUFFIX. */
131-
public static final String RELATED_SUFFIX = "related:";
13270
}

core/src/main/java/com/github/api/v2/services/impl/BaseGitHubService.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package com.github.api.v2.services.impl;
22

33
import java.io.InputStream;
4+
import java.io.InputStreamReader;
5+
import java.lang.reflect.Type;
46
import java.util.ArrayList;
57
import java.util.HashMap;
68
import java.util.List;
79

810
import com.github.api.v2.schema.SchemaEntity;
911
import com.github.api.v2.services.AsyncResponseHandler;
12+
import com.github.api.v2.services.GitHubException;
1013
import com.github.api.v2.services.GitHubService;
1114
import com.github.api.v2.services.constant.ApplicationConstants;
1215
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
16+
import com.google.gson.Gson;
1317
import com.google.gson.GsonBuilder;
1418
import com.google.gson.JsonElement;
15-
import com.google.gson.JsonObject;
1619
import com.google.gson.JsonParser;
20+
import com.google.gson.reflect.TypeToken;
1721

1822
/**
1923
* The Class BaseGoogleSearchApiQuery.
@@ -60,9 +64,10 @@ public BaseGitHubService(String applicationId, String apiVersion) {
6064
*
6165
* @return the paged list< t>
6266
*/
63-
protected <T> List<T> unmarshallList(JsonObject response) {
64-
// TODO-NM: Implement this method.
65-
return null;
67+
protected <T> List<T> unmarshallList(Class<T> clazz, JsonElement response) {
68+
Gson gson = getGsonBuilder().create();
69+
Type collectionType = new TypeToken<List<T>>(){}.getType();
70+
return gson.fromJson(response, collectionType);
6671
}
6772

6873
/**
@@ -72,9 +77,9 @@ protected <T> List<T> unmarshallList(JsonObject response) {
7277
*
7378
* @return the t
7479
*/
75-
protected <T> T unmarshall(JsonElement object) {
76-
// TODO-NM: Implement this method.
77-
return null;
80+
protected <T> T unmarshall(Class<T> clazz, JsonElement response) {
81+
Gson gson = getGsonBuilder().create();
82+
return gson.fromJson(response, clazz);
7883
}
7984

8085
/**
@@ -95,13 +100,6 @@ public void addResonseHandler(AsyncResponseHandler<List<? extends SchemaEntity>>
95100
handlers.add(handler);
96101
}
97102

98-
/* (non-Javadoc)
99-
* @see com.google.code.stackexchange.client.impl.StackOverflowApiGateway#marshallObject(java.lang.Object)
100-
*/
101-
protected String marshallObject(Object element) {
102-
return null;
103-
}
104-
105103
/**
106104
* Gets the gson builder.
107105
*
@@ -122,12 +120,14 @@ protected GsonBuilder getGsonBuilder() {
122120
return builder;
123121
}
124122

125-
/* (non-Javadoc)
126-
* @see com.google.code.googlesearch.client.impl.GoogleSearchApiGateway#unmarshallObject(java.lang.Class, java.io.InputStream)
127-
*/
128-
@Override
129-
protected <V> V unmarshallObject(Class<V> clazz, InputStream xmlContent) {
130-
return null;
123+
protected JsonElement unmarshall(InputStream jsonContent) {
124+
try {
125+
return parser.parse(new InputStreamReader(jsonContent));
126+
} catch (Exception e) {
127+
throw new GitHubException(e);
128+
} finally {
129+
closeStream(jsonContent);
130+
}
131131
}
132132

133133
/**

core/src/main/java/com/github/api/v2/services/impl/GitHubApiGateway.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public abstract class GitHubApiGateway {
2929

3030
/** The LOG. */
31-
protected final Logger LOG = Logger.getLogger(getClass().getCanonicalName());
31+
protected final Logger logger = Logger.getLogger(getClass().getCanonicalName());
3232

3333
/** The Constant GZIP_ENCODING. */
3434
private static final String GZIP_ENCODING = "gzip";
@@ -364,7 +364,7 @@ protected void closeStream(InputStream is) {
364364
is.close();
365365
}
366366
} catch (IOException e) {
367-
LOG.log(Level.SEVERE, "An error occurred while closing stream.", e);
367+
logger.log(Level.SEVERE, "An error occurred while closing stream.", e);
368368
}
369369
}
370370

@@ -379,7 +379,7 @@ protected void closeConnection(HttpURLConnection connection) {
379379
connection.disconnect();
380380
}
381381
} catch (Exception e) {
382-
LOG.log(Level.SEVERE, "An error occurred while disconnecting connection.", e);
382+
logger.log(Level.SEVERE, "An error occurred while disconnecting connection.", e);
383383
}
384384
}
385385

@@ -402,42 +402,6 @@ protected InputStream getWrappedInputStream(InputStream is, boolean gzip)
402402
}
403403
}
404404

405-
/**
406-
* Read response.
407-
*
408-
* @param clazz the clazz
409-
* @param is the is
410-
*
411-
* @return the t
412-
*/
413-
protected <T> T readResponse(Class<T> clazz, InputStream is) {
414-
try {
415-
return unmarshallObject(clazz, is);
416-
} finally {
417-
closeStream(is);
418-
}
419-
}
420-
421-
422-
/**
423-
* Unmarshall object.
424-
*
425-
* @param clazz the clazz
426-
* @param xmlContent the xml content
427-
*
428-
* @return the t
429-
*/
430-
protected abstract <T> T unmarshallObject(Class<T> clazz, InputStream xmlContent);
431-
432-
/**
433-
* Marshall object.
434-
*
435-
* @param element the element
436-
*
437-
* @return the string
438-
*/
439-
protected abstract String marshallObject(Object element);
440-
441405
/**
442406
* Encode url.
443407
*
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
com.googleapis.ajax.services.client.encoding=UTF-8
2-
com.googleapis.ajax.services.client.connectTimeout=-1
3-
com.googleapis.ajax.services.client.readTimeout=-1
4-
com.googleapis.ajax.services.client.defaultApiVersion=v2
5-
com.googleapis.ajax.services.client.requestHeaders.Accept-Encoding=gzip, deflate
6-
com.googleapis.ajax.services.client.dateFormat=EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z
1+
com.github.api.v2.services.encoding=UTF-8
2+
com.github.api.v2.services.connectTimeout=-1
3+
com.github.api.v2.services.readTimeout=-1
4+
com.github.api.v2.services.defaultApiVersion=v2
5+
com.github.api.v2.services.defaultFormat=json
6+
com.github.api.v2.services.requestHeaders.Accept-Encoding=gzip, deflate
7+
com.github.api.v2.services.dateFormat=EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z

core/src/main/resources/com/github/api/v2/services/constant/GitHubApiUrls.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ com.github.api.v2.services.networkService.getNetworkMeta=http://github.com/{user
4343
com.github.api.v2.services.networkService.getNetworkData=http://github.com/{userName}/{repositoryName}/network_data_chunk?{netHash}{startIndex}{endIndex}
4444

4545
# Repository API
46-
com.github.api.v2.services.repositoryService.searchRepositories=http://github.com/api/{version}/{format}/repos/search/{query}{language}{startPage}
46+
com.github.api.v2.services.repositoryService.searchRepositories=http://github.com/api/{version}/{format}/repos/search/{keyword}?{language}{startPage}
4747
com.github.api.v2.services.repositoryService.getRepository=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}
4848
com.github.api.v2.services.repositoryService.updateRepository=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}
4949
com.github.api.v2.services.repositoryService.getRepositories=http://github.com/api/{version}/{format}/repos/show/{userName}
@@ -57,8 +57,8 @@ com.github.api.v2.services.repositoryService.getKeys=http://github.com/api/{vers
5757
com.github.api.v2.services.repositoryService.addKey=http://github.com/api/{version}/{format}/repos/key/{repositoryName}/add
5858
com.github.api.v2.services.repositoryService.removeKey=http://github.com/api/{version}/{format}/repos/key/{repositoryName}/remove
5959
com.github.api.v2.services.repositoryService.getCollaborators=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}/collaborators
60-
com.github.api.v2.services.repositoryService.addCollaborator=http://github.com/api/{version}/{format}/repos/collaborators/{repositoryName}/add/{collaboratorName}
61-
com.github.api.v2.services.repositoryService.removeCollaborator=http://github.com/api/{version}/{format}/repos/collaborators/{repositoryName}/remove/{collaboratorName}
60+
com.github.api.v2.services.repositoryService.addCollaborator=http://github.com/api/{version}/{format}/repos/collaborators/{repositoryName}/add/{userName}
61+
com.github.api.v2.services.repositoryService.removeCollaborator=http://github.com/api/{version}/{format}/repos/collaborators/{repositoryName}/remove/{userName}
6262
com.github.api.v2.services.repositoryService.getPushableRepositories=http://github.com/api/{version}/{format}/repos/pushable
6363
com.github.api.v2.services.repositoryService.getContributors=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}/contributors
6464
com.github.api.v2.services.repositoryService.getWatchers=http://github.com/api/{version}/{format}/repos/show/{userName}/{repositoryName}/watchers

0 commit comments

Comments
 (0)