Skip to content

Commit 27c4ba7

Browse files
committed
Merge pull request #245 from stephenplusplus/spp--pubsub-refactor
pubsub refactor
2 parents 18b374d + 3acb446 commit 27c4ba7

File tree

15 files changed

+1918
-515
lines changed

15 files changed

+1918
-515
lines changed

docs/components/docs/docs-values.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ angular.module('gcloud.docs')
3939
]
4040
},
4141

42+
pubsub: {
43+
title: 'PubSub',
44+
_url: '{baseUrl}/pubsub',
45+
pages: [
46+
{
47+
title: 'Topic',
48+
url: '/topic'
49+
},
50+
{
51+
title: 'Subscription',
52+
url: '/subscription'
53+
}
54+
]
55+
},
56+
4257
storage: {
4358
title: 'Storage',
4459
_url: '{baseUrl}/storage'
@@ -49,6 +64,6 @@ angular.module('gcloud.docs')
4964
// https://github.com/npm/node-semver#versions
5065
// List should be in ascending order.
5166
'<=0.7.1': ['gcloud', 'datastore', 'storage'],
52-
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'storage']
67+
'>0.7.1': ['gcloud', 'datastoreWithTransaction', 'pubsub', 'storage']
5368
}
5469
});

docs/components/docs/docs.html

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ <h3>Datastore Overview</h3>
7373
</p>
7474
</article>
7575

76+
<article ng-if="isActiveDoc('pubsub')">
77+
<h3>Pub/Sub Overview</h3>
78+
<p class="notice">
79+
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.
80+
</p>
81+
<p>
82+
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.
83+
</p>
84+
<div hljs>
85+
var pubsub = gcloud.pubsub({
86+
projectId: 'myProject',
87+
keyFilename: '/path/to/keyfile.json'
88+
});</div>
89+
<p>
90+
See the examples below, which demonstrate everything from creating a topic to subscribing to messages on a topic.
91+
</p>
92+
</article>
93+
7694
<article ng-if="isActiveDoc('storage')">
7795
<h3>Storage Overview</h3>
7896
<p>

docs/components/docs/docs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ angular
172172
return function(mixInData) {
173173
return mixInData
174174
.reduce(function(acc, mixInMethods) {
175-
return acc = acc.concat(mixInMethods);
175+
acc = acc.concat(mixInMethods);
176+
return acc;
176177
}, data)
177178
.sort(function(a, b) {
178179
return a.name > b.name;

docs/css/main.css

+5
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ h2, h3 {
617617
position: relative;
618618
}
619619

620+
.notice {
621+
background-color: #e5ecf9;
622+
padding: 8px;
623+
}
624+
620625
.permalink {
621626
display: none;
622627
position: absolute;

lib/common/util.js

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ module.exports.handleResp = handleResp;
183183
* @return {string}
184184
*/
185185
function getType(value) {
186+
if (value instanceof Buffer) {
187+
return 'buffer';
188+
}
186189
return Object.prototype.toString.call(value).match(/\s(\w+)\]/)[1];
187190
}
188191

lib/index.js

+20-9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
'use strict';
2222

23+
/**
24+
* @type module:common/util
25+
* @private
26+
*/
27+
var util = require('./common/util.js');
28+
2329
/**
2430
* @type {module:datastore}
2531
* @private
@@ -30,7 +36,7 @@ var Datastore = require('./datastore');
3036
* @type {module:pubsub}
3137
* @private
3238
*/
33-
var pubsub = require('./pubsub');
39+
var PubSub = require('./pubsub');
3440

3541
/**
3642
* @type {module:storage}
@@ -86,13 +92,17 @@ var Storage = require('./storage');
8692
*
8793
* var bucket = gcloud.storage.bucket({
8894
* bucketName: 'PhotosBucket',
89-
* // properties may be overriden:
95+
* // properties may be overridden:
9096
* keyFilename: '/path/to/other/keyfile.json'
9197
* });
9298
*/
9399
function gcloud(config) {
94100
return {
95101
datastore: new Datastore(config),
102+
pubsub: function(options) {
103+
options = options || {};
104+
return new PubSub(util.extendGlobalConfig(config, options));
105+
},
96106
storage: new Storage(config)
97107
};
98108
}
@@ -130,24 +140,25 @@ gcloud.datastore = Datastore;
130140
* Note: Google Cloud Pub/Sub API is available as a Limited Preview and the
131141
* client library we provide is currently experimental. The API and/or the
132142
* client might be changed in backward-incompatible ways. This API is not
133-
* subject to any SLA or deprecation policy. Request to be whitelisted to use
134-
* it by filling the
143+
* subject to any SLA or deprecation policy. Request to be whitelisted to use it
144+
* by filling the
135145
* [Limited Preview application form]{@link http://goo.gl/sO0wTu}.
136146
*
137147
* @type {module:pubsub}
138148
*
139-
* @return {object}
149+
* @return {module:pubsub}
140150
*
141151
* @example
142152
* var gcloud = require('gcloud');
143-
* var pubsub = gcloud.pubsub;
144153
*
145-
* var conn = new pubsub.Connection({
154+
* var pubsub = gcloud.pubsub({
146155
* projectId: YOUR_PROJECT_ID,
147156
* keyFilename: '/path/to/the/key.json'
148157
* });
149158
*/
150-
gcloud.pubsub = pubsub;
159+
gcloud.pubsub = function(config) {
160+
return new PubSub(config);
161+
};
151162

152163
/**
153164
* Google Cloud Storage allows you to store data on Google infrastructure.
@@ -171,7 +182,7 @@ gcloud.pubsub = pubsub;
171182
*
172183
* // storage:
173184
* // {
174-
* // Bucket: function() {}
185+
* // bucket: function() {}
175186
* // }
176187
*/
177188
gcloud.storage = Storage;

0 commit comments

Comments
 (0)