json-activity-streamish
JSON Activity Streamish ... simple with added verbs
Last updated 4 years ago by slooker .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install json-activity-streamish 
SYNC missed versions from official npm registry.

Build Passing Image

JSON Activity Stream-ish

History

We started writing an activity user stream that used JSON Activity Stream but was bit overly strict for us. We needed things verbs like 'Download' which aren't available in the stream. I wrote this to simplify our actions. It's a VERY simple implementation that produces JSON Activity Stream style JSON output.

To Begin

  1. Install it:
  npm install json-activity-streamish --save
  1. Require it and use:
  const Activity = require('json-activity-streamish')
   let activity = new Activity();
   // <Set the actor, object and type fields as below>
   // Get JSON object
   console.log(activity.toJSON());
   // Get string representation of JSON object
   console.log(activity.toString());

Notes

You can pass in all data when you create the activity like so:

let activity = new Activity({
  "name": "John Smith has accepted JPG.jpg",
  "actor": {
		"id": "98765",
		"type": "Person",
		"attributedTo": "john.smith@myfakedomain.com",
		"name": "John Smith"
	},
	"object": {
		"id": "123456",
		"type": "Link",
		"href": "http://www.fakedomain.com/image/123456",
		"mediaType": "mime/jpeg",
		"name": "JPG.jpg"
	},
	"type": "Accept",  
});

You can also set fields manually:

let activity = new Activity();
activity.type('Accept')
  .actor({
    "id": "98765",
    "type": "Person",
    "attributedTo": "john.smith@myfakedomain.com",
    "name": "John Smith"
  })
  .object({
    "id": "123456",
    "type": "Link",
    "href": "http://www.fakedomain.com/image/123456",
    "mediaType": "mime/jpeg",
    "name": "JPG.jpg"
  });

Note that name will be generated for you from your type, actor and object if you don't set it explicitly. id will also be auto-populated using the node-uuid module

We've added a meta field so that you can add any extraneous data that doesn't fit into JSON Activity Stream spec as well. It works the same way as all of the other fields you can set.

let activity = new Activity();
activity.meta({
  recipients: ["john.smith@myfakedomain.com", "jane.smith@myfakedomain.com"],
  someOtherField: "someOtherData"
});

You can return a json object or a json representation of a string.

// Get a JSON object
activity.toJSON();

// Output to a JSON string representation
activity.toString();

Supported Functions

Getters and Setters

All getters and setters can be called with an argument to set the argument, or without to get the property.

Here's a list of getters and setters:

  • * activity.actor()

  • * activity.object()

  • activity.target()

  • * activity.type()

  • activity.content()

  • activity.meta()

  • activity.name()

  • is a required field.

.name() will be auto generated for you if you do not supply it.

Output

toJSON() will return a JSON object toString() will return a string representation of the JSON object

Current Tags

  • 0.1.17                                ...           latest (4 years ago)

18 Versions

  • 0.1.17                                ...           4 years ago
  • 0.1.16                                ...           4 years ago
  • 0.1.15                                ...           4 years ago
  • 0.1.14                                ...           4 years ago
  • 0.1.13                                ...           4 years ago
  • 0.1.12                                ...           4 years ago
  • 0.1.11                                ...           4 years ago
  • 0.1.10                                ...           4 years ago
  • 0.1.9                                ...           4 years ago
  • 0.1.8                                ...           4 years ago
  • 0.1.7                                ...           4 years ago
  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |