Skip to content

Commit

Permalink
(pubsub) refactor api.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Oct 6, 2014
1 parent 18b374d commit 3acb446
Show file tree
Hide file tree
Showing 15 changed files with 1,918 additions and 515 deletions.
17 changes: 16 additions & 1 deletion docs/components/docs/docs-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ angular.module('gcloud.docs')
]
},

pubsub: {
title: 'PubSub',
_url: '{baseUrl}/pubsub',
pages: [
{
title: 'Topic',
url: '/topic'
},
{
title: 'Subscription',
url: '/subscription'
}
]
},

storage: {
title: 'Storage',
_url: '{baseUrl}/storage'
Expand All @@ -49,6 +64,6 @@ angular.module('gcloud.docs')
// https://github.com/npm/node-semver#versions
// List should be in ascending order.
'<=0.7.1': ['gcloud', 'datastore', 'storage'],
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'storage']
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'pubsub', 'storage']
}
});
18 changes: 18 additions & 0 deletions docs/components/docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ <h3>Datastore Overview</h3>
</p>
</article>

<article ng-if="isActiveDoc('pubsub')">
<h3>Pub/Sub Overview</h3>
<p class="notice">
Google Cloud Pub/Sub is in Alpha status. As a result, it might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
</p>
<p>
The <code>gcloud.pubsub</code> method will return a <code>pubsub</code> object, allowing you to create topics, publish messages, subscribe to topics, and more. See the <a href="https://developers.google.com/pubsub/overview">Google Cloud Pub/Sub overview</a> for more information.
</p>
<div hljs>
var pubsub = gcloud.pubsub({
projectId: 'myProject',
keyFilename: '/path/to/keyfile.json'
});</div>
<p>
See the examples below, which demonstrate everything from creating a topic to subscribing to messages on a topic.
</p>
</article>

<article ng-if="isActiveDoc('storage')">
<h3>Storage Overview</h3>
<p>
Expand Down
3 changes: 2 additions & 1 deletion docs/components/docs/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ angular
return function(mixInData) {
return mixInData
.reduce(function(acc, mixInMethods) {
return acc = acc.concat(mixInMethods);
acc = acc.concat(mixInMethods);
return acc;
}, data)
.sort(function(a, b) {
return a.name > b.name;
Expand Down
5 changes: 5 additions & 0 deletions docs/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ h2, h3 {
position: relative;
}

.notice {
background-color: #e5ecf9;
padding: 8px;
}

.permalink {
display: none;
position: absolute;
Expand Down
3 changes: 3 additions & 0 deletions lib/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ module.exports.handleResp = handleResp;
* @return {string}
*/
function getType(value) {
if (value instanceof Buffer) {
return 'buffer';
}
return Object.prototype.toString.call(value).match(/\s(\w+)\]/)[1];
}

Expand Down
29 changes: 20 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@

'use strict';

/**
* @type module:common/util
* @private
*/
var util = require('./common/util.js');

/**
* @type {module:datastore}
* @private
Expand All @@ -30,7 +36,7 @@ var Datastore = require('./datastore');
* @type {module:pubsub}
* @private
*/
var pubsub = require('./pubsub');
var PubSub = require('./pubsub');

/**
* @type {module:storage}
Expand Down Expand Up @@ -86,13 +92,17 @@ var Storage = require('./storage');
*
* var bucket = gcloud.storage.bucket({
* bucketName: 'PhotosBucket',
* // properties may be overriden:
* // properties may be overridden:
* keyFilename: '/path/to/other/keyfile.json'
* });
*/
function gcloud(config) {
return {
datastore: new Datastore(config),
pubsub: function(options) {
options = options || {};
return new PubSub(util.extendGlobalConfig(config, options));
},
storage: new Storage(config)
};
}
Expand Down Expand Up @@ -130,24 +140,25 @@ gcloud.datastore = Datastore;
* Note: Google Cloud Pub/Sub API is available as a Limited Preview and the
* client library we provide is currently experimental. The API and/or the
* client might be changed in backward-incompatible ways. This API is not
* subject to any SLA or deprecation policy. Request to be whitelisted to use
* it by filling the
* subject to any SLA or deprecation policy. Request to be whitelisted to use it
* by filling the
* [Limited Preview application form]{@link http://goo.gl/sO0wTu}.
*
* @type {module:pubsub}
*
* @return {object}
* @return {module:pubsub}
*
* @example
* var gcloud = require('gcloud');
* var pubsub = gcloud.pubsub;
*
* var conn = new pubsub.Connection({
* var pubsub = gcloud.pubsub({
* projectId: YOUR_PROJECT_ID,
* keyFilename: '/path/to/the/key.json'
* });
*/
gcloud.pubsub = pubsub;
gcloud.pubsub = function(config) {
return new PubSub(config);
};

/**
* Google Cloud Storage allows you to store data on Google infrastructure.
Expand All @@ -171,7 +182,7 @@ gcloud.pubsub = pubsub;
*
* // storage:
* // {
* // Bucket: function() {}
* // bucket: function() {}
* // }
*/
gcloud.storage = Storage;
Expand Down
Loading

0 comments on commit 3acb446

Please sign in to comment.