Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1092)

Side by Side Diff: GoogleApis.Tools.ServiceGenerator/DiscoveryRepository.cs

Issue 12020043: Issue 325 - Remove discovery and codegen (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: Sir miceli comment Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 Copyright 2011 Google Inc
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 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Linq;
21 using Google.Apis.Discovery.v1.Data;
22 using Google.Apis.Json;
23
24 namespace GoogleApis.Tools.ServiceGenerator
25 {
26 /// <summary>
27 /// Describes a discovery service repository.
28 /// </summary>
29 public static class DiscoveryRepository
30 {
31 private const string GoogleDiscoveryURL = "https://www.googleapis.com/di scovery/v1/apis";
32 ·
33 /// <summary>
34 /// Retrieves the list of APIs of the specified discovery reposistory.
35 /// </summary>
36 public static IEnumerable<DirectoryList.ItemsData> RetrieveDiscovery(Uri listUri)
37 {
38 string document = Utils.FetchDocument(listUri);
39 var items = new NewtonsoftJsonSerializer().Deserialize<DirectoryList >(document).Items·
40 ?? Enumerable.Empty<DirectoryList.ItemsData>();
41
42 // Make the path references rooted. We do this so that we can use ju st the ItemsData object
43 // to generate an API.
44 string basePath = listUri.ToString().Substring(0, listUri.ToString() .LastIndexOf('/') + 1);
45 foreach (DirectoryList.ItemsData api in items)
46 {
47 if (api.DiscoveryLink.StartsWith("./"))
48 {
49 api.DiscoveryLink = basePath + api.DiscoveryLink.Substring(" ./".Length);
50 }
51 else if (api.DiscoveryLink.StartsWith("../"))
52 {
53 api.DiscoveryLink = basePath + api.DiscoveryLink;
54 }
55 }
56
57 return items;
58 }
59
60 /// <summary>
61 /// Retrieves the list of apis in the Google Discovery repository.
62 /// </summary>
63 /// <returns></returns>
64 public static IEnumerable<DirectoryList.ItemsData> RetrieveGoogleDiscove ry()
65 {
66 return RetrieveDiscovery(new Uri(GoogleDiscoveryURL));
67 }
68 }
69 }
OLDNEW
« no previous file with comments | « GoogleApis.Tools.ServiceGenerator/ArgumentEnumerator.cs ('k') | GoogleApis.Tools.ServiceGenerator/Generator.cs » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b