Skip to content

Commit

Permalink
Ruby Activity Streams too
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Sep 25, 2012
1 parent 3abd4e7 commit 738aee9
Show file tree
Hide file tree
Showing 4 changed files with 840 additions and 7 deletions.
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
js.strea.ms
===========
## js.strea.ms

A simple JavaScript Activity Streams implementation.

Example:

<pre>
``` javascript
var as =
AS.activity()
.actor(AS.person().displayName("James"))
Expand All @@ -15,6 +14,53 @@ var as =
.get();

print(as.write());
</pre>
```

More details to be added later...
More details to be added later...


## activitystreams.rb

A simple Ruby Activity Streams implementation

Example:
require 'activitystreams'
include ActivityStreams

``` ruby
#!/Users/james/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
$: << '.' if !$:.include? '.'
##############################################
# Author: James M Snell (jasnell@gmail.com) #
# License: Apache v2.0 #
##############################################
require 'activitystreams'
require 'optparse'

options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: note [options] content"
options[:name] = nil
opts.on( '-n', '--name NAME', 'The name' ) do |x|
options[:name] = x
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!

include ActivityStreams

STDOUT << activity {
pretty
verb :post
actor person {
display_name options[:name]
}
obj note {
content ARGV.shift
}
}
```
17 changes: 15 additions & 2 deletions activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ AS.Object = function() {}
AS.Object.prototype = {
write: function() {
return JSON.stringify(this);
},
toString : function() {
return this.write();
}
}

Expand All @@ -162,16 +165,26 @@ AS.Builder = function(o) {
builder.set(p,v,p.type,p.range);
return builder;
}
if (p.type == Date) {
if (p.type == Date)
builder[p + "Now"] = function() {
return builder[p](new Date());
}
}
if (p.type == Array)
builder["add_" + p] = function(v) {
builder.add(p,v,p.type,p.range);
return builder;
}
});
return builder;
}
}
AS.Builder.prototype = {
add: function(n,v,t,r) {
if (!v) return this;
var o = v instanceof AS.Builder ? v.get() : v;
this.obj[n] = this.obj[n] || new Array();
this.obj[n].push(r?r(o):o);
},
set: function(n,v,t,r) {
if (!v) return this;
var o = v instanceof AS.Builder ? v.get() : v;
Expand Down
36 changes: 36 additions & 0 deletions activity_note
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/Users/james/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
$: << '.' if !$:.include? '.'
##############################################
# Author: James M Snell (jasnell@gmail.com) #
# License: Apache v2.0 #
##############################################
require 'activitystreams'
require 'optparse'

options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: note [options] content"
options[:name] = nil
opts.on( '-n', '--name NAME', 'The name' ) do |x|
options[:name] = x
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!

include ActivityStreams

STDOUT << activity {
pretty
verb :post
actor person {
display_name options[:name]
}
obj note {
content ARGV.shift
}
}

Loading

0 comments on commit 738aee9

Please sign in to comment.