In addition to the mandatory and recommended fields, extra custom fields may be added to an activity. Let's look at a more expressive example:
# Create a bit more complex activity
activity_data = {:actor => 'User:1', :verb => 'run', :object => 'Exercise:42',
:course => {:name => 'Golden Gate park', :distance => 10},
:participants => ['Thierry', 'Tommaso'],
:started_at => DateTime.now(),
:foreign_id => 'run:1',
:location => {:type => 'point', :coordinates => [37.769722,-122.476944] }
}
activity_response = user_feed_1.add_activity(activity_data)
// Create a bit more complex activity
activity = {'actor': 'User:1', 'verb': 'run', 'object': 'Exercise:42',
'course': {'name': 'Golden Gate park', 'distance': 10},
'participants': ['Thierry', 'Tommaso'],
'started_at': new Date(),
'foreign_id': 'run:1',
'location': {'type': 'point', 'coordinates': [37.769722,-122.476944] }
};
user1.addActivity(activity)
.then(function(data) { /* on success */ })
.catch(function(reason) { /* on failure */ });
import datetime
# Create a bit more complex activity
activity_data = {'actor': 'User:1', 'verb': 'run', 'object': 'Exercise:42',
'course': {'name': 'Golden Gate park', 'distance': 10},
'participants': ['Thierry', 'Tommaso'],
'started_at': datetime.datetime.utcnow(),
'foreign_id': 'run:1',
'location': {'type': 'point', 'coordinates': [37.769722,-122.476944] }
}
user_feed_1.add_activity(activity_data)
// Create a bit more complex activity
$now = new DateTime('now');
$data = [
'actor' => 'User:1',
'verb' => 'run',
'object' => 1,
'course' => ['name'=> 'Golden Gate park', 'distance'=> 10],
'participants' => ['Thierry', 'Tommaso'],
'started_at' => $now,
'foreign_id' => 'run:1',
'location' => [
'type'=> 'point',
'coordinates'=> [
37.769722, -122.476944,
],
],
];
$userFeed1->addActivity($data);
// You can add custom data to your activities.
//
// Here's an example on how to do it:
// https://github.com/GetStream/stream-java/blob/master/stream-repo-apache/src/test/java/io/getstream/client/apache/example/mixtype/MixedType.java
// Create a bit more complex activity
activity := stream.Activity{
Actor: "User:1",
Verb: "run",
Object: "Exercise:42",
ForeignID: "run:1",
Extra: map[string]interface{}{
"course": map[string]interface{}{
"name": "Golden Gate park",
"distance": 10,
},
"participants": []string{
"Thierry",
"Tommaso",
},
"started_at": time.Now(),
},
}
_, err := userFeed.AddActivity(activity)
if err != nil {
panic(err)
}
// Create a bit more complex activity
var activity = new Activity("User:1", "run", "Exercise:42")
{
ForeignId = "run:1"
};
var course = new Dictionary<string, object>();
course["name"] = "Shevlin Park";
course["distance"] = 10;
var participants = new string[] { "Thierry", "Tommaso" };
var location = new Dictionary<string, object>();
location.Add("type", "point");
location.Add("coordinates", new float[] {37.769722F, -122.476944F});
activity.SetData("location", location);
activity.SetData("course", course);
activity.SetData("participants", participants);
For performance reasons activities are limited in size (128KB) and must not contain blob/binary data (eg. base64 encoded images). Use references and identifiers to facilitate Activity enrichment by your backend or client.
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
course:{
distance:10,
name:"Golden Gate Park"
},
object:"Exercise:42",
participants:[
"Thierry",
"Tommaso"
],
started_at:"2014-11-11T15:06:16+01:00",
target:null,
time:"2014-11-11T14:06:30.494",
verb:"run"
}
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
course:{
distance:10,
name:"Golden Gate Park"
},
object:"Exercise:42",
participants:[
"Thierry",
"Tommaso"
],
started_at:"2014-11-11T15:06:16+01:00",
target:null,
time:"2014-11-11T14:06:30.494",
verb:"run"
}
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
course:{
distance:10,
name:"Golden Gate Park"
},
object:"Exercise:42",
participants:[
"Thierry",
"Tommaso"
],
started_at:"2014-11-11T15:06:16+01:00",
target:null,
time:"2014-11-11T14:06:30.494",
verb:"run"
}
{
"id": "ef696c12-69ab-11e4-8080-80003644b625",
"actor": "User:1",
"course": {
"distance":10,
"name":"Golden Gate Park"
},
"object": "Exercise:42",
"participants": [
"Thierry",
"Tommaso"
],
"started_at": "2014-11-11T15:06:16+01:00",
"target": null,
"time": "2014-11-11T14:06:30.494",
"verb": "run"
}
{
id:"ef696c12-69ab-11e4-8080-80003644b625",
actor:"User:1",
course:{
distance:10,
name:"Golden Gate Park"
},
object:"Exercise:42",
participants:[
"Thierry",
"Tommaso"
],
started_at:"2014-11-11T15:06:16+01:00",
target:null,
time:"2014-11-11T14:06:30.494",
verb:"run"
}