-
Notifications
You must be signed in to change notification settings - Fork 355
/
ConnectionsSamplePeople
137 lines (123 loc) · 6.85 KB
/
ConnectionsSamplePeople
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2017 DAIMTO ([Linda Lawton](https://twitter.com/LindaLawtonDK)) : [www.daimto.com](http://www.daimto.com/)
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by DAIMTO-Google-apis-Sample-generator 1.0.0
// Template File Name: methodTemplate.tt
// Build date: 2017-10-08
// C# generater version: 1.0.0
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
// About
//
// Unoffical sample for the Peopleservice v1 API for C#.
// This sample is designed to be used with the Google .Net client library. (https://github.com/google/google-api-dotnet-client)
//
// API Description: Provides access to information about profiles and contacts.
// API Documentation Link https://developers.google.com/people/
//
// Discovery Doc https://www.googleapis.com/discovery/v1/apis/Peopleservice/v1/rest
//
//------------------------------------------------------------------------------
// Installation
//
// This sample code uses the Google .Net client library (https://github.com/google/google-api-dotnet-client)
//
// NuGet package:
//
// Location: https://www.nuget.org/packages/Google.Apis.Peopleservice.v1/
// Install Command: PM> Install-Package Google.Apis.Peopleservice.v1
//
//------------------------------------------------------------------------------
using Google.Apis.Peopleservice.v1;
using Google.Apis.Peopleservice.v1.Data;
using System;
namespace GoogleSamplecSharpSample.Peopleservicev1.Methods
{
public static class ConnectionsSample
{
public class ConnectionsListOptionalParms
{
/// **Required.** A field mask to restrict which fields on each person arereturned. Valid values are:* addresses* ageRanges* biographies* birthdays* braggingRights* coverPhotos* emailAddresses* events* genders* imClients* interests* locales* memberships* metadata* names* nicknames* occupations* organizations* phoneNumbers* photos* relations* relationshipInterests* relationshipStatuses* residences* skills* taglines* urls
public string PersonFields { get; set; }
/// The order in which the connections should be sorted. Defaults to`LAST_MODIFIED_ASCENDING`.
public string SortOrder { get; set; }
/// Whether the response should include a sync token, which can be used to getall changes since the last request.
public bool? RequestSyncToken { get; set; }
/// The token of the page to be returned.
public string PageToken { get; set; }
/// The number of connections to include in the response. Valid values arebetween 1 and 2000, inclusive. Defaults to 100.
public int? PageSize { get; set; }
/// **Required.** Comma-separated list of person fields to be included in theresponse. Each path should start with `person.`: for example,`person.names` or `person.photos`.
public string RequestMask.includeField { get; set; }
/// A sync token, returned by a previous call to `people.connections.list`.Only resources changed since the sync token was created will be returned.
public string SyncToken { get; set; }
}
/// <summary>
/// Provides a list of the authenticated user's contacts merged with anyconnected profiles.<br>The request throws a 400 error if 'personFields' is not specified.
/// Documentation https://developers.google.com/peopleservice/v1/reference/connections/list
/// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong.
/// </summary>
/// <param name="service">Authenticated Peopleservice service.</param>
/// <param name="resourceName">The resource name to return connections for. Only `people/me` is valid.</param>
/// <param name="optional">Optional paramaters.</param>
/// <returns>ListConnectionsResponseResponse</returns>
public static ListConnectionsResponse List(PeopleserviceService service, string resourceName, ConnectionsListOptionalParms optional = null)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException("service");
if (resourceName == null)
throw new ArgumentNullException(resourceName);
// Building the initial request.
var request = service.Connections.List(resourceName);
// Applying optional parameters to the request.
request = (ConnectionsResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);
// Requesting data.
return request.Execute();
}
catch (Exception ex)
{
throw new Exception("Request Connections.List failed.", ex);
}
}
}
public static class SampleHelpers
{
/// <summary>
/// Using reflection to apply optional parameters to the request.
///
/// If the optonal parameters are null then we will just return the request as is.
/// </summary>
/// <param name="request">The request. </param>
/// <param name="optional">The optional parameters. </param>
/// <returns></returns>
public static object ApplyOptionalParms(object request, object optional)
{
if (optional == null)
return request;
System.Reflection.PropertyInfo[] optionalProperties = (optional.GetType()).GetProperties();
foreach (System.Reflection.PropertyInfo property in optionalProperties)
{
// Copy value from optional parms to the request. They should have the same names and datatypes.
System.Reflection.PropertyInfo piShared = (request.GetType()).GetProperty(property.Name);
if (property.GetValue(optional, null) != null) // TODO Test that we do not add values for items that are null
piShared.SetValue(request, property.GetValue(optional, null), null);
}
return request;
}
}
}