Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh gapics #679

Merged
merged 17 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/PubSub/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function testTopicIamPermissions(array $args);
*/
public function createSubscription(array $args);

/**
* @param array $args
*/
public function updateSubscription(array $args);

/**
* @param array $args
*/
Expand Down
22 changes: 22 additions & 0 deletions src/PubSub/Connection/Grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ public function createSubscription(array $args)
]);
}

/**
* @param array $args
*/
public function updateSubscription(array $args)
{
// Get a list of keys used before building subscription, which modifies $args
$mask = array_keys($args);

// Remove immutable properties.
$mask = array_values(array_diff($mask, ['name', 'topic']));

$fieldMask = $this->serializer->decodeMessage(new FieldMask(), ['paths' => $mask]);

$subscriptionObject = $this->buildSubscription($args);

return $this->send([$this->subscriberClient, 'updateSubscription'], [
$subscriptionObject,
$fieldMask,
$args
]);
}

/**
* @param array $args
*/
Expand Down
8 changes: 8 additions & 0 deletions src/PubSub/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ public function createSubscription(array $args)
return $this->send('subscriptions', 'create', $args);
}

/**
* @param array $args
*/
public function updateSubscription(array $args)
{
return $this->send('subscriptions', 'patch', $args);
}

/**
* @param array $args
*/
Expand Down
46 changes: 46 additions & 0 deletions src/PubSub/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,52 @@ public function create(array $options = [])
return $this->info;
}

/**
* Update the subscription.
*
* Note that subscription name and topic are immutable properties and may

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* not be modified.
*
* Example:
* ```
* $subscription->update([
* 'retainAckedMessages' => true
* ]);
* ```
*
* @param array $subscription {
* The Subscription data.
*
* For information regarding the push configuration settings, see
* [PushConfig](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions#PushConfig).
*
* @type string $pushConfig.pushEndpoint A URL locating the endpoint to which
* messages should be pushed. For example, a Webhook endpoint
* might use "https://example.com/push".
* @type array $pushConfig.attributes Endpoint configuration attributes.
* @type int $ackDeadlineSeconds The maximum time after a subscriber
* receives a message before the subscriber should acknowledge the
* message.
* @type bool $retainAckedMessages Indicates whether to retain
* acknowledged messages.
* @type Duration $messageRetentionDuration How long to retain
* unacknowledged messages in the subscription's backlog, from the
* moment a message is published. If `$retainAckedMessages` is
* true, then this also configures the retention of acknowledged
* messages, and thus configures how far back in time a `Seek`
* can be done. Cannot be more than 7 days or less than 10 minutes.
* **Defaults to** 7 days.
* }
* @param array $options [optional] Configuration options.
* @return array The subscription info.
*/
public function update(array $subscription, array $options = [])
{
return $this->info = $this->connection->updateSubscription([
'name' => $this->name
] + $options + $subscription);
}

/**
* Delete a subscription
*
Expand Down
13 changes: 13 additions & 0 deletions tests/snippets/PubSub/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ public function testCreate()
$this->assertEquals($return, $res->returnVal());
}

public function testUpdate()
{
$snippet = $this->snippetFromMethod(Subscription::class, 'update');
$snippet->addLocal('subscription', $this->subscription);

$this->connection->updateSubscription(Argument::any())
->shouldBeCalled();

$this->subscription->___setProperty('connection', $this->connection->reveal());

$snippet->invoke();
}

public function testDelete()
{
$snippet = $this->snippetFromMethod(Subscription::class, 'delete');
Expand Down