Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit bee44ea

Browse files
committed
api samples: Updates to style, using getDefaultInstance
https://codereview.appspot.com/13143043/
1 parent 3072dfd commit bee44ea

File tree

25 files changed

+154
-154
lines changed
  • adexchangebuyer-cmdline-sample/src/main/java/com/google/api/services/samples/adexchangebuyer/cmdline
  • adsense-cmdline-sample/src/main/java/com/google/api/services/samples/adsense/cmdline
  • adsensehost-cmdline-sample/src/main/java/com/google/api/services/samples/adsensehost/cmdline
  • analytics-cmdline-sample/src/main/java/com/google/api/services/samples/analytics/cmdline
  • bigquery-appengine-sample/src/main/java/com/google/api/client/sample/bigquery/appengine/dashboard
  • books-cmdline-sample/src/main/java/com/google/api/services/samples/books/cmdline
  • calendar-android-sample/src/main/java/com/google/api/services/samples/calendar/android
  • calendar-appengine-sample/src/main/java/com/google/api/services/samples/calendar/appengine/server
  • calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline
  • compute-engine-cmdline-sample/src/main/java/com/google/api/services/samples/computeengine/cmdline
  • dfareporting-cmdline-sample/src/main/java/com/google/api/services/samples/dfareporting/cmdline
  • discovery-cmdline-sample/src/main/java/com/google/api/services/samples/discovery/cmdline
  • drive-cmdline-sample/src/main/java/com/google/api/services/samples/drive/cmdline
  • fusiontables-cmdline-sample/src/main/java/com/google/api/services/samples/fusiontables/cmdline
  • oauth2-cmdline-sample/src/main/java/com/google/api/services/samples/oauth2/cmdline
  • picasa-cmdline-sample/src/main/java/com/google/api/services/samples/picasa/cmdline
  • plus-appengine-sample/src/main/java/com/google/api/services/samples/plus
  • plus-cmdline-sample/src/main/java/com/google/api/services/samples/plus/cmdline
  • plus-serviceaccount-cmdline-sample/src/main/java/com/google/api/services/samples/plus/serviceaccount/cmdline
  • prediction-cmdline-sample/src/main/java/com/google/api/services/samples/prediction/cmdline
  • siteVerification-cmdline-sample/src/main/java/com/google/api/services/samples/verification/cmdline
  • storage-cmdline-sample/src/main/java/com/google/api/services/samples/storage/cmdline
  • storage-serviceaccount-cmdline-sample/src/main/java/com/google/api/services/samples/storage/serviceaccount/cmdline
  • taskqueue-cmdline-sample/src/main/java/com/google/api/services/samples/taskqueue/cmdline
  • tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android

25 files changed

+154
-154
lines changed

adexchangebuyer-cmdline-sample/src/main/java/com/google/api/services/samples/adexchangebuyer/cmdline/AdExchangeBuyerSample.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public class AdExchangeBuyerSample {
6060
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
6161
* globally shared instance across your application.
6262
*/
63-
private static FileDataStoreFactory DATA_STORE_FACTORY;
63+
private static FileDataStoreFactory dataStoreFactory;
6464

6565
/** Global instance of the HTTP transport. */
66-
private static HttpTransport HTTP_TRANSPORT;
66+
private static HttpTransport httpTransport;
6767

6868
/** Global instance of the JSON factory. */
69-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
69+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
7070

7171
private static ArrayList<BaseSample> samples;
7272

@@ -85,9 +85,9 @@ JSON_FACTORY, new InputStreamReader(
8585
}
8686
// set up authorization code flow
8787
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
88-
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
88+
httpTransport, JSON_FACTORY, clientSecrets,
8989
Collections.singleton(AdexchangebuyerScopes.ADEXCHANGE_BUYER)).setDataStoreFactory(
90-
DATA_STORE_FACTORY).build();
90+
dataStoreFactory).build();
9191
// authorize
9292
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
9393
}
@@ -104,7 +104,7 @@ private static Adexchangebuyer initClient() throws Exception {
104104

105105
// Set up API client.
106106
Adexchangebuyer client = new Adexchangebuyer.Builder(
107-
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
107+
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
108108

109109
return client;
110110
}
@@ -128,8 +128,8 @@ private static void initSamples() {
128128
* @throws Exception
129129
*/
130130
public static void main(String[] args) throws Exception {
131-
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
132-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
131+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
132+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
133133
initSamples();
134134
Adexchangebuyer client = initClient();
135135
BaseSample sample = null;

adsense-cmdline-sample/src/main/java/com/google/api/services/samples/adsense/cmdline/AdSenseSample.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public class AdSenseSample {
7777
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
7878
* globally shared instance across your application.
7979
*/
80-
private static FileDataStoreFactory DATA_STORE_FACTORY;
80+
private static FileDataStoreFactory dataStoreFactory;
8181

8282
/** Global instance of the JSON factory. */
83-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
83+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
8484

8585
// Request parameters.
8686
private static final int MAX_LIST_PAGE_SIZE = 50;
@@ -105,7 +105,7 @@ private static Credential authorize() throws Exception {
105105
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
106106
httpTransport, JSON_FACTORY, clientSecrets,
107107
Collections.singleton(AdSenseScopes.ADSENSE_READONLY)).setDataStoreFactory(
108-
DATA_STORE_FACTORY).build();
108+
dataStoreFactory).build();
109109
// authorize
110110
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
111111
}
@@ -136,7 +136,7 @@ private static AdSense initializeAdsense() throws Exception {
136136
public static void main(String[] args) {
137137
try {
138138
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
139-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
139+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
140140
AdSense adsense = initializeAdsense();
141141

142142
Accounts accounts = GetAllAccounts.run(adsense, MAX_LIST_PAGE_SIZE);

adsensehost-cmdline-sample/src/main/java/com/google/api/services/samples/adsensehost/cmdline/AdSenseHostSample.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ public class AdSenseHostSample {
8585
private static FileDataStoreFactory DATA_STORE_FACTORY;
8686

8787
// Global instance of the HTTP transport.
88-
private static HttpTransport HTTP_TRANSPORT;
88+
private static HttpTransport httpTransport;
8989

9090
// Global instance of the JSON factory.
91-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
91+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
9292

9393
// Maximum page size for list calls.
9494
private static final long MAX_LIST_PAGE_SIZE = 50;
@@ -110,7 +110,7 @@ private static Credential authorize() throws Exception {
110110
}
111111
// set up authorization code flow
112112
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
113-
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
113+
httpTransport, JSON_FACTORY, clientSecrets,
114114
Collections.singleton(AdSenseHostScopes.ADSENSEHOST)).setDataStoreFactory(
115115
DATA_STORE_FACTORY).build();
116116
// authorize
@@ -149,7 +149,7 @@ public static String getUniqueName() {
149149
*/
150150
public static void main(String[] args) {
151151
try {
152-
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
152+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
153153
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
154154
AdSenseHost service = initializeAdsensehost();
155155

analytics-cmdline-sample/src/main/java/com/google/api/services/samples/analytics/cmdline/HelloAnalyticsApiSample.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public class HelloAnalyticsApiSample {
6565
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
6666
* globally shared instance across your application.
6767
*/
68-
private static FileDataStoreFactory DATA_STORE_FACTORY;
68+
private static FileDataStoreFactory dataStoreFactory;
6969

7070
/** Global instance of the HTTP transport. */
71-
private static HttpTransport HTTP_TRANSPORT;
71+
private static HttpTransport httpTransport;
7272

7373
/** Global instance of the JSON factory. */
74-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
74+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
7575

7676
/**
7777
* Main demo. This first initializes an analytics service object. It then uses the Google
@@ -83,8 +83,8 @@ public class HelloAnalyticsApiSample {
8383
*/
8484
public static void main(String[] args) {
8585
try {
86-
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
87-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
86+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
87+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
8888
Analytics analytics = initializeAnalytics();
8989
String profileId = getFirstProfileId(analytics);
9090
if (profileId == null) {
@@ -116,9 +116,9 @@ JSON_FACTORY, new InputStreamReader(
116116
}
117117
// set up authorization code flow
118118
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
119-
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
119+
httpTransport, JSON_FACTORY, clientSecrets,
120120
Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)).setDataStoreFactory(
121-
DATA_STORE_FACTORY).build();
121+
dataStoreFactory).build();
122122
// authorize
123123
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
124124
}
@@ -135,7 +135,7 @@ private static Analytics initializeAnalytics() throws Exception {
135135
Credential credential = authorize();
136136

137137
// Set up and return Google Analytics API client.
138-
return new Analytics.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(
138+
return new Analytics.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(
139139
APPLICATION_NAME).build();
140140
}
141141

bigquery-appengine-sample/src/main/java/com/google/api/client/sample/bigquery/appengine/dashboard/ServiceUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ class ServiceUtils {
4646
static final HttpTransport HTTP_TRANSPORT = new UrlFetchTransport();
4747

4848
/** Global instance of the JSON factory. */
49-
static final JsonFactory JSON_FACTORY = new JacksonFactory();
49+
static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
5050

5151
/**
5252
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
5353
* globally shared instance across your application.
5454
*/
5555
private static final AppEngineDataStoreFactory DATA_STORE_FACTORY =
56-
new AppEngineDataStoreFactory();
56+
AppEngineDataStoreFactory.getDefaultInstance();
5757

5858
private static GoogleClientSecrets clientSecrets = null;
5959

@@ -86,7 +86,7 @@ static void deleteCredentials(String userId) throws IOException {
8686
static GoogleAuthorizationCodeFlow newFlow() throws IOException {
8787
return new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
8888
getClientCredential(), Collections.singleton(BigqueryScopes.BIGQUERY)).setDataStoreFactory(
89-
DATA_STORE_FACTORY).setAccessType("offline").build();
89+
DATA_STORE_FACTORY).setAccessType("offline").build();
9090
}
9191

9292
static Bigquery loadBigqueryClient(String userId) throws IOException {

books-cmdline-sample/src/main/java/com/google/api/services/samples/books/cmdline/BooksSample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private static void queryGoogleBooks(JsonFactory jsonFactory, String query) thro
134134
}
135135

136136
public static void main(String[] args) {
137-
JsonFactory jsonFactory = new JacksonFactory();
137+
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
138138
try {
139139
// Verify command line parameters.
140140
if (args.length == 0) {

calendar-android-sample/src/main/java/com/google/api/services/samples/calendar/android/CalendarSampleActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public final class CalendarSampleActivity extends Activity {
9999

100100
final HttpTransport transport = AndroidHttp.newCompatibleTransport();
101101

102-
final JsonFactory jsonFactory = new GsonFactory();
102+
final JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
103103

104104
GoogleAccountCredential credential;
105105

calendar-appengine-sample/src/main/java/com/google/api/services/samples/calendar/appengine/server/Utils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class Utils {
4747
* globally shared instance across your application.
4848
*/
4949
private static final AppEngineDataStoreFactory DATA_STORE_FACTORY =
50-
new AppEngineDataStoreFactory();
50+
AppEngineDataStoreFactory.getDefaultInstance();
5151

5252
/** Global instance of the HTTP transport. */
5353
static final HttpTransport HTTP_TRANSPORT = new UrlFetchTransport();
5454

5555
/** Global instance of the JSON factory. */
56-
static final JsonFactory JSON_FACTORY = new JacksonFactory();
56+
static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
5757

5858
private static GoogleClientSecrets clientSecrets = null;
5959

calendar-cmdline-sample/src/main/java/com/google/api/services/samples/calendar/cmdline/CalendarSample.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public class CalendarSample {
6363
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
6464
* globally shared instance across your application.
6565
*/
66-
private static FileDataStoreFactory DATA_STORE_FACTORY;
66+
private static FileDataStoreFactory dataStoreFactory;
6767

6868
/** Global instance of the HTTP transport. */
69-
private static HttpTransport HTTP_TRANSPORT;
69+
private static HttpTransport httpTransport;
7070

7171
/** Global instance of the JSON factory. */
72-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
72+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
7373

7474
private static com.google.api.services.calendar.Calendar client;
7575

@@ -89,8 +89,8 @@ private static Credential authorize() throws Exception {
8989
}
9090
// set up authorization code flow
9191
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
92-
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,
93-
Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(DATA_STORE_FACTORY)
92+
httpTransport, JSON_FACTORY, clientSecrets,
93+
Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
9494
.build();
9595
// authorize
9696
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
@@ -99,17 +99,17 @@ private static Credential authorize() throws Exception {
9999
public static void main(String[] args) {
100100
try {
101101
// initialize the transport
102-
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
102+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
103103

104104
// initialize the data store factory
105-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
105+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
106106

107107
// authorization
108108
Credential credential = authorize();
109109

110110
// set up global Calendar instance
111111
client = new com.google.api.services.calendar.Calendar.Builder(
112-
HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
112+
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
113113

114114
// run commands
115115
showCalendars();

compute-engine-cmdline-sample/src/main/java/com/google/api/services/samples/computeengine/cmdline/ComputeEngineSample.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,28 @@ public class ComputeEngineSample {
6161
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
6262
* globally shared instance across your application.
6363
*/
64-
private static FileDataStoreFactory DATA_STORE_FACTORY;
64+
private static FileDataStoreFactory dataStoreFactory;
6565

6666
/** Global instance of the HTTP transport. */
67-
private static HttpTransport HTTP_TRANSPORT;
67+
private static HttpTransport httpTransport;
6868

6969
/** Global instance of the JSON factory. */
70-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
70+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
7171

7272
/** OAuth 2.0 scopes */
7373
private static final List<String> SCOPES = Arrays.asList(ComputeScopes.COMPUTE_READONLY);
7474

7575
public static void main(String[] args) {
7676
// Start Authorization process
7777
try {
78-
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
79-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
78+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
79+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
8080
// Authorization
8181
Credential credential = authorize();
8282

8383
// Create compute engine object for listing instances
8484
Compute compute = new Compute.Builder(
85-
HTTP_TRANSPORT, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME)
85+
httpTransport, JSON_FACTORY, null).setApplicationName(APPLICATION_NAME)
8686
.setHttpRequestInitializer(credential).build();
8787

8888
// List out instances
@@ -112,7 +112,7 @@ private static Credential authorize() throws Exception {
112112
}
113113
// set up authorization code flow
114114
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
115-
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY)
115+
httpTransport, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(dataStoreFactory)
116116
.build();
117117
// authorize
118118
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");

dfareporting-cmdline-sample/src/main/java/com/google/api/services/samples/dfareporting/cmdline/DfaReportingSample.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ public class DfaReportingSample {
6565
* Global instance of the {@link DataStoreFactory}. The best practice is to make it a single
6666
* globally shared instance across your application.
6767
*/
68-
private static FileDataStoreFactory DATA_STORE_FACTORY;
68+
private static FileDataStoreFactory dataStoreFactory;
6969

7070
private static final List<String> SCOPES = ImmutableList.of(
7171
"https://www.googleapis.com/auth/dfareporting");
7272

73-
private static HttpTransport TRANSPORT;
74-
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
73+
private static HttpTransport httpTransport;
74+
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
7575
private static final DateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
7676
private static final int MAX_LIST_PAGE_SIZE = 50;
7777
private static final int MAX_REPORT_PAGE_SIZE = 10;
@@ -91,8 +91,8 @@ JSON_FACTORY, new InputStreamReader(
9191
}
9292
// set up authorization code flow
9393
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
94-
TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(
95-
DATA_STORE_FACTORY).build();
94+
httpTransport, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(
95+
dataStoreFactory).build();
9696
// authorize
9797
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
9898
}
@@ -107,7 +107,7 @@ private static Dfareporting initializeDfareporting() throws Exception {
107107
Credential credential = authorize();
108108

109109
// Create DFA Reporting client.
110-
return new Dfareporting(TRANSPORT, JSON_FACTORY, credential);
110+
return new Dfareporting(httpTransport, JSON_FACTORY, credential);
111111
}
112112

113113
/**
@@ -127,8 +127,8 @@ public static void main(String[] args) {
127127
String endDate = DATE_FORMATTER.format(today);
128128

129129
try {
130-
TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
131-
DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);
130+
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
131+
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
132132
Dfareporting reporting = initializeDfareporting();
133133

134134
UserProfileList userProfiles = GetAllUserProfiles.list(reporting);

0 commit comments

Comments
 (0)