Please disable Adblockers and enable JavaScript for domain CEWebS.cs.univie.ac.at! We have NO ADS, but they may interfere with some of our course material.
Name: examples/activity_syncing_before.rb
1: | #!/usr/bin/ruby |
2: | require 'rubygems' |
3: | require '../../riddl/lib/ruby/client' |
4: | require 'xml/smart' |
5: | require 'active_support' |
6: | |
7: | |
8: | def build_notification(key,what,content,type) |
9: | res = [] |
10: | res << ['key' , key] |
11: | res << ['topic' , ::File::dirname(what)] |
12: | res << [type , ::File::basename(what)] |
13: | res << ['notification', ActiveSupport::JSON::encode(content)] |
14: | res << ['uid' , Digest::MD5.hexdigest(Kernel::rand().to_s)] |
15: | res << ['fp' , Digest::MD5.hexdigest(res.join(''))] |
16: | # TODO add secret to fp |
17: | end |
18: | |
19: | if ARGV.length != 3 |
20: | puts "Usage : #{File.basename($0)} [OPTION=VALUE] ..." |
21: | puts "Example: #{File.basename($0)} instance=3 activity=a1 endpoint=http://www.pri.univie.ac.at/~mangler/services/timeout-sync.php" |
22: | exit |
23: | end |
24: | |
25: | args = {} |
26: | ARGV.each do |a| |
27: | if a =~ /([A-Za-z]+)=(.*)/ |
28: | args[$1] = $2 |
29: | end |
30: | end |
31: | |
32: | ev = build_notification("xxx","activity/syncing_before",args,"vote") |
33: | |
34: | srv = Riddl::Client.new("http://localhost:9399/") |
35: | res = srv.resource("/1/events") |
36: | res.post ev.map{|k,v|Riddl::Parameter::Simple.new(k,v)} |