Skip to content

Commit 5a497c4

Browse files
committed
2 parents 957e89a + 6929ae8 commit 5a497c4

File tree

1 file changed

+74
-7
lines changed

1 file changed

+74
-7
lines changed

README.md

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
This repo is still in earlier stage of development, but all completed parts already tested with real world applications.
1111

1212
## Documentation
13-
Prepairing.
13+
Please look at examples.
1414

1515

1616
## Contributing
@@ -22,22 +22,89 @@ Welcome to all contributors!
2222
Nothing special with this package.
2323
### Step 1: Inject HttpClientFactory
2424

25+
Add Services into program.cs
26+
```cs
27+
builder.Services.AddCodeBeamGoogleApiServices();
28+
```
29+
2530
For blazor component files
2631
```razor
27-
@inject IHttpClientFactory HttpClientFactory
32+
@inject CalendarService CalendarService
2833
```
2934
For cs files
3035
```cs
31-
[Inject] IHttpClientFactory HttpClientFactory { get; set; }
36+
[Inject] CalendarService CalendarService { get; set; }
3237
```
3338

34-
### Step 2: Create an instance of needed api class and implement
39+
### Step 2: Implement whatever you want
3540
```cs
36-
private void NewCalendar()
41+
private void CreateCalendar()
3742
{
38-
CalendarService calendarService = new CalendarService(HttpClientFactory);
39-
calendarService.AddCalendar(_accessToken, "Calendar Title"); //Can get access token with AuthService.
43+
GoogleCalendarListModel googleCalendarListModel = new GoogleCalendarListModel()
44+
{
45+
summary = "Test Calendar",
46+
description = "Created By CodeBeam",
47+
timeZone = "Europe/Istanbul",
48+
};
49+
CalendarService.AddCalendar(googleCalendarListModel);
4050
}
4151
```
4252

4353
### Step 3: null. That's all.
54+
55+
# Examples
56+
## How To Use Auth Service To Get Permission From a Google Account
57+
#### Step 1. Request Authorization Code
58+
```cs
59+
private async Task RequestCode()
60+
{
61+
List<Scope> scopes = new();
62+
scopes.Add(Scope.OAuth2Email); //Not required, but useful for get user email in future.
63+
scopes.Add(Scope.Calendar);
64+
await AuthService.RequestAuthorizationCode(AuthService.GetClientId(), scopes, NavigationManager.BaseUri + "v1/browser-callback"); //"v1/browser-callback" is your page that method returns and opens the page as a new tab
65+
}
66+
```
67+
#### Step 2. Get Access Token With Obtained Authorization Code in Step 1
68+
These codes should be in the callback page.
69+
Blazor Component
70+
```razor
71+
@page "/v1/browser-callback"
72+
```
73+
Code
74+
```cs
75+
[Parameter]
76+
[SupplyParameterFromQuery]
77+
public string Code { get; set; }
78+
79+
string _accessToken = "";
80+
protected override async Task OnAfterRenderAsync(bool firstRender)
81+
{
82+
if (firstRender)
83+
{
84+
var request = AuthService.AuthorizeCredential(Code, AuthService.GetCliendId(), AuthService.GetClientSecret(), NavigationManager.BaseUri + "v1/browser-callback");
85+
// This method is built in this package. You also can write your own method to process request result.
86+
_accessToken = AuthService.GetValueFromCredential(request, CredentialValueType.AccessToken);
87+
}
88+
}
89+
```
90+
91+
#### Step 3. You can store this access token (can also obtain refresh token etc. with same way) in your database or make a cookie. You can use this token to call calendar, drive etc. features.
92+
93+
94+
## How To Create a Calendar Event
95+
#### Make an instance of GoogleCalendarEventModel and add it. Notice that for datetimes like event start and end, need to use GetProperDateTimeFormat method.
96+
```cs
97+
[Inject] CalendarService CalendarService { get; set; }
98+
private void AddEvent()
99+
{
100+
GoogleCalendarEventModel googleCalendarEvent = new()
101+
{
102+
summary = "Test Event",
103+
description = "Some Description",
104+
start = new Start { dateTime = CalendarService.GetProperDateTimeFormat(DateTime.Now) },
105+
end = new End { dateTime = CalendarService.GetProperDateTimeFormat(DateTime.Now) },
106+
};
107+
// If you don't know the id of calendar which will the event be added, use FindCalendarId method. In this case, the event added the calendar which has "Test Calendar" title.
108+
string result = CalendarService.AddEvent(googleCalendarEvent, CalendarService.FindCalendarId(CalendarValueType.Summary, "Test Calendar"));
109+
}
110+
```

0 commit comments

Comments
 (0)