Skip to content

Commit 7a54fcd

Browse files
committed
Finished Job API.
1 parent fae3fc2 commit 7a54fcd

File tree

15 files changed

+855
-4
lines changed

15 files changed

+855
-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/gson-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
@@ -376,6 +376,17 @@ public static interface PullRequestApiUrls {
376376
public static final String GET_PULL_REQUEST_URL = gitHubApiUrls.getProperty("com.github.api.v2.services.pullRequestService.getPullRequest");
377377
}
378378

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

380391
/**
381392
* 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
@@ -182,4 +182,16 @@ public interface ParameterNames {
182182

183183
/** The Constant PAGE. */
184184
public static final String PAGE = "page";
185+
186+
/** The Constant SEARCH. */
187+
public static final String SEARCH = "search";
188+
189+
/** The Constant LATITUDE. */
190+
public static final String LATITUDE = "lat";
191+
192+
/** The Constant LONGITUDE. */
193+
public static final String LONGITUDE = "long";
194+
195+
/** The Constant FULL_TIME. */
196+
public static final String FULL_TIME = "full_time";
185197
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.github.api.v2.schema.Discussion;
2727
import com.github.api.v2.schema.Gist;
2828
import com.github.api.v2.schema.Issue;
29+
import com.github.api.v2.schema.Job;
2930
import com.github.api.v2.schema.Language;
3031
import com.github.api.v2.schema.Organization;
3132
import com.github.api.v2.schema.Permission;
@@ -57,7 +58,7 @@ public abstract class BaseGitHubService extends GitHubApiGateway implements GitH
5758
protected static final Charset UTF_8_CHAR_SET = Charset.forName(ApplicationConstants.CONTENT_ENCODING);
5859

5960
/** The parser. */
60-
private final JsonParser parser = new JsonParser();
61+
protected final JsonParser parser = new JsonParser();
6162

6263
/** The handlers. */
6364
private List<AsyncResponseHandler<List<? extends SchemaEntity>>> handlers = new ArrayList<AsyncResponseHandler<List<? extends SchemaEntity>>>();
@@ -186,6 +187,13 @@ public Permission deserialize(JsonElement arg0, Type arg1,
186187
return Permission.fromValue(arg0.getAsString());
187188
}
188189
});
190+
builder.registerTypeAdapter(Job.Type.class, new JsonDeserializer<Job.Type>() {
191+
@Override
192+
public Job.Type deserialize(JsonElement arg0, Type arg1,
193+
JsonDeserializationContext arg2) throws JsonParseException {
194+
return Job.Type.fromValue(arg0.getAsString());
195+
}
196+
});
189197
return builder;
190198
}
191199

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.gson.GsonBuilder;
31+
import com.google.gson.JsonElement;
32+
import com.google.gson.JsonObject;
33+
import com.google.gson.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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ com.github.api.v2.services.userService.removeKey=http://github.com/api/{version}
2323
com.github.api.v2.services.userService.getEmails=http://github.com/api/{version}/{format}/user/emails
2424
com.github.api.v2.services.userService.addEmail=http://github.com/api/{version}/{format}/user/email/add
2525
com.github.api.v2.services.userService.removeEmail=http://github.com/api/{version}/{format}/user/email/remove
26-
com.github.api.v2.services.userService.getUserOrganizations=http://github.com/api/{version}/{format}/user/show/{userName}/organizations
26+
com.github.api.v2.services.userService.getUserOrganizations=http://github.com/api/{version}/{format}/{userName}/organizations
2727

2828
# Issue API
2929
com.github.api.v2.services.issueService.searchIssues=http://github.com/api/{version}/{format}/issues/search/{userName}/{repositoryName}/{state}/{keyword}
@@ -110,6 +110,10 @@ com.github.api.v2.services.pullRequestService.createPullRequest=http://github.co
110110
com.github.api.v2.services.pullRequestService.getPullRequest=http://github.com/api/{version}/{format}/pulls/{userName}/{repositoryName}/{issueNumber}
111111
com.github.api.v2.services.pullRequestService.getPullRequests=http://github.com/api/{version}/{format}/pulls/{userName}/{repositoryName}/{state}
112112

113+
# Job API
114+
com.github.api.v2.services.jobService.searchJobs=http://jobs.github.com/positions.{format}?{search}{location}{lat}{long}{full_time}
115+
com.github.api.v2.services.jobService.getJob=http://jobs.github.com/positions/{id}.{format}
116+
113117
# Feed
114118
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
115119
com.github.api.v2.services.feedService.getPrivateUserFeed=http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&{num}&q=http%3A%2F%2Fgithub.com%2F{userName}.atom&key=ABQIAAAAvQycN2a0eBLRB8DGrLfzQRTQV5l3ALoWoSA9wfMrLZSV0Qnu4RQ6x1TgR7d8ayIoK_hqJWsqLImnDg

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)