1414
1515require "google/cloud/pubsub"
1616
17- def create_topic_with_cloud_storage_ingestion topic_id :, bucket :, input_format :, text_delimiter :, match_glob :, minimum_object_create_time :
17+ # rubocop:disable Metrics/MethodLength
18+
19+ def create_topic_with_cloud_storage_ingestion topic_id :,
20+ bucket :,
21+ input_format :,
22+ text_delimiter :,
23+ match_glob :,
24+ minimum_object_create_time :
1825 # [START pubsub_create_topic_with_cloud_storage_ingestion]
1926 # project_id = "your-project-id"
2027 # topic_id = "your-topic-id"
@@ -25,16 +32,15 @@ def create_topic_with_cloud_storage_ingestion topic_id:, bucket:, input_format:,
2532 # minimum_object_create_time = "YYYY-MM-DDThh:mm:ssZ"
2633
2734 pubsub = Google ::Cloud ::Pubsub . new
28-
2935 cloud_storage_settings = Google ::Cloud ::PubSub ::V1 ::IngestionDataSourceSettings ::CloudStorage . new (
3036 bucket : bucket ,
37+ match_glob : match_glob
3138 )
32-
3339 case input_format
3440 when "text"
3541 cloud_storage_settings . text_format =
3642 Google ::Cloud ::PubSub ::V1 ::IngestionDataSourceSettings ::CloudStorage ::TextFormat . new (
37- delimiter : text_delimiter ,
43+ delimiter : text_delimiter
3844 )
3945 when "avro"
4046 cloud_storage_settings . avro_format =
@@ -46,21 +52,15 @@ def create_topic_with_cloud_storage_ingestion topic_id:, bucket:, input_format:,
4652 puts "Invalid input format: #{ input_format } ; must be in ('text', 'avro', 'pubsub_avro')"
4753 return
4854 end
49-
50- unless match_glob . empty?
51- cloud_storage_settings . match_glob = match_glob
52- end
53-
5455 unless minimum_object_create_time . empty?
55- minimum_object_create_time_timestamp = Time . parse ( minimum_object_create_time )
56- cloud_storage_settings . minimum_object_create_time = minimum_object_create_time_timestamp
56+ cloud_storage_settings . minimum_object_create_time = Time . parse minimum_object_create_time
5757 end
58-
5958 ingestion_data_source_settings = Google ::Cloud ::PubSub ::V1 ::IngestionDataSourceSettings . new (
60- cloud_storage : cloud_storage_settings ,
59+ cloud_storage : cloud_storage_settings
6160 )
6261 topic = pubsub . create_topic topic_id , ingestion_data_source_settings : ingestion_data_source_settings
63-
6462 puts "Topic #{ topic . name } with Cloud Storage ingestion settings created."
6563 # [END pubsub_create_topic_with_cloud_storage_ingestion]
6664end
65+
66+ # rubocop:enable Metrics/MethodLength
0 commit comments