Skip to content

Commit b23fbce

Browse files
committed
Merged
2 parents 6f3e141 + 7a54fcd commit b23fbce

File tree

14 files changed

+861
-4
lines changed

14 files changed

+861
-4
lines changed

build.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
<pathelement location="target"/>
1515
<pathelement location="dev-lib/junit-4.5.jar"/>
1616
<pathelement location="lib/mygson-1.4.jar"/>
17-
<pathelement location="lib/rome-1.0.jar"/>
18-
<pathelement location="lib/jdom-1.0.jar"/>
1917
</path>
2018
<target name="init">
2119
<mkdir dir="target"/>

core/src/main/java/com/github/api/v2/services/GitHubServiceFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.github.api.v2.services.impl.FeedServiceImpl;
2121
import com.github.api.v2.services.impl.GistServiceImpl;
2222
import com.github.api.v2.services.impl.IssueServiceImpl;
23+
import com.github.api.v2.services.impl.JobServiceImpl;
2324
import com.github.api.v2.services.impl.NetworkServiceImpl;
2425
import com.github.api.v2.services.impl.OAuthServiceImpl;
2526
import com.github.api.v2.services.impl.ObjectServiceImpl;
@@ -154,4 +155,13 @@ public FeedService createFeedService() {
154155
public PullRequestService createPullRequestService() {
155156
return new PullRequestServiceImpl();
156157
}
158+
159+
/**
160+
* Creates a new GitHubService object.
161+
*
162+
* @return the job service
163+
*/
164+
public JobService createJobService() {
165+
return new JobServiceImpl();
166+
}
157167
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2010 Nabeel Mukhtar
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.github.api.v2.services;
18+
19+
import java.util.List;
20+
21+
import com.github.api.v2.schema.GeoLocation;
22+
import com.github.api.v2.schema.Job;
23+
24+
25+
/**
26+
* The Interface JobService.
27+
*/
28+
public interface JobService extends GitHubService {
29+
30+
/**
31+
* Search jobs.
32+
*
33+
* @param query
34+
* the query
35+
*
36+
* @return the list< job>
37+
*/
38+
public List<Job> searchJobs(String query);
39+
40+
/**
41+
* Search jobs.
42+
*
43+
* @param query
44+
* the query
45+
* @param location
46+
* the location
47+
*
48+
* @return the list< job>
49+
*/
50+
public List<Job> searchJobs(String query, String location);
51+
52+
/**
53+
* Search jobs.
54+
*
55+
* @param query
56+
* the query
57+
* @param location
58+
* the location
59+
*
60+
* @return the list< job>
61+
*/
62+
public List<Job> searchJobs(String query, GeoLocation location);
63+
64+
/**
65+
* Search full time jobs.
66+
*
67+
* @param query
68+
* the query
69+
*
70+
* @return the list< job>
71+
*/
72+
public List<Job> searchFullTimeJobs(String query);
73+
74+
/**
75+
* Search full time jobs.
76+
*
77+
* @param query
78+
* the query
79+
* @param location
80+
* the location
81+
*
82+
* @return the list< job>
83+
*/
84+
public List<Job> searchFullTimeJobs(String query, String location);
85+
86+
/**
87+
* Search full time jobs.
88+
*
89+
* @param query
90+
* the query
91+
* @param location
92+
* the location
93+
*
94+
* @return the list< job>
95+
*/
96+
public List<Job> searchFullTimeJobs(String query, GeoLocation location);
97+
98+
/**
99+
* Gets the job.
100+
*
101+
* @param id
102+
* the id
103+
*
104+
* @return the job
105+
*/
106+
public Job getJob(String id);
107+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ public static interface PullRequestApiUrls {
379379
public static final String GET_PULL_REQUEST_URL = gitHubApiUrls.getProperty("com.github.api.v2.services.pullRequestService.getPullRequest");
380380
}
381381

382+
/**
383+
* The Interface JobApiUrls.
384+
*/
385+
public static interface JobApiUrls {
386+
387+
/** The Constant SEARCH_JOBS_URL. */
388+
public static final String SEARCH_JOBS_URL = gitHubApiUrls.getProperty("com.github.api.v2.services.jobService.searchJobs");
389+
390+
/** The Constant GET_JOB_URL. */
391+
public static final String GET_JOB_URL = gitHubApiUrls.getProperty("com.github.api.v2.services.jobService.getJob");
392+
}
382393

383394
/**
384395
* The Interface FeedUrls.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,16 @@ public interface ParameterNames {
185185

186186
/** The Constant PAGE. */
187187
public static final String PAGE = "page";
188+
189+
/** The Constant SEARCH. */
190+
public static final String SEARCH = "search";
191+
192+
/** The Constant LATITUDE. */
193+
public static final String LATITUDE = "lat";
194+
195+
/** The Constant LONGITUDE. */
196+
public static final String LONGITUDE = "long";
197+
198+
/** The Constant FULL_TIME. */
199+
public static final String FULL_TIME = "full_time";
188200
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.github.api.v2.schema.Gist;
3131
import com.github.api.v2.schema.IntegerPayloadPullRequest;
3232
import com.github.api.v2.schema.Issue;
33+
import com.github.api.v2.schema.Job;
3334
import com.github.api.v2.schema.Language;
3435
import com.github.api.v2.schema.ObjectPayloadPullRequest;
3536
import com.github.api.v2.schema.ObjectPayloadTarget;
@@ -68,14 +69,16 @@ public abstract class BaseGitHubService extends GitHubApiGateway implements GitH
6869
protected static final Charset UTF_8_CHAR_SET = Charset.forName(ApplicationConstants.CONTENT_ENCODING);
6970

7071
/** The parser. */
71-
private final JsonParser parser = new JsonParser();
72+
protected final JsonParser parser = new JsonParser();
7273

7374
/** The handlers. */
7475
private List<AsyncResponseHandler<List<? extends SchemaEntity>>> handlers = new ArrayList<AsyncResponseHandler<List<? extends SchemaEntity>>>();
7576

7677
private static final SimpleDateFormat sdf = new SimpleDateFormat(ApplicationConstants.DATE_FORMAT);
7778

7879
private static final SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
80+
81+
private static final SimpleDateFormat sdf3 = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'UTC' yyyy");//not sure why it fails in android when using EEE MMM dd HH:mm:ss z yyyy
7982

8083
/**
8184
* Instantiates a new base git hub service.
@@ -161,7 +164,12 @@ public Date deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext
161164
return sdf2.parse(arg0.getAsJsonPrimitive().getAsString());
162165
}
163166
catch (ParseException e1) {
164-
return null;
167+
try {
168+
return sdf3.parse(arg0.getAsJsonPrimitive().getAsString());
169+
}
170+
catch (ParseException e2) {
171+
return null;
172+
}
165173
}
166174
}
167175
}
@@ -234,6 +242,13 @@ public UserFeed.Type deserialize(JsonElement arg0, Type arg1,
234242
return UserFeed.Type.fromValue(arg0.getAsString());
235243
}
236244
});
245+
builder.registerTypeAdapter(Job.Type.class, new JsonDeserializer<Job.Type>() {
246+
@Override
247+
public Job.Type deserialize(JsonElement arg0, Type arg1,
248+
JsonDeserializationContext arg2) throws JsonParseException {
249+
return Job.Type.fromValue(arg0.getAsString());
250+
}
251+
});
237252
return builder;
238253
}
239254

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright 2010 Nabeel Mukhtar
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.github.api.v2.services.impl;
18+
19+
import java.io.InputStream;
20+
import java.io.InputStreamReader;
21+
import java.util.List;
22+
23+
import com.github.api.v2.schema.GeoLocation;
24+
import com.github.api.v2.schema.Job;
25+
import com.github.api.v2.services.GitHubException;
26+
import com.github.api.v2.services.JobService;
27+
import com.github.api.v2.services.constant.GitHubApiUrls;
28+
import com.github.api.v2.services.constant.ParameterNames;
29+
import com.github.api.v2.services.constant.GitHubApiUrls.GitHubApiUrlBuilder;
30+
import com.google.mygson.gh4a.GsonBuilder;
31+
import com.google.mygson.gh4a.JsonElement;
32+
import com.google.mygson.gh4a.JsonObject;
33+
import com.google.mygson.gh4a.reflect.TypeToken;
34+
35+
/**
36+
* The Class JobServiceImpl.
37+
*/
38+
public class JobServiceImpl extends BaseGitHubService implements JobService {
39+
40+
/* (non-Javadoc)
41+
* @see com.github.api.v2.services.JobService#getJob(java.lang.String)
42+
*/
43+
@Override
44+
public Job getJob(String id) {
45+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.GET_JOB_URL);
46+
String apiUrl = builder.withField(ParameterNames.ID, id).buildUrl();
47+
JsonObject json = unmarshall(callApiGet(apiUrl));
48+
return unmarshall(new TypeToken<Job>(){}, json);
49+
}
50+
51+
/* (non-Javadoc)
52+
* @see com.github.api.v2.services.JobService#searchFullTimeJobs(java.lang.String)
53+
*/
54+
@Override
55+
public List<Job> searchFullTimeJobs(String query) {
56+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
57+
String apiUrl = builder.withParameter(ParameterNames.SEARCH, query).withParameter(ParameterNames.FULL_TIME, "true").buildUrl();
58+
JsonElement json = unmarshallList(callApiGet(apiUrl));
59+
return unmarshall(new TypeToken<List<Job>>(){}, json);
60+
}
61+
62+
/* (non-Javadoc)
63+
* @see com.github.api.v2.services.JobService#searchFullTimeJobs(java.lang.String, java.lang.String)
64+
*/
65+
@Override
66+
public List<Job> searchFullTimeJobs(String query, String location) {
67+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
68+
String apiUrl = builder.withParameter(ParameterNames.FULL_TIME, "true").withParameter(ParameterNames.SEARCH, query).withParameter(ParameterNames.LOCATION, location).buildUrl();
69+
JsonElement json = unmarshallList(callApiGet(apiUrl));
70+
return unmarshall(new TypeToken<List<Job>>(){}, json);
71+
}
72+
73+
/* (non-Javadoc)
74+
* @see com.github.api.v2.services.JobService#searchFullTimeJobs(java.lang.String, com.github.api.v2.schema.GeoLocation)
75+
*/
76+
@Override
77+
public List<Job> searchFullTimeJobs(String query, GeoLocation location) {
78+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
79+
String apiUrl = builder.withParameter(ParameterNames.FULL_TIME, "true").withParameter(ParameterNames.SEARCH, query).withParameter(ParameterNames.LATITUDE, String.valueOf(location.getLatitude())).withParameter(ParameterNames.LONGITUDE, String.valueOf(location.getLongitude())).buildUrl();
80+
JsonElement json = unmarshallList(callApiGet(apiUrl));
81+
return unmarshall(new TypeToken<List<Job>>(){}, json);
82+
}
83+
84+
/* (non-Javadoc)
85+
* @see com.github.api.v2.services.JobService#searchJobs(java.lang.String)
86+
*/
87+
@Override
88+
public List<Job> searchJobs(String query) {
89+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
90+
String apiUrl = builder.withParameter(ParameterNames.SEARCH, query).buildUrl();
91+
JsonElement json = unmarshallList(callApiGet(apiUrl));
92+
return unmarshall(new TypeToken<List<Job>>(){}, json);
93+
}
94+
95+
/* (non-Javadoc)
96+
* @see com.github.api.v2.services.JobService#searchJobs(java.lang.String, java.lang.String)
97+
*/
98+
@Override
99+
public List<Job> searchJobs(String query, String location) {
100+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
101+
String apiUrl = builder.withParameter(ParameterNames.SEARCH, query).withParameter(ParameterNames.LOCATION, location).buildUrl();
102+
JsonElement json = unmarshallList(callApiGet(apiUrl));
103+
return unmarshall(new TypeToken<List<Job>>(){}, json);
104+
}
105+
106+
/* (non-Javadoc)
107+
* @see com.github.api.v2.services.JobService#searchJobs(java.lang.String, com.github.api.v2.schema.GeoLocation)
108+
*/
109+
@Override
110+
public List<Job> searchJobs(String query, GeoLocation location) {
111+
GitHubApiUrlBuilder builder = createGitHubApiUrlBuilder(GitHubApiUrls.JobApiUrls.SEARCH_JOBS_URL);
112+
String apiUrl = builder.withParameter(ParameterNames.SEARCH, query).withParameter(ParameterNames.LATITUDE, String.valueOf(location.getLatitude())).withParameter(ParameterNames.LONGITUDE, String.valueOf(location.getLongitude())).buildUrl();
113+
JsonElement json = unmarshallList(callApiGet(apiUrl));
114+
return unmarshall(new TypeToken<List<Job>>(){}, json);
115+
}
116+
117+
/**
118+
* Unmarshall list.
119+
*
120+
* @param jsonContent
121+
* the json content
122+
*
123+
* @return the json element
124+
*/
125+
protected JsonElement unmarshallList(InputStream jsonContent) {
126+
try {
127+
return parser.parse(new InputStreamReader(jsonContent, UTF_8_CHAR_SET));
128+
} catch (Exception e) {
129+
throw new GitHubException(e);
130+
} finally {
131+
closeStream(jsonContent);
132+
}
133+
}
134+
135+
/* (non-Javadoc)
136+
* @see com.github.api.v2.services.impl.BaseGitHubService#getGsonBuilder()
137+
*/
138+
@Override
139+
protected GsonBuilder getGsonBuilder() {
140+
GsonBuilder gson = super.getGsonBuilder();
141+
gson.setDateFormat("EEE MMM d HH:mm:ss z yyyy");
142+
return gson;
143+
}
144+
145+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ com.github.api.v2.services.pullRequestService.createPullRequest=http://github.co
113113
com.github.api.v2.services.pullRequestService.getPullRequest=http://github.com/api/{version}/{format}/pulls/{userName}/{repositoryName}/{issueNumber}
114114
com.github.api.v2.services.pullRequestService.getPullRequests=http://github.com/api/{version}/{format}/pulls/{userName}/{repositoryName}/{state}
115115

116+
# Job API
117+
com.github.api.v2.services.jobService.searchJobs=http://jobs.github.com/positions.{format}?{search}{location}{lat}{long}{full_time}
118+
com.github.api.v2.services.jobService.getJob=http://jobs.github.com/positions/{id}.{format}
119+
116120
# Feed
117121
com.github.api.v2.services.feedService.getPublicUserFeed=http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&{num}&q=http%3A%2F%2Fgithub.com%2F{userName}.atom&key=ABQIAAAAvQycN2a0eBLRB8DGrLfzQRTQV5l3ALoWoSA9wfMrLZSV0Qnu4RQ6x1TgR7d8ayIoK_hqJWsqLImnDg
118122
com.github.api.v2.services.feedService.getPublicUserFeedJson=https://github.com/{userName}.json

core/src/test/java/com/github/api/v2/services/AllTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static Test suite() {
4343
suite.addTestSuite(OAuthServiceTest.class);
4444
suite.addTestSuite(ObjectServiceTest.class);
4545
suite.addTestSuite(UserServiceTest.class);
46+
suite.addTestSuite(JobServiceTest.class);
4647
//$JUnit-END$
4748
return suite;
4849
}

0 commit comments

Comments
 (0)