Skip to content

Commit

Permalink
Add binary type
Browse files Browse the repository at this point in the history
Closes #33.
  • Loading branch information
Evan Prodromou committed Aug 22, 2012
1 parent 344284c commit c803e07
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/model/activityobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ ActivityObject.objectTypes = ["alert",
"article",
"audio",
"badge",
"binary",
"bookmark",
"collection",
"comment",
Expand Down
36 changes: 36 additions & 0 deletions lib/model/binary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// binary.js
//
// data object representing an binary
//
// Copyright 2012, StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var _ = require("underscore"),
DatabankObject = require("databank").DatabankObject,
ActivityObject = require("./activityobject").ActivityObject;

var Binary = DatabankObject.subClass("binary", ActivityObject);

Binary.schema = {
pkey: ActivityObject.baseSchema.pkey,
indices: _.clone(ActivityObject.baseSchema.indices),
fields: ActivityObject.baseSchema.fields.concat(["compression",
"data",
"fileUrl",
"length",
"md5",
"mimeType"])
};

exports.Binary = Binary;
1 change: 1 addition & 0 deletions test/activityobject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ vows.describe("activityobject class interface").addBatch({
assert.equal(ActivityObject.ARTICLE, "article");
assert.equal(ActivityObject.AUDIO, "audio");
assert.equal(ActivityObject.BADGE, "badge");
assert.equal(ActivityObject.BINARY, "binary");
assert.equal(ActivityObject.BOOKMARK, "bookmark");
assert.equal(ActivityObject.COLLECTION, "collection");
assert.equal(ActivityObject.COMMENT, "comment");
Expand Down
71 changes: 71 additions & 0 deletions test/binary-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// binary-test.js
//
// Test the binary module
//
// Copyright 2012, StatusNet Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var assert = require("assert"),
vows = require("vows"),
databank = require("databank"),
URLMaker = require("../lib/urlmaker").URLMaker,
modelBatch = require("./lib/model").modelBatch,
Databank = databank.Databank,
DatabankObject = databank.DatabankObject;

var suite = vows.describe("binary module interface");

var testSchema = {
pkey: "id",
fields: ["attachments",
"author",
"content",
"displayName",
"downstreamDuplicates",
"id",
"image",
"objectType",
"published",
"summary",
"updated",
"upstreamDuplicates",
"url",
"uuid",
"compression",
"data",
"fileUrl",
"length",
"md5",
"mimeType"],
indices: ["uuid"]
};

var testData = {
"create": {
displayName: "The traditional greeting",
data: "SGVsbG8sIFdvcmxkCg==",
length: 13,
md5: "9af2f8218b150c351ad802c6f3d66abe",
mimeType: "text/plain"
},
"update": {
data: "SGVsbG8gYWdhaW4sIFdvcmxkCg==",
length: 19,
md5: "a89617014e7be8529deb55473795320c"
}
};

suite.addBatch(modelBatch("binary", "Binary", testSchema, testData));

suite["export"](module);

0 comments on commit c803e07

Please sign in to comment.