Skip to content

Commit

Permalink
Remove creating subscription without a name
Browse files Browse the repository at this point in the history
The Google Cloud docs state that subscriptions can be created without
a name, and that a name will be generated in such cases. However, we
cannot create subscriptions without a name using Google API Client.
Remove the option to subscribe without a name until this is supported.

[refs googleapis#193]
  • Loading branch information
blowmage committed Jul 20, 2015
1 parent 45b1e7a commit b80325f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
10 changes: 0 additions & 10 deletions lib/gcloud/pubsub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ def self.pubsub project = nil, keyfile = nil
# sub = topic.subscribe "my-topic-sub"
# puts sub.name # => "my-topic-sub"
#
# The name is optional, and will be generated if not given.
#
# require "gcloud/pubsub"
#
# pubsub = Gcloud.pubsub
#
# topic = pubsub.topic "my-topic"
# sub = topic.subscribe "my-topic-sub"
# puts sub.name # => "generated-sub-name"
#
# The subscription can be created that specifies the number of seconds to
# wait to be acknowledged as well as an endpoint URL to push the messages to:
#
Expand Down
2 changes: 1 addition & 1 deletion lib/gcloud/pubsub/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def delete_topic topic

##
# Creates a subscription on a given topic for a given subscriber.
def create_subscription topic, subscription_name = nil, options = {}
def create_subscription topic, subscription_name, options = {}
data = subscription_data topic, options
@client.execute(
api_method: @pubsub.projects.subscriptions.create,
Expand Down
10 changes: 6 additions & 4 deletions lib/gcloud/pubsub/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ def delete
# === Parameters
#
# +subscription_name+::
# Name of the new subscription. If the name is not provided in the
# request, the server will assign a random name for this subscription
# on the same project as the topic. (+String+)
# Name of the new subscription. Must start with a letter, and contain
# only letters ([A-Za-z]), numbers ([0-9], dashes (-), underscores (_),
# periods (.), tildes (~), plus (+) or percent signs (%). It must be
# between 3 and 255 characters in length, and it must not start with
# "goog". (+String+)
# +options+::
# An optional Hash for controlling additional behavior. (+Hash+)
# <code>options[:deadline]</code>::
Expand Down Expand Up @@ -152,7 +154,7 @@ def delete
# deadline: 120,
# endpoint: "https://example.com/push"
#
def subscribe subscription_name = nil, options = {}
def subscribe subscription_name, options = {}
ensure_connection!
resp = connection.create_subscription name, subscription_name, options
if resp.success?
Expand Down
13 changes: 0 additions & 13 deletions test/gcloud/pubsub/test_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@
sub.must_be_kind_of Gcloud::Pubsub::Subscription
end

it "creates a subscription without giving a name" do
mock_connection.put "/v1/projects/#{project}/subscriptions/" do |env|
JSON.parse(env.body)["topic"].must_equal topic_path(topic_name)
JSON.parse(env.body)["name"].must_be :nil?
[200, {"Content-Type"=>"application/json"},
subscription_json(topic_name, nil)]
end

sub = topic.subscribe
sub.wont_be :nil?
sub.must_be_kind_of Gcloud::Pubsub::Subscription
end

it "creates a subscription with a deadline" do
new_sub_name = "new-sub-#{Time.now.to_i}"
deadline = 42
Expand Down

0 comments on commit b80325f

Please sign in to comment.