{"action":"created","issue":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/393","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/393/labels{/name}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/393/comments","events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/393/events","html_url":"https://github.com/GoogleCloudPlatform/gcloud-ruby/issues/393","id":112895908,"number":393,"title":"Question: Most Ruby way to create a Pub/Sub topic?","user":{"login":"jeffmendoza","id":771387,"avatar_url":"https://avatars.githubusercontent.com/u/771387?v=3","gravatar_id":"","url":"https://api.github.com/users/jeffmendoza","html_url":"https://github.com/jeffmendoza","followers_url":"https://api.github.com/users/jeffmendoza/followers","following_url":"https://api.github.com/users/jeffmendoza/following{/other_user}","gists_url":"https://api.github.com/users/jeffmendoza/gists{/gist_id}","starred_url":"https://api.github.com/users/jeffmendoza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeffmendoza/subscriptions","organizations_url":"https://api.github.com/users/jeffmendoza/orgs","repos_url":"https://api.github.com/users/jeffmendoza/repos","events_url":"https://api.github.com/users/jeffmendoza/events{/privacy}","received_events_url":"https://api.github.com/users/jeffmendoza/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-22T21:31:22Z","updated_at":"2015-10-23T14:22:16Z","closed_at":"2015-10-22T21:42:31Z","body":"This library allows a lot of flexibility\r\n\r\n```ruby\r\n# I think I'll go with\r\ntopic = pubsub.get_topic $topic_name\r\nif topic.nil?\r\n  topic = pubsub.create_topic $topic_name\r\nend\r\n\r\n#----\r\n\r\ntopic = pubsub.create_topic $topic_name unless pubsub.topic($topic_name).exists?\r\ntopic = pubsub.topic $topic_name\r\n\r\n#---\r\n\r\nif pubsub.topic($topic_name).exists?\r\n  topic = pubsub.topic $topic_name\r\nelse\r\n  topic = pubsub.create_topic $topic_name\r\nend\r\n\r\n#---\r\n\r\n# use autocreate\r\ntopic = pubsub.topic $topic_name\r\ntopic.publish \"message\"\r\n# need to create explicitly first to add a subscription though...\r\n\r\n#---\r\n```\r\ncc @thagomizer"},"comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/comments/150588419","html_url":"https://github.com/GoogleCloudPlatform/gcloud-ruby/issues/393#issuecomment-150588419","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-ruby/issues/393","id":150588419,"user":{"login":"jgeewax","id":112928,"avatar_url":"https://avatars.githubusercontent.com/u/112928?v=3","gravatar_id":"","url":"https://api.github.com/users/jgeewax","html_url":"https://github.com/jgeewax","followers_url":"https://api.github.com/users/jgeewax/followers","following_url":"https://api.github.com/users/jgeewax/following{/other_user}","gists_url":"https://api.github.com/users/jgeewax/gists{/gist_id}","starred_url":"https://api.github.com/users/jgeewax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgeewax/subscriptions","organizations_url":"https://api.github.com/users/jgeewax/orgs","repos_url":"https://api.github.com/users/jgeewax/repos","events_url":"https://api.github.com/users/jgeewax/events{/privacy}","received_events_url":"https://api.github.com/users/jgeewax/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T14:22:16Z","updated_at":"2015-10-23T14:22:16Z","body":"To be clear, I could see either of the following being awesome:\r\n\r\n```ruby\r\ntopic = pubsub.get_or_create_topic \"my-topic\"\r\nsubscription = topic.subscribe \"my-subscription\"\r\n# Note that there shouldn't be an error that the subscriptions already exists, right?\r\n# The intent is for me to subscribe. \"making that happen\" is the same as get-or-create.\r\n```\r\n\r\nor\r\n\r\n```ruby\r\nsubscription = pubsub.subscribe \"my-topic\" \"my-subscription\"\r\n# Same note as above about no errors...?\r\n```"}}