File: topics.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (32 lines) | stat: -rw-r--r-- 874 bytes parent folder | download | duplicates (4)
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
require "fog/core/collection"
require "fog/google/models/pubsub/topic"

module Fog
  module Google
    class Pubsub
      class Topics < Fog::Collection
        model Fog::Google::Pubsub::Topic

        # Lists all topics that exist on the project.
        #
        # @return [Array<Fog::Google::Pubsub::Topic>] list of topics
        def all
          data = service.list_topics.to_h[:topics] || []
          load(data)
        end

        # Retrieves a topic by name
        #
        # @param topic_name [String] name of topic to retrieve
        # @return [Fog::Google::Pubsub::Topic] topic found, or nil if not found
        def get(topic_name)
          topic = service.get_topic(topic_name).to_h
          new(topic)
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404
          nil
        end
      end
    end
  end
end