google-cloud-pubsub 0.27.2 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f83c458e0a45afd77106e7e66922ad2b1e1d8515
4
- data.tar.gz: 6aeda54db32d7f78e6c8b649cad9beac294408d4
2
+ SHA256:
3
+ metadata.gz: 786c0d9e552987a0743be14c13240519f55fd1d65d18a7dc7462b9d5ce80d33d
4
+ data.tar.gz: 2238dfa68394d90617cced8cd2053761ccf53dc5533049c2b06cfb37a12b5c85
5
5
  SHA512:
6
- metadata.gz: 609784712397870174e5fd07a41978f74616ee7bab81db6ad007efda11b8bb2d1d13f8dce68e0681f1ff4e64be8d2b5c5035e8ae8a10e0a669776eda474430d1
7
- data.tar.gz: af8a25738680f2d7fb74e236ecb6ce7db9a7b5de56774fc34d33f917464c251c13caec9f4cc4d96750a1db786a8a424fd92064dd5b379278820f2d73222f432f
6
+ metadata.gz: 4516e62d4c349e53febc8a632b4aeff7f92633de0050ff2109bab6c64f9b4b8808cac44965c9654a32447dfd9d40ae58cddf82e1810f9cb9d89ff8c9bf5d1615
7
+ data.tar.gz: b553b1e011d2b8e8610e2404c1e9a4a6fec921f2435b60c41b3399582d2d6f67e89ccd14adf09f72615cef6735d0551f777f29ac659cd1dee29e7c5fc7c53aac
data/README.md CHANGED
@@ -24,8 +24,8 @@ Instructions and configuration options are covered in the [Authentication Guide]
24
24
  require "google/cloud/pubsub"
25
25
 
26
26
  pubsub = Google::Cloud::Pubsub.new(
27
- project: "my-project",
28
- keyfile: "/path/to/keyfile.json"
27
+ project_id: "my-project",
28
+ credentials: "/path/to/keyfile.json"
29
29
  )
30
30
 
31
31
  # Retrieve a topic
@@ -13,9 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  ##
16
- # This file is here to be autorequired by bundler, so that the .bigquery and
17
- # #bigquery methods can be available, but the library and all dependencies won't
18
- # be loaded until required and used.
16
+ # This file is here to be autorequired by bundler, so that the
17
+ # Google::Cloud.pubsub and Google::Cloud#pubsub methods can be available, but
18
+ # the library and all dependencies won't be loaded until required and used.
19
19
 
20
20
 
21
21
  gem "google-cloud-core"
@@ -72,10 +72,12 @@ module Google
72
72
  # For more information on connecting to Google Cloud see the [Authentication
73
73
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
74
74
  #
75
- # @param [String] project Project identifier for the Pub/Sub service you are
76
- # connecting to.
77
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
78
- # file path the file must be readable.
75
+ # @param [String] project_id Project identifier for the Pub/Sub service you
76
+ # are connecting to. If not present, the default project for the
77
+ # credentials is used.
78
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
79
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
80
+ # Google::Auth::Credentials object. (See {Pubsub::Credentials})
79
81
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
80
82
  # set of resources and operations that the connection can access. See
81
83
  # [Using OAuth 2.0 to Access Google
@@ -98,10 +100,11 @@ module Google
98
100
  # topic = pubsub.topic "my-topic"
99
101
  # topic.publish "task completed"
100
102
  #
101
- def self.pubsub project = nil, keyfile = nil, scope: nil, timeout: nil,
102
- client_config: nil
103
+ def self.pubsub project_id = nil, credentials = nil, scope: nil,
104
+ timeout: nil, client_config: nil
103
105
  require "google/cloud/pubsub"
104
- Google::Cloud::Pubsub.new project: project, keyfile: keyfile,
106
+ Google::Cloud::Pubsub.new project_id: project_id,
107
+ credentials: credentials,
105
108
  scope: scope, timeout: timeout,
106
109
  client_config: client_config
107
110
  end
@@ -425,11 +425,11 @@ module Google
425
425
  # ```ruby
426
426
  # require "google/cloud/pubsub"
427
427
  #
428
- # pubsub = Google::Cloud::Pubsub.new # my-project-id
428
+ # pubsub = Google::Cloud::Pubsub.new # my-project
429
429
  #
430
430
  # # Get a topic in the current project
431
431
  # my_topic = pubsub.topic "my-topic"
432
- # my_topic.name #=> "projects/my-project-id/topics/my-topic"
432
+ # my_topic.name #=> "projects/my-project/topics/my-topic"
433
433
  # # Get a topic in another project
434
434
  # other_topic = pubsub.topic "other-topic", project: "other-project-id"
435
435
  # other_topic.name #=> "projects/other-project-id/topics/other-topic"
@@ -441,14 +441,14 @@ module Google
441
441
  # ```ruby
442
442
  # require "google/cloud/pubsub"
443
443
  #
444
- # pubsub = Google::Cloud::Pubsub.new # my-project-id
444
+ # pubsub = Google::Cloud::Pubsub.new # my-project
445
445
  #
446
446
  # # Get a topic in another project
447
447
  # topic = pubsub.topic "other-topic", project: "other-project-id"
448
448
  # # Create a subscription in the current project that pulls from
449
449
  # # the topic in another project
450
450
  # sub = topic.subscribe "my-sub"
451
- # sub.name #=> "projects/my-project-id/subscriptions/my-sub"
451
+ # sub.name #=> "projects/my-project/subscriptions/my-sub"
452
452
  # sub.topic.name #=> "projects/other-project-id/topics/other-topic"
453
453
  # ```
454
454
  #
@@ -489,10 +489,12 @@ module Google
489
489
  # [Authentication
490
490
  # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
491
491
  #
492
- # @param [String] project Project identifier for the Pub/Sub service you
493
- # are connecting to.
494
- # @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If
495
- # file path the file must be readable.
492
+ # @param [String] project_id Project identifier for the Pub/Sub service
493
+ # you are connecting to. If not present, the default project for the
494
+ # credentials is used.
495
+ # @param [String, Hash, Google::Auth::Credentials] credentials The path to
496
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
497
+ # Google::Auth::Credentials object. (See {Pubsub::Credentials})
496
498
  # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
497
499
  # the set of resources and operations that the connection can access.
498
500
  # See [Using OAuth 2.0 to Access Google
@@ -506,6 +508,9 @@ module Google
506
508
  # behavior of the API client. Optional.
507
509
  # @param [String] emulator_host Pub/Sub emulator host. Optional.
508
510
  # If the param is nil, ENV["PUBSUB_EMULATOR_HOST"] will be used.
511
+ # @param [String] project Alias for the `project_id` argument. Deprecated.
512
+ # @param [String] keyfile Alias for the `credentials` argument.
513
+ # Deprecated.
509
514
  #
510
515
  # @return [Google::Cloud::Pubsub::Project]
511
516
  #
@@ -517,37 +522,30 @@ module Google
517
522
  # topic = pubsub.topic "my-topic"
518
523
  # topic.publish "task completed"
519
524
  #
520
- def self.new project: nil, keyfile: nil, scope: nil, timeout: nil,
521
- client_config: nil, emulator_host: nil
522
- project ||= Google::Cloud::Pubsub::Project.default_project
523
- project = project.to_s # Always cast to a string
524
- fail ArgumentError, "project is missing" if project.empty?
525
+ def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
526
+ client_config: nil, emulator_host: nil, project: nil,
527
+ keyfile: nil
528
+ project_id ||= (project || Pubsub::Project.default_project_id)
529
+ project_id = project_id.to_s # Always cast to a string
530
+ fail ArgumentError, "project_id is missing" if project_id.empty?
525
531
 
526
532
  emulator_host ||= ENV["PUBSUB_EMULATOR_HOST"]
527
533
  if emulator_host
528
- ps = Google::Cloud::Pubsub::Project.new(
529
- Google::Cloud::Pubsub::Service.new(
530
- project, :this_channel_is_insecure))
531
- ps.service.host = emulator_host
532
- return ps
534
+ return Pubsub::Project.new(
535
+ Pubsub::Service.new(
536
+ project_id, :this_channel_is_insecure,
537
+ host: emulator_host))
533
538
  end
534
539
 
535
- credentials = credentials_with_scope keyfile, scope
536
-
537
- Google::Cloud::Pubsub::Project.new(
538
- Google::Cloud::Pubsub::Service.new(
539
- project, credentials, timeout: timeout,
540
- client_config: client_config))
541
- end
542
-
543
- ##
544
- # @private
545
- def self.credentials_with_scope keyfile, scope
546
- if keyfile.nil?
547
- Google::Cloud::Pubsub::Credentials.default(scope: scope)
548
- else
549
- Google::Cloud::Pubsub::Credentials.new(keyfile, scope: scope)
540
+ credentials ||= (keyfile || Pubsub::Credentials.default(scope: scope))
541
+ unless credentials.is_a? Google::Auth::Credentials
542
+ credentials = Pubsub::Credentials.new credentials, scope: scope
550
543
  end
544
+
545
+ Pubsub::Project.new(
546
+ Pubsub::Service.new(
547
+ project_id, credentials, timeout: timeout,
548
+ client_config: client_config))
551
549
  end
552
550
  end
553
551
  end
@@ -13,18 +13,44 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/credentials"
16
+ require "googleauth"
17
17
 
18
18
  module Google
19
19
  module Cloud
20
20
  module Pubsub
21
21
  ##
22
- # @private Represents the OAuth 2.0 signing logic for Pub/Sub.
23
- class Credentials < Google::Cloud::Credentials
22
+ # # Credentials
23
+ #
24
+ # Represents the authentication and authorization used to connect to the
25
+ # Pub/Sub API.
26
+ #
27
+ # @example
28
+ # require "google/cloud/pubsub"
29
+ #
30
+ # keyfile = "/path/to/keyfile.json"
31
+ # creds = Google::Cloud::Pubsub::Credentials.new keyfile
32
+ #
33
+ # pubsub = Google::Cloud::Pubsub.new(
34
+ # project_id: "my-project",
35
+ # credentials: creds
36
+ # )
37
+ #
38
+ # pubsub.project_id #=> "my-project"
39
+ #
40
+ class Credentials < Google::Auth::Credentials
24
41
  SCOPE = ["https://www.googleapis.com/auth/pubsub"]
25
- PATH_ENV_VARS = %w(PUBSUB_KEYFILE GOOGLE_CLOUD_KEYFILE GCLOUD_KEYFILE)
26
- JSON_ENV_VARS = %w(PUBSUB_KEYFILE_JSON GOOGLE_CLOUD_KEYFILE_JSON
42
+ PATH_ENV_VARS = %w(PUBSUB_CREDENTIALS
43
+ PUBSUB_KEYFILE
44
+ GOOGLE_CLOUD_CREDENTIALS
45
+ GOOGLE_CLOUD_KEYFILE
46
+ GCLOUD_KEYFILE)
47
+ JSON_ENV_VARS = %w(PUBSUB_CREDENTIALS_JSON
48
+ PUBSUB_KEYFILE_JSON
49
+ GOOGLE_CLOUD_CREDENTIALS_JSON
50
+ GOOGLE_CLOUD_KEYFILE_JSON
27
51
  GCLOUD_KEYFILE_JSON)
52
+ DEFAULT_PATHS = \
53
+ ["~/.config/gcloud/application_default_credentials.json"]
28
54
  end
29
55
  end
30
56
  end
@@ -62,19 +62,20 @@ module Google
62
62
  # require "google/cloud/pubsub"
63
63
  #
64
64
  # pubsub = Google::Cloud::Pubsub.new(
65
- # project: "my-project",
66
- # keyfile: "/path/to/keyfile.json"
65
+ # project_id: "my-project",
66
+ # credentials: "/path/to/keyfile.json"
67
67
  # )
68
68
  #
69
- # pubsub.project #=> "my-project"
69
+ # pubsub.project_id #=> "my-project"
70
70
  #
71
- def project
71
+ def project_id
72
72
  service.project
73
73
  end
74
+ alias_method :project, :project_id
74
75
 
75
76
  ##
76
77
  # @private Default project.
77
- def self.default_project
78
+ def self.default_project_id
78
79
  ENV["PUBSUB_PROJECT"] ||
79
80
  ENV["GOOGLE_CLOUD_PROJECT"] ||
80
81
  ENV["GCLOUD_PROJECT"] ||
@@ -63,7 +63,7 @@ module Google
63
63
  @subscriber ||= begin
64
64
  V1::SubscriberClient.new(
65
65
  service_path: host,
66
- channel: channel,
66
+ credentials: channel,
67
67
  timeout: timeout,
68
68
  client_config: client_config,
69
69
  lib_name: "gccl",
@@ -77,7 +77,7 @@ module Google
77
77
  @publisher ||= begin
78
78
  V1::PublisherClient.new(
79
79
  service_path: host,
80
- channel: channel,
80
+ credentials: channel,
81
81
  timeout: timeout,
82
82
  lib_name: "gccl",
83
83
  lib_version: Google::Cloud::Pubsub::VERSION)
@@ -107,7 +107,7 @@ module Google
107
107
  # snapshot.expiration_time
108
108
  #
109
109
  def expiration_time
110
- self.class.timestamp_from_grpc @grpc.expiration_time
110
+ self.class.timestamp_from_grpc @grpc.expire_time
111
111
  end
112
112
 
113
113
  ##
@@ -21,6 +21,8 @@ module Google
21
21
  # two Timestamp values is a Duration and it can be added or subtracted
22
22
  # from a Timestamp. Range is approximately +-10,000 years.
23
23
  #
24
+ # = Examples
25
+ #
24
26
  # Example 1: Compute Duration from two Timestamps in pseudo code.
25
27
  #
26
28
  # Timestamp start = ...;
@@ -60,10 +62,21 @@ module Google
60
62
  # td = datetime.timedelta(days=3, minutes=10)
61
63
  # duration = Duration()
62
64
  # duration.FromTimedelta(td)
65
+ #
66
+ # = JSON Mapping
67
+ #
68
+ # In JSON format, the Duration type is encoded as a string rather than an
69
+ # object, where the string ends in the suffix "s" (indicating seconds) and
70
+ # is preceded by the number of seconds, with nanoseconds expressed as
71
+ # fractional seconds. For example, 3 seconds with 0 nanoseconds should be
72
+ # encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
73
+ # be expressed in JSON format as "3.000000001s", and 3 seconds and 1
74
+ # microsecond should be expressed in JSON format as "3.000001s".
63
75
  # @!attribute [rw] seconds
64
76
  # @return [Integer]
65
77
  # Signed seconds of the span of time. Must be from -315,576,000,000
66
- # to +315,576,000,000 inclusive.
78
+ # to +315,576,000,000 inclusive. Note: these bounds are computed from:
79
+ # 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
67
80
  # @!attribute [rw] nanos
68
81
  # @return [Integer]
69
82
  # Signed fractions of a second at nanosecond resolution of the span
@@ -24,7 +24,9 @@ module Google
24
24
  # 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.
25
25
  # By restricting to that range, we ensure that we can convert to
26
26
  # and from RFC 3339 date strings.
27
- # See {https://www.ietf.org/rfc/rfc3339.txt}[https://www.ietf.org/rfc/rfc3339.txt].
27
+ # See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt).
28
+ #
29
+ # = Examples
28
30
  #
29
31
  # Example 1: Compute Timestamp from POSIX +time()+.
30
32
  #
@@ -65,6 +67,29 @@ module Google
65
67
  #
66
68
  # timestamp = Timestamp()
67
69
  # timestamp.GetCurrentTime()
70
+ #
71
+ # = JSON Mapping
72
+ #
73
+ # In JSON format, the Timestamp type is encoded as a string in the
74
+ # [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) format. That is, the
75
+ # format is "{year}-{month}-{day}T{hour}:{min}:{sec}[.{frac_sec}]Z"
76
+ # where {year} is always expressed using four digits while {month}, {day},
77
+ # {hour}, {min}, and {sec} are zero-padded to two digits each. The fractional
78
+ # seconds, which can go up to 9 digits (i.e. up to 1 nanosecond resolution),
79
+ # are optional. The "Z" suffix indicates the timezone ("UTC"); the timezone
80
+ # is required, though only UTC (as indicated by "Z") is presently supported.
81
+ #
82
+ # For example, "2017-01-15T01:30:15.01Z" encodes 15.01 seconds past
83
+ # 01:30 UTC on January 15, 2017.
84
+ #
85
+ # In JavaScript, one can convert a Date object to this format using the
86
+ # standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString]
87
+ # method. In Python, a standard +datetime.datetime+ object can be converted
88
+ # to this format using [+strftime+](https://docs.python.org/2/library/time.html#time.strftime)
89
+ # with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
90
+ # can use the Joda Time's [+ISODateTimeFormat.dateTime()+](
91
+ # http://joda-time.sourceforge.net/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime())
92
+ # to obtain a formatter capable of generating timestamps in this format.
68
93
  # @!attribute [rw] seconds
69
94
  # @return [Integer]
70
95
  # Represents seconds of UTC time since Unix epoch
@@ -14,6 +14,19 @@
14
14
 
15
15
  module Google
16
16
  module Pubsub
17
+ ##
18
+ # # Google Cloud Pub/Sub API Contents
19
+ #
20
+ # | Class | Description |
21
+ # | ----- | ----------- |
22
+ # | [PublisherClient][] | Provides reliable, many-to-many, asynchronous messaging between applications. |
23
+ # | [SubscriberClient][] | Provides reliable, many-to-many, asynchronous messaging between applications. |
24
+ # | [Data Types][] | Data types for Google::Cloud::Pubsub::V1 |
25
+ #
26
+ # [PublisherClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/publisherclient
27
+ # [SubscriberClient]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/subscriberclient
28
+ # [Data Types]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-pubsub/latest/google/pubsub/v1/datatypes
29
+ #
17
30
  module V1
18
31
  # A topic resource.
19
32
  # @!attribute [rw] name
@@ -24,6 +37,9 @@ module Google
24
37
  # underscores (+_+), periods (+.+), tildes (+~+), plus (+++) or percent
25
38
  # signs (+%+). It must be between 3 and 255 characters in length, and it
26
39
  # must not start with +"goog"+.
40
+ # @!attribute [rw] labels
41
+ # @return [Hash{String => String}]
42
+ # User labels.
27
43
  class Topic; end
28
44
 
29
45
  # A message data and its attributes. The message payload must not be empty;
@@ -54,6 +70,16 @@ module Google
54
70
  # Format is +projects/{project}/topics/{topic}+.
55
71
  class GetTopicRequest; end
56
72
 
73
+ # Request for the UpdateTopic method.
74
+ # @!attribute [rw] topic
75
+ # @return [Google::Pubsub::V1::Topic]
76
+ # The topic to update.
77
+ # @!attribute [rw] update_mask
78
+ # @return [Google::Protobuf::FieldMask]
79
+ # Indicates which fields in the provided topic to update.
80
+ # Must be specified and non-empty.
81
+ class UpdateTopicRequest; end
82
+
57
83
  # Request for the Publish method.
58
84
  # @!attribute [rw] topic
59
85
  # @return [String]
@@ -185,6 +211,9 @@ module Google
185
211
  # of acknowledged messages, and thus configures how far back in time a +Seek+
186
212
  # can be done. Defaults to 7 days. Cannot be more than 7 days or less than 10
187
213
  # minutes.
214
+ # @!attribute [rw] labels
215
+ # @return [Hash{String => String}]
216
+ # User labels.
188
217
  class Subscription; end
189
218
 
190
219
  # Configuration for a push delivery endpoint.
@@ -421,6 +450,16 @@ module Google
421
450
  # Format is +projects/{project}/subscriptions/{sub}+.
422
451
  class CreateSnapshotRequest; end
423
452
 
453
+ # Request for the UpdateSnapshot method.
454
+ # @!attribute [rw] snapshot
455
+ # @return [Google::Pubsub::V1::Snapshot]
456
+ # The updated snpashot object.
457
+ # @!attribute [rw] update_mask
458
+ # @return [Google::Protobuf::FieldMask]
459
+ # Indicates which fields in the provided snapshot to update.
460
+ # Must be specified and non-empty.
461
+ class UpdateSnapshotRequest; end
462
+
424
463
  # A snapshot resource.
425
464
  # @!attribute [rw] name
426
465
  # @return [String]
@@ -428,7 +467,7 @@ module Google
428
467
  # @!attribute [rw] topic
429
468
  # @return [String]
430
469
  # The name of the topic from which this snapshot is retaining messages.
431
- # @!attribute [rw] expiration_time
470
+ # @!attribute [rw] expire_time
432
471
  # @return [Google::Protobuf::Timestamp]
433
472
  # The snapshot is guaranteed to exist up until this time.
434
473
  # A newly-created snapshot expires no later than 7 days from the time of its
@@ -439,6 +478,9 @@ module Google
439
478
  # old. If a snapshot is created from this subscription, the snapshot -- which
440
479
  # will always capture this 3-day-old backlog as long as the snapshot
441
480
  # exists -- will expire in 4 days.
481
+ # @!attribute [rw] labels
482
+ # @return [Hash{String => String}]
483
+ # User labels.
442
484
  class Snapshot; end
443
485
 
444
486
  # Request for the +ListSnapshots+ method.