From 021c29ea36603dd2415d7e3ab98f2b98c6320e15 Mon Sep 17 00:00:00 2001
From: Muxi Yan <mxyan@google.com>
Date: Fri, 28 Jul 2017 13:10:26 -0700
Subject: [PATCH] Create optional subspec for GRPCCall+GID

---
 gRPC.podspec                              | 23 ++++++++++++++----
 src/objective-c/GRPCClient/GRPCCall+GID.h | 29 +++++++++++++++++++++++
 src/objective-c/GRPCClient/GRPCCall+GID.m | 28 ++++++++++++++++++++++
 templates/gRPC.podspec.template           | 23 ++++++++++++++----
 4 files changed, 95 insertions(+), 8 deletions(-)
 create mode 100644 src/objective-c/GRPCClient/GRPCCall+GID.h
 create mode 100644 src/objective-c/GRPCClient/GRPCCall+GID.m

diff --git a/gRPC.podspec b/gRPC.podspec
index 4c83ccc7a0..22ecdcf66f 100644
--- a/gRPC.podspec
+++ b/gRPC.podspec
@@ -40,12 +40,9 @@ Pod::Spec.new do |s|
   s.header_dir = name
 
   src_dir = 'src/objective-c/GRPCClient'
-  s.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}"
-  s.private_header_files = "#{src_dir}/private/*.h"
-  s.header_mappings_dir = "#{src_dir}"
 
-  s.dependency 'gRPC-Core', version
   s.dependency 'gRPC-RxLibrary', version
+  s.default_subspec = 'Main'
 
   # Certificates, to be able to establish TLS connections:
   s.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] }
@@ -54,4 +51,22 @@ Pod::Spec.new do |s|
     # This is needed by all pods that depend on gRPC-RxLibrary:
     'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
   }
+
+  s.subspec 'Main' do |ss|
+    ss.header_mappings_dir = "#{src_dir}"
+
+    ss.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}"
+    ss.exclude_files = "#{src_dir}/GRPCCall+GID.{h,m}"
+    ss.private_header_files = "#{src_dir}/private/*.h"
+
+    ss.dependency 'gRPC-Core', version
+  end
+
+  s.subspec 'GID' do |ss|
+    ss.header_mappings_dir = "#{src_dir}"
+
+    ss.source_files = "#{src_dir}/GRPCCall+GID.{h,m}"
+
+    ss.dependency 'Google/SignIn'
+  end
 end
diff --git a/src/objective-c/GRPCClient/GRPCCall+GID.h b/src/objective-c/GRPCClient/GRPCCall+GID.h
new file mode 100644
index 0000000000..3ee732e79e
--- /dev/null
+++ b/src/objective-c/GRPCClient/GRPCCall+GID.h
@@ -0,0 +1,29 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * 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.
+ *
+ */
+
+#import "GRPCCall.h"
+#import "GRPCCall+OAuth2.h"
+
+#import <Google/SignIn.h>
+
+/**
+ * Extend GIDSignIn class to comply GRPCAuthorizationProtocol
+ */
+@interface GIDSignIn (GRPC) <GRPCAuthorizationProtocol>
+- (void)getTokenWithHandler:(void (^)(NSString *token))hander;
+@end
diff --git a/src/objective-c/GRPCClient/GRPCCall+GID.m b/src/objective-c/GRPCClient/GRPCCall+GID.m
new file mode 100644
index 0000000000..030737147b
--- /dev/null
+++ b/src/objective-c/GRPCClient/GRPCCall+GID.m
@@ -0,0 +1,28 @@
+/*
+ *
+ * Copyright 2017 gRPC authors.
+ *
+ * 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.
+ *
+ */
+
+#import "GRPCCall+GID.h"
+
+@implementation GIDSignIn (GRPC)
+
+- (void)getTokenWithHandler:(void (^)(NSString *token))handler {
+  NSString *token = self.currentUser.authentication.accessToken;
+  handler(token);
+}
+
+@end
diff --git a/templates/gRPC.podspec.template b/templates/gRPC.podspec.template
index 62a6d37c3c..5c92f9f9c4 100644
--- a/templates/gRPC.podspec.template
+++ b/templates/gRPC.podspec.template
@@ -42,12 +42,9 @@
     s.header_dir = name
 
     src_dir = 'src/objective-c/GRPCClient'
-    s.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}"
-    s.private_header_files = "#{src_dir}/private/*.h"
-    s.header_mappings_dir = "#{src_dir}"
 
-    s.dependency 'gRPC-Core', version
     s.dependency 'gRPC-RxLibrary', version
+    s.default_subspec = 'Main'
 
     # Certificates, to be able to establish TLS connections:
     s.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] }
@@ -56,4 +53,22 @@
       # This is needed by all pods that depend on gRPC-RxLibrary:
       'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
     }
+
+    s.subspec 'Main' do |ss|
+      ss.header_mappings_dir = "#{src_dir}"
+
+      ss.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}"
+      ss.exclude_files = "#{src_dir}/GRPCCall+GID.{h,m}"
+      ss.private_header_files = "#{src_dir}/private/*.h"
+
+      ss.dependency 'gRPC-Core', version
+    end
+
+    s.subspec 'GID' do |ss|
+      ss.header_mappings_dir = "#{src_dir}"
+
+      ss.source_files = "#{src_dir}/GRPCCall+GID.{h,m}"
+
+      ss.dependency 'Google/SignIn'
+    end
   end
-- 
GitLab