Skip to content

Commit ec2f771

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #6 from davidmoten/builder-method
Builder method and README updates
2 parents 028ed38 + 32adfde commit ec2f771

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,49 +43,49 @@ Register your application by following [these](https://developer.microsoft.com/e
4343
### 2.2 Create an IAuthenticationProvider object
4444

4545
An instance of the **GraphServiceClient** class handles building requests,
46-
sending them to Microsoft Graph API, and processing the responses. To create a
46+
sending them to the Microsoft Graph API, and processing the responses. To create a
4747
new instance of this class, you need to provide an instance of
4848
`IAuthenticationProvider` which can authenticate requests to Microsoft Graph.
4949

5050
For an example of authentication in a client application see the [MSGraph SDK Android MSA Auth for Android Adapter](https://github.com/microsoftgraph/msgraph-sdk-android-msa-auth-for-android-adapter).
5151

5252
### 2.3 Get a GraphServiceClient object
5353

54+
TODO: the para below needs expansion or removal. Would need to mention the different flows (authorization code flow, implicit flow, client credential flow) and give pointers on where to get sample code. Dave Moten can provide link for client credentials flow.
55+
5456
Once you have set the correct application ID and url, you must get a **GraphServiceClient** object to make requests against the service. The SDK will store the account information for you, but when a user logs on for the first time, it will invoke UI to get the user's account information.
5557

5658
```java
57-
final IClientConfig mCLientConfig = DefaultClientConfig
58-
.createWithAuthenticationProvider(mAuthenticationProvider);
59+
IClientConfig clientConfig =
60+
DefaultClientConfig.createWithAuthenticationProvider(mAuthenticationProvider);
5961

60-
final IGraphServiceClient mClient = new GraphServiceClient
61-
.Builder()
62-
.fromConfig(mClientConfig)
63-
.buildClient();
62+
IGraphServiceClient graphClient =
63+
GraphServiceClient.builder()
64+
.fromConfig(mClientConfig)
65+
.buildClient();
6466
```
6567

6668
## 3. Make requests against the service
6769

68-
Once you have an GraphServiceClient that is authenticated you can begin making calls against the service. The requests against the service look like our [REST API](https://developer.microsoft.com/en-us/graph/docs/concepts/overview).
70+
Once you have a GraphServiceClient that is authenticated you can begin making calls against the service. The requests against the service look like our [REST API](https://developer.microsoft.com/en-us/graph/docs/concepts/overview).
6971

70-
### Get the drive
72+
### Get the user's drive
7173

72-
To retrieve a user's drive:
74+
To retrieve the user's drive:
7375

7476
```java
7577
graphClient
76-
.me()
77-
.drive()
78-
.buildRequest()
79-
.get(new ICallback<Drive>() {
80-
@Override
81-
public void success(final Drive result) {
82-
final String msg = "Found Drive " + result.id;
83-
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT)
84-
.show();
85-
}
86-
...
87-
// Handle failure case
88-
});
78+
.me()
79+
.drive()
80+
.buildRequest()
81+
.get(new ICallback<Drive>() {
82+
@Override
83+
public void success(final Drive result) {
84+
System.out.println("Found Drive " + result.id);
85+
}
86+
...
87+
// Handle failure case
88+
});
8989
```
9090

9191
For a general overview of how the SDK is designed, see [overview](docs/overview.md).

src/main/java/com/microsoft/graph/models/extensions/GraphServiceClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ public CustomRequestBuilder customRequest(final String url, final Class response
5252
public CustomRequestBuilder customRequest(final String url) {
5353
return new CustomRequestBuilder(url, (IGraphServiceClient)this, null, JsonObject.class);
5454
}
55+
56+
public static Builder builder() {
57+
return new Builder();
58+
}
5559

5660
/**
5761
* The builder for this GraphServiceClient
5862
*/
5963
public static class Builder {
64+
65+
Builder() {
66+
// ensure instantiation only from static factory method
67+
}
6068

6169
/**
6270
* The client under construction

src/test/java/com/microsoft/graph/functional/TestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void authenticateRequest(final IHttpRequest request) {
5252
};
5353
IClientConfig mClientConfig = DefaultClientConfig.createWithAuthenticationProvider(mAuthenticationProvider);
5454

55-
graphClient = new GraphServiceClient.Builder().fromConfig(mClientConfig).buildClient();
55+
graphClient = GraphServiceClient.builder().fromConfig(mClientConfig).buildClient();
5656
}
5757
catch (Exception e)
5858
{

0 commit comments

Comments
 (0)